Skip to content

Commit 0ff0a97

Browse files
committed
Fix #6263: Register needsStaging when creating a synthetic quoted type
1 parent 832b140 commit 0ff0a97

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -667,29 +667,36 @@ trait Implicits { self: Typer =>
667667
EmptyTree
668668
}
669669

670-
def synthesizedTypeTag(formal: Type): Tree = formal.argInfos match {
671-
case arg :: Nil if !arg.typeSymbol.is(Param) =>
672-
object bindFreeVars extends TypeMap {
673-
var ok = true
674-
def apply(t: Type) = t match {
675-
case t @ TypeRef(NoPrefix, _) =>
676-
inferImplicit(defn.QuotedTypeType.appliedTo(t), EmptyTree, span) match {
677-
case SearchSuccess(tag, _, _) if tag.tpe.isStable =>
678-
tag.tpe.select(defn.QuotedType_splice)
679-
case _ =>
680-
ok = false
681-
t
682-
}
683-
case _ => t
670+
def synthesizedTypeTag(formal: Type): Tree = {
671+
def quotedType(t: Type) = {
672+
if (StagingContext.level == 0)
673+
ctx.compilationUnit.needsStaging = true // We will need to run ReifyQuotes
674+
ref(defn.InternalQuoted_typeQuote).appliedToType(t)
675+
}
676+
formal.argInfos match {
677+
case arg :: Nil if !arg.typeSymbol.is(Param) =>
678+
object bindFreeVars extends TypeMap {
679+
var ok = true
680+
def apply(t: Type) = t match {
681+
case t @ TypeRef(NoPrefix, _) =>
682+
inferImplicit(defn.QuotedTypeType.appliedTo(t), EmptyTree, span) match {
683+
case SearchSuccess(tag, _, _) if tag.tpe.isStable =>
684+
tag.tpe.select(defn.QuotedType_splice)
685+
case _ =>
686+
ok = false
687+
t
688+
}
689+
case _ => t
690+
}
684691
}
685-
}
686-
val tag = bindFreeVars(arg)
687-
if (bindFreeVars.ok) ref(defn.InternalQuoted_typeQuote).appliedToType(tag)
688-
else EmptyTree
689-
case arg :: Nil if ctx.inInlineMethod =>
690-
ref(defn.InternalQuoted_typeQuote).appliedToType(arg)
691-
case _ =>
692-
EmptyTree
692+
val tag = bindFreeVars(arg)
693+
if (bindFreeVars.ok) quotedType(tag)
694+
else EmptyTree
695+
case arg :: Nil if ctx.inInlineMethod =>
696+
quotedType(arg)
697+
case _ =>
698+
EmptyTree
699+
}
693700
}
694701

695702
def synthesizedTastyContext(formal: Type): Tree =

compiler/test-resources/repl/i6263

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
scala> import quoted._
2+
scala> def fn[T : Type](v : T) = println("ok")
3+
def fn[T](v: T)(implicit evidence$1: quoted.Type[T]): Unit
4+
scala> fn("foo")
5+
ok
6+
scala> fn((1,2))
7+
ok
8+
scala> object O
9+
// defined object O
10+
scala> fn(O)
11+
ok
12+
scala> fn(1)
13+
ok

0 commit comments

Comments
 (0)