Skip to content

Commit 13b7ba2

Browse files
committed
Fix #4493: Fail level checks for macro type parameters at level 0
They require a type tag.
1 parent ecf95c1 commit 13b7ba2

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
144144
/** We are in a `~(...)` context that is not shadowed by a nested `'(...)` */
145145
def inSplice = outer != null && !inQuote
146146

147+
/** We are not in a `~(...)` or a `'(...)` */
148+
def isRoot = outer != null
149+
147150
/** A map from type ref T to expressions of type `quoted.Type[T]`".
148151
* These will be turned into splices using `addTags` and represent type variables
149152
* that can be possibly healed.
@@ -242,8 +245,8 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
242245
*/
243246
def levelOK(sym: Symbol)(implicit ctx: Context): Boolean = levelOf.get(sym) match {
244247
case Some(l) =>
245-
l == level ||
246-
sym.is(Inline) && sym.owner.is(Macro) && sym.info.isValueType && l - 1 == level
248+
if (level == 1 && l == level && sym.isType && sym.owner.is(Macro) && outer.isRoot) false
249+
else l == level || (l - 1 == level && sym.is(Inline) && sym.owner.is(Macro) && sym.info.isValueType)
247250
case None =>
248251
!sym.is(Param) || levelOK(sym.owner)
249252
}

tests/neg/i4493.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Index[K]
2+
object Index {
3+
inline def succ[K]: Unit = ~{
4+
'(new Index[K]) // error: missing typetag Type[K]. May not be an error if we synthesize them #4515.
5+
}
6+
}

tests/pos/i4493-b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Index[K]
2+
object Index {
3+
inline def succ[K](x: K): Unit = ~{
4+
implicit val t: quoted.Type[K] = '[K]
5+
'(new Index[K])
6+
}
7+
}

tests/pos/i4493.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Index[K]
2+
object Index {
3+
inline def succ[K]: Unit = ~{
4+
implicit val t: quoted.Type[K] = '[K]
5+
'(new Index[K])
6+
}
7+
}

0 commit comments

Comments
 (0)