Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check is inline unapply has leading implicits #15583

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,15 @@ object Inlines:
// transforms the patterns into terms, the `inlinePatterns` phase removes this anonymous class by β-reducing
// the call to the `unapply`.

val UnApply(fun, implicits, patterns) = unapp
object SplitFunAndGivenArgs:
def unapply(tree: Tree): (Tree, List[List[Tree]]) = tree match
case Apply(SplitFunAndGivenArgs(fn, argss), args) => (fn, argss :+ args)
case _ => (tree, Nil)
val UnApply(SplitFunAndGivenArgs(fun, leadingImplicits), trailingImplicits, patterns) = unapp
if leadingImplicits.flatten.nonEmpty then
// To support them see https://github.com/lampepfl/dotty/pull/13158
report.error("inline unapply methods with given parameters before the scrutinee are not supported", fun)

val sym = unapp.symbol
val cls = newNormalizedClassSymbol(ctx.owner, tpnme.ANON_CLASS, Synthetic | Final, List(defn.ObjectType), coord = sym.coord)
val constr = newConstructor(cls, Synthetic, Nil, Nil, coord = sym.coord).entered
Expand All @@ -204,7 +212,7 @@ object Inlines:
val cdef = ClassDef(cls, DefDef(constr), List(unapply))
val newUnapply = Block(cdef :: Nil, New(cls.typeRef, Nil))
val newFun = newUnapply.select(unappplySym).withSpan(unapp.span)
cpy.UnApply(unapp)(newFun, implicits, patterns)
cpy.UnApply(unapp)(newFun, trailingImplicits, patterns)
end inlinedUnapply

/** For a retained inline method, another method that keeps track of
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i12991.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Foo:
inline def unapply(using String)(i: Int): Some[Int] = Some(i)

given String = ""

val i = 10 match
case Foo(x) => x // error