Skip to content

Commit c6adab8

Browse files
committed
Move typedQuotedExpr/typedSplicedExpr to QuotesAndSplices
1 parent f0d758b commit c6adab8

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,33 @@ trait QuotesAndSplices {
3131

3232
import tpd._
3333

34+
def typedQuotedExpr(tree: untpd.QuotedExpr, pt: Type)(using Context): Tree =
35+
if tree.tpt.isEmpty then
36+
typedQuoteSyntactic(tree, pt)
37+
else
38+
val tpt1 = checkSimpleKinded(typedType(tree.tpt, mapPatternBounds = true))
39+
val expr1 = typed(tree.expr, tpt1.tpe.widenSkolem)(using quoteContext)
40+
assignType(untpd.cpy.QuotedExpr(tree)(expr1, tpt1), tpt1)
41+
42+
def typedSplicedExpr(tree: untpd.SplicedExpr, pt: Type)(using Context): Tree =
43+
if tree.tpt.isEmpty then
44+
typedSpliceSyntactic(tree, pt)
45+
else
46+
val tpt1 = checkSimpleKinded(typedType(tree.tpt, mapPatternBounds = true))
47+
val splicedType = // Quotes ?=> Expr[T]
48+
defn.FunctionType(1, isContextual = true)
49+
.appliedTo(defn.QuotesClass.typeRef, defn.QuotedExprClass.typeRef.appliedTo(tpt1.tpe.widenSkolem))
50+
val expr1 = typed(tree.expr, splicedType)(using spliceContext)
51+
assignType(untpd.cpy.SplicedExpr(tree)(expr1, tpt1), tpt1)
52+
53+
def typedHole(tree: untpd.Hole, pt: Type)(using Context): Tree =
54+
val tpt = typedType(tree.tpt)
55+
assignType(tree, tpt)
56+
3457
/** Translate `'{ e }` into `scala.quoted.Expr.apply(e)` and `'[T]` into `scala.quoted.Type.apply[T]`
3558
* while tracking the quotation level in the context.
3659
*/
37-
def typedQuote(tree: untpd.QuotedExpr, pt: Type)(using Context): Tree = {
60+
private def typedQuoteSyntactic(tree: untpd.QuotedExpr, pt: Type)(using Context): Tree = {
3861
record("typedQuote")
3962
tree.expr match {
4063
case untpd.SplicedExpr(innerExpr, _) if tree.isTerm && !ctx.mode.is(Mode.Pattern) =>
@@ -70,7 +93,7 @@ trait QuotesAndSplices {
7093
}
7194

7295
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
73-
def typedSplice(tree: untpd.SplicedExpr, pt: Type)(using Context): Tree = {
96+
private def typedSpliceSyntactic(tree: untpd.SplicedExpr, pt: Type)(using Context): Tree = {
7497
record("typedSplice")
7598
checkSpliceOutsideQuote(tree)
7699
tree.expr match {
@@ -130,7 +153,7 @@ trait QuotesAndSplices {
130153
else if splice.isInBraces then // ${x}(...) match an application
131154
val typedArgs = args.map(arg => typedExpr(arg))
132155
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
133-
val splice1 = typedSplice(splice, defn.FunctionOf(argTypes, pt))
156+
val splice1 = typedSpliceSyntactic(splice, defn.FunctionOf(argTypes, pt))
134157
Apply(splice1.select(nme.apply), typedArgs).withType(pt).withSpan(tree.span)
135158
else // $x(...) higher-order quasipattern
136159
val typedArgs = args.map {
@@ -143,7 +166,7 @@ trait QuotesAndSplices {
143166
if args.isEmpty then
144167
report.error("Missing arguments for open pattern", tree.srcPos)
145168
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
146-
val typedPat = typedSplice(splice, defn.FunctionOf(argTypes, pt))
169+
val typedPat = typedSpliceSyntactic(splice, defn.FunctionOf(argTypes, pt))
147170
ref(defn.QuotedRuntimePatterns_patternHigherOrderHole).appliedToType(pt).appliedTo(typedPat, SeqLiteral(typedArgs, TypeTree(defn.AnyType)))
148171
}
149172

@@ -165,10 +188,6 @@ trait QuotesAndSplices {
165188
using spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx)))
166189
pat.select(tpnme.Underlying)
167190

168-
def typedHole(tree: untpd.Hole, pt: Type)(using Context): Tree =
169-
val tpt = typedType(tree.tpt)
170-
assignType(tree, tpt)
171-
172191
private def checkSpliceOutsideQuote(tree: untpd.Tree)(using Context): Unit =
173192
if (level == 0 && !ctx.owner.ownersIterator.exists(_.isInlineMethod))
174193
report.error("Splice ${...} outside quotes '{...} or inline method", tree.srcPos)

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,25 +2045,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
20452045
bindings1, expansion1)
20462046
}
20472047

2048-
def typedQuotedExpr(tree: untpd.QuotedExpr, pt: Type)(using Context): Tree =
2049-
if tree.tpt.isEmpty then
2050-
typedQuote(tree, pt)
2051-
else
2052-
val tpt1 = checkSimpleKinded(typedType(tree.tpt, mapPatternBounds = true))
2053-
val expr1 = typed(tree.expr, tpt1.tpe.widenSkolem)(using StagingLevel.quoteContext)
2054-
assignType(cpy.QuotedExpr(tree)(expr1, tpt1), tpt1)
2055-
2056-
def typedSplicedExpr(tree: untpd.SplicedExpr, pt: Type)(using Context): Tree =
2057-
if tree.tpt.isEmpty then
2058-
typedSplice(tree, pt)
2059-
else
2060-
val tpt1 = checkSimpleKinded(typedType(tree.tpt, mapPatternBounds = true))
2061-
val splicedType = // Quotes ?=> Expr[T]
2062-
defn.FunctionType(1, isContextual = true)
2063-
.appliedTo(defn.QuotesClass.typeRef, defn.QuotedExprClass.typeRef.appliedTo(tpt1.tpe.widenSkolem))
2064-
val expr1 = typed(tree.expr, splicedType)(using StagingLevel.spliceContext)
2065-
assignType(cpy.SplicedExpr(tree)(expr1, tpt1), tpt1)
2066-
20672048
def completeTypeTree(tree: untpd.TypeTree, pt: Type, original: untpd.Tree)(using Context): TypeTree =
20682049
tree.withSpan(original.span).withAttachmentsFrom(original)
20692050
.withType(

0 commit comments

Comments
 (0)