Skip to content

Commit 9bf429d

Browse files
Fix HOAS pattern example and error message (#19655)
Fixes #19342
2 parents 2c0b021 + d332cb0 commit 9bf429d

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
764764
val spliceTypeText = (keywordStr("[") ~ toTextGlobal(tree.typeOpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
765765
keywordStr("$") ~ spliceTypeText ~ {
766766
if args.isEmpty then keywordStr("{") ~ inPattern(toText(pattern)) ~ keywordStr("}")
767-
else toText(pattern.symbol.name) ~ "(" ~ toTextGlobal(args, ", ") ~ ")"
767+
else toText(pattern) ~ "(" ~ toTextGlobal(args, ", ") ~ ")"
768768
}
769769
case Hole(isTerm, idx, args, content) =>
770770
val (prefix, postfix) = if isTerm then ("{{{", "}}}") else ("[[[", "]]]")

docs/_docs/reference/metaprogramming/macros.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ The lambda arguments will replace the variables that might have been extruded.
452452

453453
```scala
454454
'{ ((x: Int) => x + 1).apply(2) } match
455-
case '{ ((y: Int) => $f(y)).apply($z: Int) } =>
455+
case '{ ((y: Int) => $f(y): Int).apply($z: Int) } =>
456456
// f may contain references to `x` (replaced by `$y`)
457-
// f = (y: Expr[Int]) => '{ $y + 1 }
458-
f(z) // generates '{ 2 + 1 }
457+
// f = '{ (y: Int) => $y + 1 }
458+
Expr.betaReduce('{ $f($z)}) // generates '{ 2 + 1 }
459459
```
460460

461461

tests/neg-macros/i19342.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Error: tests/neg-macros/i19342.scala:5:26 ---------------------------------------------------------------------------
2+
5 | case '{ ((y: Int) => $f(y)).apply($z: Int) } => () // error
3+
| ^
4+
| Type must be fully defined.
5+
| Consider annotating the splice using a type ascription:
6+
| ($f(y): XYZ).

tests/neg-macros/i19342.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.*
2+
3+
def scrutinizeHoas(expr: Expr[Int])(using Quotes): Unit =
4+
expr match {
5+
case '{ ((y: Int) => $f(y)).apply($z: Int) } => () // error
6+
case _ => ()
7+
}

0 commit comments

Comments
 (0)