Skip to content

Commit 15e2ecd

Browse files
Backport "Fix HOAS pattern example and error message" to LTS (#20891)
Backports #19655 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 95b8e13 + f638f7d commit 15e2ecd

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
@@ -743,7 +743,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
743743
val spliceTypeText = (keywordStr("[") ~ toTextGlobal(tree.typeOpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
744744
keywordStr("$") ~ spliceTypeText ~ {
745745
if args.isEmpty then keywordStr("{") ~ inPattern(toText(pattern)) ~ keywordStr("}")
746-
else toText(pattern.symbol.name) ~ "(" ~ toTextGlobal(args, ", ") ~ ")"
746+
else toText(pattern) ~ "(" ~ toTextGlobal(args, ", ") ~ ")"
747747
}
748748
case Hole(isTerm, idx, args, content) =>
749749
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)