Skip to content

Commit 181eaca

Browse files
committed
Use unapply tree fun as prefix
1 parent 6fcd438 commit 181eaca

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ class Typer extends Namer
12591259
val constr = ctx.newConstructor(cls, Synthetic, Nil, Nil, coord = sym.coord).entered
12601260
val unappplySym = ctx.newSymbol(cls, sym.name.toTermName, Synthetic | Method, sym.info, coord = sym.coord).entered
12611261
val unapply = polyDefDef(unappplySym, targs => argss =>
1262-
Inliner.inlineCall(ref(sym).appliedToTypes(targs).appliedToArgss(argss).withSpan(t.span))
1262+
Inliner.inlineCall(t.fun.appliedToTypes(targs).appliedToArgss(argss).withSpan(t.span))(ctx.withOwner(unappplySym))
12631263
)
12641264
val cdef = ClassDef(cls, DefDef(constr), List(unapply))
12651265
val newUnapply = Block(cdef :: Nil, New(cls.typeRef, Nil))

tests/run/i8530-b.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.compiletime.erasedValue
2+
3+
class MyRegex[Pattern <: String & Singleton/*Literal constant*/]:
4+
inline def unapplySeq(s: CharSequence): Option[List[String]] =
5+
inline erasedValue[Pattern] match
6+
case "foo" => if s == "foo" then Some(Nil) else None
7+
case _ => valueOf[Pattern].r.unapplySeq(s)
8+
9+
@main def Test: Unit =
10+
val myRegexp1 = new MyRegex["foo"]
11+
val myRegexp2 = new MyRegex["f(o+)"]
12+
"foo" match
13+
case myRegexp1() => // Match ok
14+
case myRegexp2(x) => ???
15+
"foooo" match
16+
case myRegexp1() => ???
17+
case myRegexp2(x) =>
18+
assert(x == "oooo")

0 commit comments

Comments
 (0)