Skip to content

Commit 4f2bb4b

Browse files
committed
Revert "Remove tpt from Quote"
Reverts 5ae7861 Fixes scala#17434
1 parent 14b7aa7 commit 4f2bb4b

27 files changed

+136
-65
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ object desugar {
19761976
trees foreach collect
19771977
case Block(Nil, expr) =>
19781978
collect(expr)
1979-
case Quote(body, _) =>
1979+
case Quote(body, _, _) =>
19801980
new UntypedTreeTraverser {
19811981
def traverse(tree: untpd.Tree)(using Context): Unit = tree match {
19821982
case SplicePattern(body, _) => collect(body)

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -697,28 +697,12 @@ object Trees {
697697
* @param body The tree that was quoted
698698
* @param tags Term references to instances of `Type[T]` for `T`s that are used in the quote
699699
*/
700-
case class Quote[+T <: Untyped] private[ast] (body: Tree[T], tags: List[Tree[T]])(implicit @constructorOnly src: SourceFile)
700+
case class Quote[+T <: Untyped] private[ast] (body: Tree[T], tags: List[Tree[T]], tpt: Tree[T])(implicit @constructorOnly src: SourceFile)
701701
extends TermTree[T] {
702702
type ThisTree[+T <: Untyped] = Quote[T]
703703

704704
/** Is this a type quote `'[tpe]' */
705705
def isTypeQuote = body.isType
706-
707-
/** Type of the quoted expression as seen from outside the quote */
708-
def bodyType(using Context): Type =
709-
val quoteType = typeOpt // `Quotes ?=> Expr[T]` or `Quotes ?=> Type[T]`
710-
val exprType = quoteType.argInfos.last // `Expr[T]` or `Type[T]`
711-
exprType.argInfos.head // T
712-
713-
/** Set the type of the body of the quote */
714-
def withBodyType(tpe: Type)(using Context): Quote[Type] =
715-
val exprType = // `Expr[T]` or `Type[T]`
716-
if body.isTerm then defn.QuotedExprClass.typeRef.appliedTo(tpe)
717-
else defn.QuotedTypeClass.typeRef.appliedTo(tpe)
718-
val quoteType = // `Quotes ?=> Expr[T]` or `Quotes ?=> Type[T]`
719-
defn.FunctionType(1, isContextual = true)
720-
.appliedTo(defn.QuotesClass.typeRef, exprType)
721-
withType(quoteType)
722706
}
723707

724708
/** A tree representing a splice `${ expr }`
@@ -1334,9 +1318,9 @@ object Trees {
13341318
case tree: Inlined if (call eq tree.call) && (bindings eq tree.bindings) && (expansion eq tree.expansion) => tree
13351319
case _ => finalize(tree, untpd.Inlined(call, bindings, expansion)(sourceFile(tree)))
13361320
}
1337-
def Quote(tree: Tree)(body: Tree, tags: List[Tree])(using Context): Quote = tree match {
1338-
case tree: Quote if (body eq tree.body) && (tags eq tree.tags) => tree
1339-
case _ => finalize(tree, untpd.Quote(body, tags)(sourceFile(tree)))
1321+
def Quote(tree: Tree)(body: Tree, tags: List[Tree], tpt: Tree)(using Context): Quote = tree match {
1322+
case tree: Quote if (body eq tree.body) && (tags eq tree.tags) && (tpt eq tree.tpt) => tree
1323+
case _ => finalize(tree, untpd.Quote(body, tags, tpt)(sourceFile(tree)))
13401324
}
13411325
def Splice(tree: Tree)(expr: Tree)(using Context): Splice = tree match {
13421326
case tree: Splice if (expr eq tree.expr) => tree
@@ -1583,8 +1567,8 @@ object Trees {
15831567
case Thicket(trees) =>
15841568
val trees1 = transform(trees)
15851569
if (trees1 eq trees) tree else Thicket(trees1)
1586-
case Quote(body, tags) =>
1587-
cpy.Quote(tree)(transform(body)(using quoteContext), transform(tags))
1570+
case Quote(body, tags, tpt) =>
1571+
cpy.Quote(tree)(transform(body)(using quoteContext), transform(tags), transform(tpt))
15881572
case tree @ Splice(expr) =>
15891573
cpy.Splice(tree)(transform(expr)(using spliceContext))
15901574
case tree @ SplicePattern(body, args) =>
@@ -1730,8 +1714,8 @@ object Trees {
17301714
this(this(x, arg), annot)
17311715
case Thicket(ts) =>
17321716
this(x, ts)
1733-
case Quote(body, tags) =>
1734-
this(this(x, body)(using quoteContext), tags)
1717+
case Quote(body, tags, tpt) =>
1718+
this(this(this(x, body)(using quoteContext), tags), tpt)
17351719
case Splice(expr) =>
17361720
this(x, expr)(using spliceContext)
17371721
case SplicePattern(body, args) =>

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
170170
def Inlined(call: Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined =
171171
ta.assignType(untpd.Inlined(call, bindings, expansion), bindings, expansion)
172172

173-
def Quote(body: Tree, tags: List[Tree])(using Context): Quote =
174-
untpd.Quote(body, tags).withBodyType(body.tpe)
173+
def Quote(body: Tree, tags: List[Tree], tpt: Tree)(using Context): Quote =
174+
ta.assignType(untpd.Quote(body, tags, tpt), tpt)
175175

176176
def Splice(expr: Tree, tpe: Type)(using Context): Splice =
177177
untpd.Splice(expr).withType(tpe)

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
397397
def SeqLiteral(elems: List[Tree], elemtpt: Tree)(implicit src: SourceFile): SeqLiteral = new SeqLiteral(elems, elemtpt)
398398
def JavaSeqLiteral(elems: List[Tree], elemtpt: Tree)(implicit src: SourceFile): JavaSeqLiteral = new JavaSeqLiteral(elems, elemtpt)
399399
def Inlined(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(implicit src: SourceFile): Inlined = new Inlined(call, bindings, expansion)
400-
def Quote(body: Tree, tags: List[Tree])(implicit src: SourceFile): Quote = new Quote(body, tags)
400+
def Quote(body: Tree, tags: List[Tree], tpt: Tree)(implicit src: SourceFile): Quote = new Quote(body, tags, tpt)
401401
def Splice(expr: Tree)(implicit src: SourceFile): Splice = new Splice(expr)
402402
def SplicePattern(body: Tree, args: List[Tree])(implicit src: SourceFile): SplicePattern = new SplicePattern(body, args)
403403
def TypeTree()(implicit src: SourceFile): TypeTree = new TypeTree()

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,15 @@ class TreePickler(pickler: TastyPickler) {
665665
pickleTree(hi)
666666
pickleTree(alias)
667667
}
668-
case tree @ Quote(body, Nil) =>
668+
case tree @ Quote(body, Nil, _) =>
669669
// TODO: Add QUOTE tag to TASTy
670670
assert(body.isTerm,
671671
"""Quote with type should not be pickled.
672672
|Quote with type should only exists after staging phase at staging level 0.""".stripMargin)
673673
pickleTree(
674674
// scala.quoted.runtime.Expr.quoted[<tree.bodyType>](<body>)
675675
ref(defn.QuotedRuntime_exprQuote)
676-
.appliedToType(tree.bodyType)
676+
.appliedToTypeTree(tree.tpt)
677677
.appliedTo(body)
678678
.withSpan(tree.span)
679679
)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ class TreeUnpickler(reader: TastyReader,
12691269

12701270
def quotedExpr(fn: Tree, args: List[Tree]): Tree =
12711271
val TypeApply(_, targs) = fn: @unchecked
1272-
untpd.Quote(args.head, Nil).withBodyType(targs.head.tpe)
1272+
Quote(args.head, Nil, targs.head)
12731273

12741274
def splicedExpr(fn: Tree, args: List[Tree]): Tree =
12751275
val TypeApply(_, targs) = fn: @unchecked

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ class Inliner(val call: tpd.Tree)(using Context):
827827

828828
override def typedQuote(tree: untpd.Quote, pt: Type)(using Context): Tree =
829829
super.typedQuote(tree, pt) match
830-
case Quote(Splice(inner), _) => inner
830+
case Quote(Splice(inner), _, _) => inner
831831
case tree1 =>
832832
ctx.compilationUnit.needsStaging = true
833833
tree1

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ object Parsers {
12431243
}
12441244
}
12451245
in.nextToken()
1246-
Quote(t, Nil)
1246+
Quote(t, Nil, EmptyTree)
12471247
}
12481248
else
12491249
if !in.featureEnabled(Feature.symbolLiterals) then
@@ -2482,7 +2482,7 @@ object Parsers {
24822482
val body =
24832483
if (in.token == LBRACKET) inBrackets(typ())
24842484
else stagedBlock()
2485-
Quote(body, Nil)
2485+
Quote(body, Nil, EmptyTree)
24862486
}
24872487
}
24882488
case NEW =>

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
726726
"Thicket {" ~~ toTextGlobal(trees, "\n") ~~ "}"
727727
case MacroTree(call) =>
728728
keywordStr("macro ") ~ toTextGlobal(call)
729-
case tree @ Quote(body, tags) =>
729+
case tree @ Quote(body, tags, tpt) =>
730730
val tagsText = (keywordStr("<") ~ toTextGlobal(tags, ", ") ~ keywordStr(">")).provided(tree.tags.nonEmpty)
731-
val exprTypeText = (keywordStr("[") ~ toTextGlobal(tree.bodyType) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
731+
val exprTypeText = (keywordStr("[") ~ toTextGlobal(tree.tpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
732732
val open = if (body.isTerm) keywordStr("{") else keywordStr("[")
733733
val close = if (body.isTerm) keywordStr("}") else keywordStr("]")
734734
keywordStr("'") ~ tagsText ~ exprTypeText ~ open ~ toTextGlobal(body) ~ close

compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ class CrossStageSafety extends TreeMapWithStages {
6868
val tree1 =
6969
val stripAnnotationsDeep: TypeMap = new TypeMap:
7070
def apply(tp: Type): Type = mapOver(tp.stripAnnots)
71-
val bodyType1 = healType(tree.srcPos)(stripAnnotationsDeep(tree.bodyType))
72-
tree.withBodyType(bodyType1)
71+
val bodyType1 = healType(tree.srcPos)(stripAnnotationsDeep(tree.tpt.tpe))
72+
cpy.Quote(tree)(tree.body, tree.tags, TypeTree(bodyType1))
7373

7474
if level == 0 then
7575
val (tags, body1) = inContextWithQuoteTypeTags { transform(tree1.body)(using quoteContext) }
76-
cpy.Quote(tree1)(body1, tags)
76+
cpy.Quote(tree1)(body1, tags, tree1.tpt)
7777
else
7878
super.transform(tree1)
7979

@@ -98,7 +98,7 @@ class CrossStageSafety extends TreeMapWithStages {
9898
tag // Optimization: `quoted.Type.of[x.Underlying](quotes)` --> `x`
9999
case _ =>
100100
// `quoted.Type.of[<body>](<quotes>)` --> `'[<body1>].apply(<quotes>)`
101-
tpd.Quote(body1, tags).select(nme.apply).appliedTo(quotes).withSpan(tree.span)
101+
tpd.Quote(body1, tags, body1).select(nme.apply).appliedTo(quotes).withSpan(tree.span)
102102
else
103103
super.transform(tree)
104104
case _: DefDef if tree.symbol.isInlineMethod =>
@@ -234,7 +234,7 @@ class CrossStageSafety extends TreeMapWithStages {
234234
def unapply(tree: Splice): Option[Tree] =
235235
def rec(tree: Tree): Option[Tree] = tree match
236236
case Block(Nil, expr) => rec(expr)
237-
case Quote(inner, _) => Some(inner)
237+
case Quote(inner, _, _) => Some(inner)
238238
case _ => None
239239
rec(tree.expr)
240240
}

compiler/src/dotty/tools/dotc/transform/MegaPhase.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase {
402402
case tree: Quote =>
403403
inContext(prepQuote(tree, start)(using outerCtx)) {
404404
val body = transformTree(tree.body, start)(using quoteContext)
405-
goQuote(cpy.Quote(tree)(body, Nil), start)
405+
val tpt = transformTree(tree.tpt, start)
406+
goQuote(cpy.Quote(tree)(body, Nil, tpt), start)
406407
}
407408
case tree: Splice =>
408409
inContext(prepSplice(tree, start)(using outerCtx)) {

compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class PickleQuotes extends MacroTransform {
156156

157157
val holeMaker = new HoleContentExtractor
158158
val body1 = holeMaker.transform(quote.body)
159-
val quote1 = cpy.Quote(quote)(body1, quote.tags)
159+
val quote1 = cpy.Quote(quote)(body1, quote.tags, quote.tpt)
160160

161161
(holeMaker.getContents(), quote1)
162162
end extractHolesContents
@@ -193,7 +193,7 @@ class PickleQuotes extends MacroTransform {
193193
case None => tree
194194
case _ => tree
195195
val body1 = new TreeTypeMap(typeMap, treeMap).transform(quote.body)
196-
cpy.Quote(quote)(Block(tdefs, body1), quote.tags)
196+
cpy.Quote(quote)(Block(tdefs, body1), quote.tags, quote.tpt)
197197

198198
private def mkTagSymbolAndAssignType(typeArg: Tree, idx: Int)(using Context): TypeDef = {
199199
val holeType = getTypeHoleType(typeArg.tpe.select(tpnme.Underlying))
@@ -238,7 +238,7 @@ object PickleQuotes {
238238

239239
def pickle(quote: Quote, quotes: Tree, holeContents: List[Tree])(using Context) = {
240240
val body = quote.body
241-
val bodyType = quote.bodyType
241+
val bodyType = quote.tpt.tpe
242242

243243
/** Helper methods to construct trees calling methods in `Quotes.reflect` based on the current `quotes` tree */
244244
object reflect extends ReifiedReflect {

compiler/src/dotty/tools/dotc/transform/ReifiedReflect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ trait ReifiedReflect:
7575
.select(defn.Quotes_reflect_TypeRepr_of)
7676
.appliedToType(tpe)
7777
.appliedTo(
78-
tpd.Quote(TypeTree(tpe), Nil)
78+
tpd.Quote(TypeTree(tpe), Nil, TypeTree(tpe))
7979
.select(nme.apply)
8080
.appliedTo(quotesTree)
8181
)

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object Splicer {
4444
* See: `Staging`
4545
*/
4646
def splice(tree: Tree, splicePos: SrcPos, spliceExpansionPos: SrcPos, classLoader: ClassLoader)(using Context): Tree = tree match {
47-
case Quote(quotedTree, Nil) => quotedTree
47+
case Quote(quotedTree, Nil, _) => quotedTree
4848
case _ =>
4949
val macroOwner = newSymbol(ctx.owner, nme.MACROkw, Macro | Synthetic, defn.AnyType, coord = tree.span)
5050
try
@@ -136,7 +136,7 @@ object Splicer {
136136
* See: `Staging`
137137
*/
138138
def checkValidMacroBody(tree: Tree)(using Context): Unit = tree match {
139-
case Quote(_, Nil) => // ok
139+
case Quote(_, Nil, _) => // ok
140140
case _ =>
141141
type Env = Set[Symbol]
142142

@@ -155,7 +155,7 @@ object Splicer {
155155
case Block(Nil, expr) => checkIfValidArgument(expr)
156156
case Typed(expr, _) => checkIfValidArgument(expr)
157157

158-
case Apply(Select(Quote(body, _), nme.apply), _) =>
158+
case Apply(Select(Quote(body, _, _), nme.apply), _) =>
159159
val noSpliceChecker = new TreeTraverser {
160160
def traverse(tree: Tree)(using Context): Unit = tree match
161161
case Splice(_) =>
@@ -203,7 +203,7 @@ object Splicer {
203203
case Typed(expr, _) =>
204204
checkIfValidStaticCall(expr)
205205

206-
case Apply(Select(Quote(quoted, Nil), nme.apply), _) =>
206+
case Apply(Select(Quote(quoted, Nil, _), nme.apply), _) =>
207207
// OK, canceled and warning emitted
208208

209209
case Call(fn, args)
@@ -240,7 +240,7 @@ object Splicer {
240240

241241
override protected def interpretTree(tree: Tree)(implicit env: Env): Object = tree match {
242242
// Interpret level -1 quoted code `'{...}` (assumed without level 0 splices)
243-
case Apply(Select(Quote(body, _), nme.apply), _) =>
243+
case Apply(Select(Quote(body, _, _), nme.apply), _) =>
244244
val body1 = body match {
245245
case expr: Ident if expr.symbol.isAllOf(InlineByNameProxy) =>
246246
// inline proxy for by-name parameter

compiler/src/dotty/tools/dotc/transform/Splicing.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Splicing extends MacroTransform:
8989
tree match
9090
case tree: Quote =>
9191
val body1 = QuoteTransformer().transform(tree.body)(using quoteContext)
92-
cpy.Quote(tree)(body1, tree.tags)
92+
cpy.Quote(tree)(body1, tree.tags, tree.tpt)
9393
case tree: DefDef if tree.symbol.is(Inline) =>
9494
// Quotes in inlined methods are only pickled after they are inlined.
9595
tree
@@ -217,7 +217,7 @@ class Splicing extends MacroTransform:
217217
else super.transform(tree)
218218
case CapturedApplication(fn, argss) =>
219219
transformCapturedApplication(tree, fn, argss)
220-
case Apply(Select(Quote(body, _), nme.apply), quotes :: Nil) if level == 0 && body.isTerm =>
220+
case Apply(Select(Quote(body, _, _), nme.apply), quotes :: Nil) if level == 0 && body.isTerm =>
221221
body match
222222
case _: RefTree if isCaptured(body.symbol) => capturedTerm(body)
223223
case _ => withCurrentQuote(quotes) { super.transform(tree) }
@@ -233,7 +233,7 @@ class Splicing extends MacroTransform:
233233
val (tags, body1) = inContextWithQuoteTypeTags {
234234
transform(quote.body)(using quoteContext)
235235
}
236-
cpy.Quote(quote)(body1, quote.tags ::: tags)
236+
cpy.Quote(quote)(body1, quote.tags ::: tags, quote.tpt)
237237

238238
class ArgsClause(val args: List[Tree]):
239239
def isTerm: Boolean = args.isEmpty || args.head.isTerm
@@ -334,7 +334,7 @@ class Splicing extends MacroTransform:
334334
}
335335
TypeTree(capturePartTypes(quote.body.tpe.widenTermRefExpr))
336336
}
337-
cpy.Quote(quote)(body1, quote.tags ::: tags)
337+
cpy.Quote(quote)(body1, quote.tags ::: tags, quote.tpt)
338338

339339
private def getTagRefFor(tree: Tree)(using Context): Tree =
340340
val capturedTypeSym = capturedType(tree)
@@ -361,7 +361,9 @@ class Splicing extends MacroTransform:
361361
Splice(closure, tpe)
362362

363363
private def quoted(expr: Tree)(using Context): Tree =
364-
tpd.Quote(expr, Nil).select(nme.apply).appliedTo(quotes.nn)
364+
tpd.Quote(expr, Nil, TypeTree(expr.tpe.widenTermRefExpr))
365+
.select(nme.apply)
366+
.appliedTo(quotes.nn)
365367

366368
/** Helper methods to construct trees calling methods in `Quotes.reflect` based on the current `quotes` tree */
367369
private object reflect extends ReifiedReflect {

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ object TreeChecker {
676676
assert(tag.typeOpt.derivesFrom(defn.QuotedTypeClass), i"expected Quote tag to be of type `Type` but was: ${tag.tpe}")
677677

678678
tree1 match
679-
case Quote(body, targ :: Nil) if body.isType =>
679+
case Quote(body, targ :: Nil, _) if body.isType =>
680680
assert(!(body.tpe =:= targ.tpe.select(tpnme.Underlying)), i"missed quote cancellation in $tree1")
681681
case _ =>
682682

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ object SpaceEngine {
312312
def isIrrefutableQuotedPattern(unapp: tpd.Tree, implicits: List[tpd.Tree], pt: Type)(using Context): Boolean = {
313313
implicits.headOption match
314314
// pattern '{ $x: T }
315-
case Some(tpd.Apply(tpd.Select(tpd.Quote(tpd.TypeApply(fn, List(tpt)), _), nme.apply), _))
315+
case Some(tpd.Apply(tpd.Select(tpd.Quote(tpd.TypeApply(fn, List(tpt)), _, _), nme.apply), _))
316316
if unapp.symbol.owner.eq(defn.QuoteMatching_ExprMatchModule)
317317
&& fn.symbol.eq(defn.QuotedRuntimePatterns_patternHole) =>
318318
pt <:< defn.QuotedExprClass.typeRef.appliedTo(tpt.tpe)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ trait QuotesAndSplices {
6262
// TODO typecheck directly (without `exprQuote`)
6363
val exprQuoteTree = untpd.Apply(untpd.ref(defn.QuotedRuntime_exprQuote.termRef), tree.body)
6464
val quotedExpr = typedApply(exprQuoteTree, pt)(using quoteContext) match
65-
case Apply(TypeApply(fn, tpt :: Nil), quotedExpr :: Nil) => untpd.Quote(quotedExpr, Nil).withBodyType(tpt.tpe)
65+
case Apply(TypeApply(fn, tpt :: Nil), quotedExpr :: Nil) => tpd.Quote(quotedExpr, Nil, tpt)
6666
makeInlineable(quotedExpr.select(nme.apply).appliedTo(quotes).withSpan(tree.span))
6767
}
6868

@@ -77,7 +77,7 @@ trait QuotesAndSplices {
7777
checkSpliceOutsideQuote(tree)
7878
assert(!ctx.mode.is(Mode.QuotedPattern))
7979
tree.expr match {
80-
case untpd.Quote(innerExpr, Nil) if innerExpr.isTerm =>
80+
case untpd.Quote(innerExpr, Nil, _) if innerExpr.isTerm =>
8181
report.warning("Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ.", tree.srcPos)
8282
return typed(innerExpr, pt)
8383
case _ =>
@@ -427,7 +427,7 @@ trait QuotesAndSplices {
427427

428428
val quoteClass = if (quoted.isTerm) defn.QuotedExprClass else defn.QuotedTypeClass
429429
val quotedPattern =
430-
if (quoted.isTerm) tpd.Quote(shape, Nil).select(nme.apply).appliedTo(quotes)
430+
if (quoted.isTerm) tpd.Quote(shape, Nil, TypeTree(defn.AnyType)).select(nme.apply).appliedTo(quotes)
431431
else ref(defn.QuotedTypeModule_of.termRef).appliedToTypeTree(shape).appliedTo(quotes)
432432

433433
val matchModule = if quoted.isTerm then defn.QuoteMatching_ExprMatch else defn.QuoteMatching_TypeMatch

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking
9696
typedApply(tree, selType)
9797

9898
override def typedQuote(tree: untpd.Quote, pt: Type)(using Context): Tree =
99-
assertTyped(tree)
100-
val body1 = typed(tree.body, tree.bodyType)(using quoteContext)
99+
val tpt1 =
100+
val tpt0 = typedType(tree.tpt, mapPatternBounds = true)
101+
if tree.body.isType then tpt0
102+
else checkSimpleKinded(tpt0)
103+
val expr1 = typed(tree.body, tpt1.tpe.widenSkolem)(using quoteContext)
101104
for tag <- tree.tags do assertTyped(tag)
102-
untpd.cpy.Quote(tree)(body1, tree.tags).withType(tree.typeOpt)
105+
assignType(untpd.cpy.Quote(tree)(expr1, tree.tags, tpt1), tpt1)
103106

104107
override def typedSplice(tree: untpd.Splice, pt: Type)(using Context): Tree =
105108
assertTyped(tree)

0 commit comments

Comments
 (0)