Skip to content

Commit 45571b2

Browse files
committed
support inlined local defs
1 parent 5f5fa14 commit 45571b2

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,16 @@ class ExtractSemanticDB extends Phase:
334334
* the same starting position have the same index.
335335
*/
336336
def localIdx(sym: Symbol)(using Context): Int =
337+
def startPos(sym: Symbol) =
338+
if sym.span.exists then sym.span.start else -1
337339
def computeLocalIdx(): Int =
338-
symsAtOffset(sym.span.start).find(_.name == sym.name) match
340+
symsAtOffset(startPos(sym)).find(_.name == sym.name) match
339341
case Some(other) => localIdx(other)
340342
case None =>
341343
val idx = nextLocalIdx
342344
nextLocalIdx += 1
343345
locals(sym) = idx
344-
symsAtOffset(sym.span.start) += sym
346+
symsAtOffset(startPos(sym)) += sym
345347
idx
346348
locals.getOrElseUpdate(sym, computeLocalIdx())
347349

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
0 match
5+
case Succ(n) => ???
6+
case _ =>
7+
8+
2 match
9+
case Succ(n) => assert(n == 1)
10+
}
11+
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted._
2+
3+
object Succ:
4+
5+
inline def unapply(n: Int): Option[Int] = ${ impl('n) }
6+
7+
private def impl(n: Expr[Int])(using QuoteContext): Expr[Option[Int]] =
8+
'{ if $n == 0 then None else Some($n - 1)}

0 commit comments

Comments
 (0)