Skip to content

Commit 4674ae6

Browse files
committed
WIP Replace quoted.Type.$splice to scala.internal.Quoted.TypeSplice
1 parent e6f424e commit 4674ae6

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ class Definitions {
713713
def InternalQuoted_exprSplice(implicit ctx: Context): Symbol = InternalQuoted_exprSpliceR.symbol
714714
lazy val InternalQuoted_typeQuoteR: TermRef = InternalQuotedModuleClass.requiredMethodRef("typeQuote".toTermName)
715715
def InternalQuoted_typeQuote(implicit ctx: Context): Symbol = InternalQuoted_typeQuoteR.symbol
716+
lazy val InternalQuoted_TypeSpliceR: TypeRef = InternalQuotedModuleClass.requiredType("TypeSplice".toTypeName).typeRef
717+
def InternalQuoted_TypeSplice(implicit ctx: Context): Symbol = InternalQuoted_TypeSpliceR.symbol
716718

717719
lazy val QuotedExprsModule: TermSymbol = ctx.requiredModule("scala.quoted.Exprs")
718720
def QuotedExprsClass(implicit ctx: Context): ClassSymbol = QuotedExprsModule.asClass

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,13 +1944,22 @@ class Typer extends Namer
19441944
/** Translate `${ t: Expr[T] }` into expresiion `t.splice` while tracking the quotation level in the context */
19451945
def typedSplice(tree: untpd.Splice, pt: Type)(implicit ctx: Context): Tree = track("typedSplice") {
19461946
checkSpliceOutsideQuote(tree)
1947-
if (tree.isType) typedSelect(untpd.Select(tree.expr, nme.splice), pt)(spliceContext).withSpan(tree.span)
1948-
else typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext)
1947+
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext)
19491948
}
19501949

19511950
/** Translate ${ t: Type[T] }` into type `t.splice` while tracking the quotation level in the context */
19521951
def typedTypSplice(tree: untpd.TypSplice, pt: Type)(implicit ctx: Context): Tree = track("typedTypSplice") {
19531952
checkSpliceOutsideQuote(tree)
1953+
// TODO desugar to defn.InternalQuoted_TypeSpliceR
1954+
// dotc -Ycheck:all -Xprint:front,stag tests/pos/quote-1.scala
1955+
1956+
// val foo = untpd.TypeApply(untpd.ref(defn.InternalQuoted_TypeSpliceR), List(untpd.TypeTree(pt), ))
1957+
println("========================")
1958+
println(tree.show)
1959+
println()
1960+
println(foo.show)
1961+
println()
1962+
println()
19541963
typedSelect(untpd.Select(tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span)
19551964
}
19561965

library/src-bootstrapped/scala/internal/Quoted.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ object Quoted {
1616
def typeQuote[T <: AnyKind]: Type[T] =
1717
throw new Error("Internal error: this method call should have been replaced by the compiler")
1818

19+
/** A type splice is desugared by the compiler into a call to this type alias */
20+
type TypeSplice[T, Typ <: Type[T] with Singleton] = T
21+
1922
}

tests/pos/quote-1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Test {
88
}
99

1010
f('{2})('[Int])
11-
f('{ true })('[Boolean])
11+
f('{ true })('[Boolean])
1212

1313
def g(es: Expr[String], t: Type[String]) =
1414
f('{ ($es + "!") :: Nil })('[List[$t]])

0 commit comments

Comments
 (0)