Skip to content

compile dotty with Ysemanticdb #8983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 19, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,16 @@ class ExtractSemanticDB extends Phase:
* the same starting position have the same index.
*/
def localIdx(sym: Symbol)(using Context): Int =
def startPos(sym: Symbol) =
if sym.span.exists then sym.span.start else -1
def computeLocalIdx(): Int =
symsAtOffset(sym.span.start).find(_.name == sym.name) match
symsAtOffset(startPos(sym)).find(_.name == sym.name) match
case Some(other) => localIdx(other)
case None =>
val idx = nextLocalIdx
nextLocalIdx += 1
locals(sym) = idx
symsAtOffset(sym.span.start) += sym
symsAtOffset(startPos(sym)) += sym
idx
locals.getOrElseUpdate(sym, computeLocalIdx())

Expand Down
12 changes: 12 additions & 0 deletions tests/pos-custom-args/semanticdb/inline-unapply/App_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

object Test {
def main(args: Array[String]): Unit = {
0 match
case Succ(n) => ???
case _ =>

2 match
case Succ(n) => assert(n == 1)
}

}
8 changes: 8 additions & 0 deletions tests/pos-custom-args/semanticdb/inline-unapply/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted._

object Succ:

inline def unapply(n: Int): Option[Int] = ${ impl('n) }

private def impl(n: Expr[Int])(using QuoteContext): Expr[Option[Int]] =
'{ if $n == 0 then None else Some($n - 1)}