Skip to content

Commit 4fa9ada

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

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,10 @@ 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
718+
lazy val InternalQuoted_typeSpliceR: TermRef = InternalQuotedModuleClass.requiredMethodRef("typeSplice".toTermName)
719+
def InternalQuoted_typeSplice(implicit ctx: Context): Symbol = InternalQuoted_typeSpliceR.symbol
716720

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

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,13 +1944,43 @@ 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+
assert(pt.isInstanceOf[WildcardType])
1954+
// TODO desugar to defn.InternalQuoted_TypeSpliceR
1955+
// dotc -Ycheck:all -Xprint:front,stag tests/pos/quote-1.scala
1956+
1957+
//// val foo = untpd.AppliedTypeTree(untpd.ref(defn.InternalQuoted_TypeSpliceR), List(untpd.TypeTree(pt), ))
1958+
// val bar = typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_typeSpliceR), tree.expr), pt)(spliceContext)
1959+
// println("========================")
1960+
// println(tree.show)
1961+
// println()
1962+
//// println(foo.show)
1963+
// println(bar.show)
1964+
// println(bar)
1965+
// println(bar.tpe)
1966+
// println()
1967+
// println()
1968+
// println(bar.asInstanceOf[Apply].args.head.show)
1969+
// println(bar.asInstanceOf[Apply].args.head)
1970+
// println(bar.asInstanceOf[Apply].args.head.tpe)
1971+
// println()
1972+
// println(bar.asInstanceOf[Apply].fun.asInstanceOf[TypeApply].args.head.show)
1973+
// println(bar.asInstanceOf[Apply].fun.asInstanceOf[TypeApply].args.head)
1974+
// println(bar.asInstanceOf[Apply].fun.asInstanceOf[TypeApply].args.head.tpe.stripTypeVar.widenDealias)
1975+
// println()
1976+
// println(bar.asInstanceOf[Apply].fun.asInstanceOf[TypeApply].args.last.show)
1977+
// println(bar.asInstanceOf[Apply].fun.asInstanceOf[TypeApply].args.last)
1978+
// println(bar.asInstanceOf[Apply].fun.asInstanceOf[TypeApply].args.last.tpe.stripTypeVar.widenDealias)
1979+
// println()
1980+
// println()
1981+
// println()
1982+
//// println()
1983+
//// println()
19541984
typedSelect(untpd.Select(tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span)
19551985
}
19561986

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ 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 <: AnyKind, Typ <: Type[T] with Singleton] = T
21+
22+
/** Temporary splice used durring typing to infere T and Typ */
23+
def typeSplice[T <: AnyKind, Typ <: Type[T] with Singleton](t: Typ): Type[T] =
24+
throw new Error("Internal error: this method call should have been replaced by the compiler")
1925
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ 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/* <: AnyKind */, Typ <: Type[T] with Singleton] = T
21+
22+
/** Temporary splice used durring typing to infere T and Typ */
23+
def typeSplice[T/* <: AnyKind */, Typ <: Type[T] with Singleton](t: Typ): Type[T] =
24+
throw new Error("Internal error: this method call should have been replaced by the compiler")
25+
1926
}

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)