Skip to content

Commit 10cbc60

Browse files
committed
Fix wrong staging level error message
The tests were failing when the code was correct. The wrong message was ``` access to parameter t from wrong staging level: - the definition is at level 0, - but the access is at level -1. ``` The access to `t.Underlying` or `t.x.Underlying` are fine when we have an implicit `Type.of[t.Underlying]` or `Type.of[t.x.Underlying]`. These will probably be of the type of the aliased type of `A`, wherefore summoning `Type.of[A]`.
1 parent 095a7f1 commit 10cbc60

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class CrossStageSafety extends TreeMapWithStages {
9292
case tree: TypeDef if tree.symbol.is(Case) && level > 0 =>
9393
report.error(reporting.CaseClassInInlinedCode(tree), tree)
9494
super.transform(tree)
95+
case tree @ SplicedType(splicedTree) =>
96+
transformSpliceType(splicedTree, tree)
9597
case _ =>
9698
super.transform(tree)
9799
}
@@ -151,7 +153,7 @@ class CrossStageSafety extends TreeMapWithStages {
151153
untpd.cpy.Splice(splice)(body1).withType(tpe1)
152154
}
153155

154-
protected def transformSpliceType(body: Tree, splice: Select)(using Context): Tree = {
156+
private def transformSpliceType(body: Tree, splice: Select)(using Context): Tree = {
155157
val body1 = transform(body)(using spliceContext)
156158
if ctx.reporter.hasErrors then
157159
splice

compiler/src/dotty/tools/dotc/staging/TreeMapWithStages.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ abstract class TreeMapWithStages extends TreeMapWithImplicits {
3333
/** Transform the expression splice `splice` which contains the spliced `body`. */
3434
protected def transformSplice(body: Tree, splice: Splice)(using Context): Tree
3535

36-
/** Transform the type splice `splice` which contains the spliced `body`. */
37-
protected def transformSpliceType(body: Tree, splice: Select)(using Context): Tree
38-
3936
override def transform(tree: Tree)(using Context): Tree =
4037
if (tree.source != ctx.source && tree.source.exists)
4138
transform(tree)(using ctx.withSource(tree.source))
@@ -67,9 +64,6 @@ abstract class TreeMapWithStages extends TreeMapWithImplicits {
6764
transformSplice(splicedTree, tree)
6865
}
6966

70-
case tree @ SplicedType(splicedTree) =>
71-
transformSpliceType(splicedTree, tree)
72-
7367
case Block(stats, _) =>
7468
val defSyms = stats.collect { case defTree: DefTree => defTree.symbol }
7569
super.transform(tree)(using symbolsInCurrentLevel(defSyms))

tests/neg-macros/i10127-a.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted.*
22

33
object T {
4-
def impl[A](using t: Type[A])(using Quotes): Expr[Unit] = {
4+
def impl[A](t: Type[A])(using Quotes): Expr[Unit] = {
55
Expr.summon[t.Underlying] // error
66
'{}
77
}

tests/neg-macros/i10127-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ case class T(x: Type[_ <: Any])
44

55
object T {
66
def impl[A](t: T)(using ctx: Quotes): Expr[Unit] = {
7-
Expr.summon[t.x.Underlying] // error // error
7+
Expr.summon[t.x.Underlying] // error
88
'{}
99
}
1010
}

tests/pos-macros/i10127-a.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted.*
2+
3+
object T {
4+
def impl[A](using t: Type[A])(using Quotes): Expr[Unit] = {
5+
Expr.summon[t.Underlying]
6+
'{}
7+
}
8+
}

0 commit comments

Comments
 (0)