@@ -35,14 +35,14 @@ trait QuotesAndSplices { self: Typer =>
35
35
* while tracking the quotation level in the context.
36
36
*/
37
37
def typedQuote (tree : untpd.Quote , pt : Type )(implicit ctx : Context ): Tree = track(" typedQuote" ) {
38
+ ctx.compilationUnit.needsStaging = true
38
39
tree.quoted match {
39
40
case untpd.Splice (innerExpr) if tree.isTerm =>
40
41
ctx.warning(" Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ." , tree.sourcePos)
41
42
case untpd.TypSplice (innerType) if tree.isType =>
42
43
ctx.warning(" Canceled splice directly inside a quote. '[ ${ XYZ } ] is equivalent to XYZ." , tree.sourcePos)
43
44
case _ =>
44
45
}
45
- ctx.compilationUnit.needsStaging = true
46
46
val tree1 =
47
47
if (tree.quoted.isType) typedTypeApply(untpd.TypeApply (untpd.ref(defn.InternalQuoted_typeQuote .termRef), tree.quoted :: Nil ), pt)(quoteContext)
48
48
else if (ctx.mode.is(Mode .Pattern ) && level == 0 ) typedQuotePattern(tree, pt)
@@ -52,36 +52,35 @@ trait QuotesAndSplices { self: Typer =>
52
52
53
53
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
54
54
def typedSplice (tree : untpd.Splice , pt : Type )(implicit ctx : Context ): Tree = track(" typedSplice" ) {
55
+ ctx.compilationUnit.needsStaging = true
55
56
checkSpliceOutsideQuote(tree)
56
57
tree.expr match {
57
58
case untpd.Quote (innerExpr) if innerExpr.isTerm =>
58
59
ctx.warning(" Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ." , tree.sourcePos)
59
- typed(innerExpr, pt)
60
- case expr =>
61
- ctx.compilationUnit.needsStaging = true
62
- if (ctx.mode.is(Mode .QuotedPattern ) && level == 1 ) {
63
- if (isFullyDefined(pt, ForceDegree .all)) {
64
- def spliceOwner (ctx : Context ): Symbol =
65
- if (ctx.mode.is(Mode .QuotedPattern )) spliceOwner(ctx.outer) else ctx.owner
66
- val pat = typedPattern(expr, defn.QuotedExprClass .typeRef.appliedTo(pt))(
67
- spliceContext.retractMode(Mode .QuotedPattern ).withOwner(spliceOwner(ctx)))
68
- Splice (pat)
69
- } else {
70
- ctx.error(i " Type must be fully defined. \n Consider annotating the splice using a type ascription: \n ( $tree: XYZ). " , expr.sourcePos)
71
- tree.withType(UnspecifiedErrorType )
72
- }
73
- }
74
- else {
75
- if (StagingContext .level == 0 ) {
76
- // Mark the first inline method from the context as a macro
77
- def markAsMacro (c : Context ): Unit =
78
- if (c.owner eq c.outer.owner) markAsMacro(c.outer)
79
- else if (c.owner.isInlineMethod) c.owner.setFlag(Macro )
80
- else if (! c.outer.owner.is(Package )) markAsMacro(c.outer)
81
- markAsMacro(ctx)
82
- }
83
- typedApply(untpd.Apply (untpd.ref(defn.InternalQuoted_exprSplice .termRef), tree.expr), pt)(spliceContext).withSpan(tree.span)
84
- }
60
+ case _ =>
61
+ }
62
+ if (ctx.mode.is(Mode .QuotedPattern ) && level == 1 ) {
63
+ if (isFullyDefined(pt, ForceDegree .all)) {
64
+ def spliceOwner (ctx : Context ): Symbol =
65
+ if (ctx.mode.is(Mode .QuotedPattern )) spliceOwner(ctx.outer) else ctx.owner
66
+ val pat = typedPattern(tree.expr, defn.QuotedExprClass .typeRef.appliedTo(pt))(
67
+ spliceContext.retractMode(Mode .QuotedPattern ).withOwner(spliceOwner(ctx)))
68
+ Splice (pat)
69
+ } else {
70
+ ctx.error(i " Type must be fully defined. \n Consider annotating the splice using a type ascription: \n ( $tree: XYZ). " , tree.expr.sourcePos)
71
+ tree.withType(UnspecifiedErrorType )
72
+ }
73
+ }
74
+ else {
75
+ if (StagingContext .level == 0 ) {
76
+ // Mark the first inline method from the context as a macro
77
+ def markAsMacro (c : Context ): Unit =
78
+ if (c.owner eq c.outer.owner) markAsMacro(c.outer)
79
+ else if (c.owner.isInlineMethod) c.owner.setFlag(Macro )
80
+ else if (! c.outer.owner.is(Package )) markAsMacro(c.outer)
81
+ markAsMacro(ctx)
82
+ }
83
+ typedApply(untpd.Apply (untpd.ref(defn.InternalQuoted_exprSplice .termRef), tree.expr), pt)(spliceContext).withSpan(tree.span)
85
84
}
86
85
}
87
86
@@ -92,30 +91,29 @@ trait QuotesAndSplices { self: Typer =>
92
91
tree.expr match {
93
92
case untpd.Quote (innerType) if innerType.isType =>
94
93
ctx.warning(" Canceled quote directly inside a splice. ${ '[ XYZ ] } is equivalent to XYZ." , tree.sourcePos)
95
- typed(innerType, pt)
96
- case expr =>
97
- if (ctx.mode.is(Mode .QuotedPattern ) && level == 1 ) {
98
- if (isFullyDefined(pt, ForceDegree .all)) {
99
- ctx.error(i " Spliced type pattern must not be fully defined. Consider using $pt directly " , tree.expr.sourcePos)
100
- tree.withType(UnspecifiedErrorType )
101
- } else {
102
- def spliceOwner (ctx : Context ): Symbol =
103
- if (ctx.mode.is(Mode .QuotedPattern )) spliceOwner(ctx.outer) else ctx.owner
104
- val name = expr match {
105
- case Ident (name) => (" $" + name).toTypeName
106
- case Typed (Ident (name), _) => (" $" + name).toTypeName
107
- case Bind (name, _) => (" $" + name).toTypeName
108
- case _ => NameKinds .UniqueName .fresh(" $" .toTypeName)
109
- }
110
- val typeSym = ctx.newSymbol(spliceOwner(ctx), name, EmptyFlags , TypeBounds .empty, NoSymbol , expr.span)
111
- typeSym.addAnnotation(Annotation (New (ref(defn.InternalQuoted_patternBindHoleAnnot .typeRef)).withSpan(expr.span)))
112
- val pat = typedPattern(expr, defn.QuotedTypeClass .typeRef.appliedTo(typeSym.typeRef))(
113
- spliceContext.retractMode(Mode .QuotedPattern ).withOwner(spliceOwner(ctx)))
114
- pat.select(tpnme.splice)
115
- }
116
- } else {
117
- typedSelect(untpd.Select (tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span)
94
+ case _ =>
95
+ }
96
+ if (ctx.mode.is(Mode .QuotedPattern ) && level == 1 ) {
97
+ if (isFullyDefined(pt, ForceDegree .all)) {
98
+ ctx.error(i " Spliced type pattern must not be fully defined. Consider using $pt directly " , tree.expr.sourcePos)
99
+ tree.withType(UnspecifiedErrorType )
100
+ } else {
101
+ def spliceOwner (ctx : Context ): Symbol =
102
+ if (ctx.mode.is(Mode .QuotedPattern )) spliceOwner(ctx.outer) else ctx.owner
103
+ val name = tree.expr match {
104
+ case Ident (name) => (" $" + name).toTypeName
105
+ case Typed (Ident (name), _) => (" $" + name).toTypeName
106
+ case Bind (name, _) => (" $" + name).toTypeName
107
+ case _ => NameKinds .UniqueName .fresh(" $" .toTypeName)
118
108
}
109
+ val typeSym = ctx.newSymbol(spliceOwner(ctx), name, EmptyFlags , TypeBounds .empty, NoSymbol , tree.expr.span)
110
+ typeSym.addAnnotation(Annotation (New (ref(defn.InternalQuoted_patternBindHoleAnnot .typeRef)).withSpan(tree.expr.span)))
111
+ val pat = typedPattern(tree.expr, defn.QuotedTypeClass .typeRef.appliedTo(typeSym.typeRef))(
112
+ spliceContext.retractMode(Mode .QuotedPattern ).withOwner(spliceOwner(ctx)))
113
+ pat.select(tpnme.splice)
114
+ }
115
+ } else {
116
+ typedSelect(untpd.Select (tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span)
119
117
}
120
118
}
121
119
0 commit comments