Skip to content
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
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,13 @@ trait Applications extends Compatibility {
// applications of inline functions.
tree.args match {
case (arg @ Match(EmptyTree, cases)) :: Nil =>
cases.foreach {
case CaseDef(Typed(_: Ident, _), _, _) => // OK
case CaseDef(Bind(_, Typed(_: Ident, _)), _, _) => // OK
case CaseDef(Ident(name), _, _) if name == nme.WILDCARD => // Ok
case CaseDef(pat, _, _) =>
ctx.error("Unexpected pattern for summonFrom. Expeced `x: T` or `_`", pat.sourcePos)
}
typed(untpd.InlineMatch(EmptyTree, cases).withSpan(arg.span), pt)
case _ =>
errorTree(tree, em"argument to summonFrom must be a pattern matching closure")
Expand Down
28 changes: 28 additions & 0 deletions tests/neg/i7977.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import scala.compiletime.summonFrom
class Main(b: Boolean) {
inline def foo(): Any = {
summonFrom {
case x => println(x) // error
}

summonFrom {
case x if b => println(x) // error
}

summonFrom {
case Some(x) if b => println(x) // error
}

summonFrom {
case x if b => println(x) // error
case _ => println()
}

summonFrom { // ok but useless
case _ if b => println()
case _ => println()
}
}

foo()
}