File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
compiler/src/dotty/tools/dotc/semanticdb
tests/pos-custom-args/semanticdb/inline-unapply Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -334,14 +334,16 @@ class ExtractSemanticDB extends Phase:
334
334
* the same starting position have the same index.
335
335
*/
336
336
def localIdx (sym : Symbol )(using Context ): Int =
337
+ def startPos (sym : Symbol ) =
338
+ if sym.span.exists then sym.span.start else - 1
337
339
def computeLocalIdx (): Int =
338
- symsAtOffset(sym.span.start ).find(_.name == sym.name) match
340
+ symsAtOffset(startPos( sym) ).find(_.name == sym.name) match
339
341
case Some (other) => localIdx(other)
340
342
case None =>
341
343
val idx = nextLocalIdx
342
344
nextLocalIdx += 1
343
345
locals(sym) = idx
344
- symsAtOffset(sym.span.start ) += sym
346
+ symsAtOffset(startPos( sym) ) += sym
345
347
idx
346
348
locals.getOrElseUpdate(sym, computeLocalIdx())
347
349
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 )}
You can’t perform that action at this time.
0 commit comments