Skip to content

Commit 8765a16

Browse files
Merge pull request #15583 from dotty-staging/patch-12991
Check is inline unapply has leading implicits
2 parents 80f67df + 776e4d6 commit 8765a16

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+10-2
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

+7
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)