diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 2872f1f823c4..1819db270132 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -743,7 +743,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { val spliceTypeText = (keywordStr("[") ~ toTextGlobal(tree.typeOpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists) keywordStr("$") ~ spliceTypeText ~ { if args.isEmpty then keywordStr("{") ~ inPattern(toText(pattern)) ~ keywordStr("}") - else toText(pattern.symbol.name) ~ "(" ~ toTextGlobal(args, ", ") ~ ")" + else toText(pattern) ~ "(" ~ toTextGlobal(args, ", ") ~ ")" } case Hole(isTerm, idx, args, content) => val (prefix, postfix) = if isTerm then ("{{{", "}}}") else ("[[[", "]]]") diff --git a/docs/_docs/reference/metaprogramming/macros.md b/docs/_docs/reference/metaprogramming/macros.md index dd45be0c4971..cbc184c219cc 100644 --- a/docs/_docs/reference/metaprogramming/macros.md +++ b/docs/_docs/reference/metaprogramming/macros.md @@ -452,10 +452,10 @@ The lambda arguments will replace the variables that might have been extruded. ```scala '{ ((x: Int) => x + 1).apply(2) } match - case '{ ((y: Int) => $f(y)).apply($z: Int) } => + case '{ ((y: Int) => $f(y): Int).apply($z: Int) } => // f may contain references to `x` (replaced by `$y`) - // f = (y: Expr[Int]) => '{ $y + 1 } - f(z) // generates '{ 2 + 1 } + // f = '{ (y: Int) => $y + 1 } + Expr.betaReduce('{ $f($z)}) // generates '{ 2 + 1 } ``` diff --git a/tests/neg-macros/i19342.check b/tests/neg-macros/i19342.check new file mode 100644 index 000000000000..13644dc130c2 --- /dev/null +++ b/tests/neg-macros/i19342.check @@ -0,0 +1,6 @@ +-- Error: tests/neg-macros/i19342.scala:5:26 --------------------------------------------------------------------------- +5 | case '{ ((y: Int) => $f(y)).apply($z: Int) } => () // error + | ^ + | Type must be fully defined. + | Consider annotating the splice using a type ascription: + | ($f(y): XYZ). diff --git a/tests/neg-macros/i19342.scala b/tests/neg-macros/i19342.scala new file mode 100644 index 000000000000..afdcecf96941 --- /dev/null +++ b/tests/neg-macros/i19342.scala @@ -0,0 +1,7 @@ +import scala.quoted.* + +def scrutinizeHoas(expr: Expr[Int])(using Quotes): Unit = + expr match { + case '{ ((y: Int) => $f(y)).apply($z: Int) } => () // error + case _ => () + }