diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 931717617e24..4ecdaeb83b5a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -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") diff --git a/tests/neg/i7977.scala b/tests/neg/i7977.scala new file mode 100644 index 000000000000..fe1fba004834 --- /dev/null +++ b/tests/neg/i7977.scala @@ -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() +} \ No newline at end of file