Skip to content

Commit 776e4d6

Browse files
committed
Check is inline unapply has leading implicits
We patch the crash in the compiler but do not support this feature yet. To support it see #13158 Fixes #12991
1 parent 7d6d42f commit 776e4d6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,15 @@ object Inlines:
185185
// transforms the patterns into terms, the `inlinePatterns` phase removes this anonymous class by β-reducing
186186
// the call to the `unapply`.
187187

188-
val UnApply(fun, implicits, patterns) = unapp
188+
object SplitFunAndGivenArgs:
189+
def unapply(tree: Tree): (Tree, List[List[Tree]]) = tree match
190+
case Apply(SplitFunAndGivenArgs(fn, argss), args) => (fn, argss :+ args)
191+
case _ => (tree, Nil)
192+
val UnApply(SplitFunAndGivenArgs(fun, leadingImplicits), trailingImplicits, patterns) = unapp
193+
if leadingImplicits.flatten.nonEmpty then
194+
// To support them see https://github.com/lampepfl/dotty/pull/13158
195+
report.error("inline unapply methods with given parameters before the scrutinee are not supported", fun)
196+
189197
val sym = unapp.symbol
190198
val cls = newNormalizedClassSymbol(ctx.owner, tpnme.ANON_CLASS, Synthetic | Final, List(defn.ObjectType), coord = sym.coord)
191199
val constr = newConstructor(cls, Synthetic, Nil, Nil, coord = sym.coord).entered
@@ -204,7 +212,7 @@ object Inlines:
204212
val cdef = ClassDef(cls, DefDef(constr), List(unapply))
205213
val newUnapply = Block(cdef :: Nil, New(cls.typeRef, Nil))
206214
val newFun = newUnapply.select(unappplySym).withSpan(unapp.span)
207-
cpy.UnApply(unapp)(newFun, implicits, patterns)
215+
cpy.UnApply(unapp)(newFun, trailingImplicits, patterns)
208216
end inlinedUnapply
209217

210218
/** For a retained inline method, another method that keeps track of

tests/neg/i12991.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Foo:
2+
inline def unapply(using String)(i: Int): Some[Int] = Some(i)
3+
4+
given String = ""
5+
6+
val i = 10 match
7+
case Foo(x) => x // error

0 commit comments

Comments
 (0)