Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
*
* See `isCaptured`
*/
val capturers = new mutable.HashMap[Symbol, RefTree => Tree]
val capturers = new mutable.HashMap[Symbol, Tree => Tree]
}

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

/** We are not in a `~(...)` or a `'(...)` */
def isRoot = outer == null

/** A map from type ref T to expressions of type `quoted.Type[T]`".
* These will be turned into splices using `addTags` and represent type variables
* that can be possibly healed.
Expand Down Expand Up @@ -291,6 +294,8 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
else i"${sym.name}.this"
if (!isThis && sym.maybeOwner.isType && !sym.is(Param))
check(sym.owner, sym.owner.thisType, pos)
else if (level == 1 && sym.isType && sym.is(Param) && sym.owner.is(Macro) && !outer.isRoot)
importedTags(sym.typeRef) = capturers(sym)(ref(sym))
else if (sym.exists && !sym.isStaticOwner && !levelOK(sym))
for (errMsg <- tryHeal(tp, pos))
ctx.error(em"""access to $symStr from wrong staging level:
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i4493-b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Index[K]
object Index {
inline def succ[K](x: K): Unit = ~{
implicit val t: quoted.Type[K] = '[K]
'(new Index[K])
}
}
6 changes: 6 additions & 0 deletions tests/pos/i4493-c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Index[K]
object Index {
inline def succ[K]: Unit = ~{
'(new Index[K])
}
}
7 changes: 7 additions & 0 deletions tests/pos/i4493.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Index[K]
object Index {
inline def succ[K]: Unit = ~{
implicit val t: quoted.Type[K] = '[K]
'(new Index[K])
}
}
4 changes: 4 additions & 0 deletions tests/pos/i4514.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Foo {
inline def foo[X](x: X): Unit = ~fooImpl('(x))
def fooImpl[X: quoted.Type](x: X): quoted.Expr[Unit] = '()
}