Skip to content

Commit f9f9f4a

Browse files
Merge pull request #4518 from dotty-staging/fix-#4493
Fix #4493 and #4514
2 parents 297e9fc + 2e04698 commit f9f9f4a

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
124124
*
125125
* See `isCaptured`
126126
*/
127-
val capturers = new mutable.HashMap[Symbol, RefTree => Tree]
127+
val capturers = new mutable.HashMap[Symbol, Tree => Tree]
128128
}
129129

130130
/** The main transformer class
@@ -148,6 +148,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
148148
/** We are in a `~(...)` context that is not shadowed by a nested `'(...)` */
149149
def inSplice = outer != null && !inQuote
150150

151+
/** We are not in a `~(...)` or a `'(...)` */
152+
def isRoot = outer == null
153+
151154
/** A map from type ref T to expressions of type `quoted.Type[T]`".
152155
* These will be turned into splices using `addTags` and represent type variables
153156
* that can be possibly healed.
@@ -295,6 +298,8 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
295298
else i"${sym.name}.this"
296299
if (!isThis && sym.maybeOwner.isType && !sym.is(Param))
297300
check(sym.owner, sym.owner.thisType, pos)
301+
else if (level == 1 && sym.isType && sym.is(Param) && sym.owner.is(Macro) && !outer.isRoot)
302+
importedTags(sym.typeRef) = capturers(sym)(ref(sym))
298303
else if (sym.exists && !sym.isStaticOwner && !levelOK(sym))
299304
for (errMsg <- tryHeal(tp, pos))
300305
ctx.error(em"""access to $symStr from wrong staging level:

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-c.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])
5+
}
6+
}

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+
}

tests/pos/i4514.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Foo {
2+
inline def foo[X](x: X): Unit = ~fooImpl('(x))
3+
def fooImpl[X: quoted.Type](x: X): quoted.Expr[Unit] = '()
4+
}

0 commit comments

Comments
 (0)