@@ -9,14 +9,13 @@ import util.Positions._
9
9
import StdNames ._
10
10
import ast .untpd
11
11
import MegaPhase .MiniPhase
12
- import typer .Implicits ._
13
12
import NameKinds .OuterSelectName
14
13
import scala .collection .mutable
15
14
16
15
/** Translates quoted terms and types to `unpickle` method calls.
17
16
* Checks that the phase consistency principle (PCP) holds.
18
17
*/
19
- class ReifyQuotes extends MacroTransformWithImplicits {
18
+ class ReifyQuotes extends MacroTransform {
20
19
import ast .tpd ._
21
20
22
21
override def phaseName : String = " reifyQuotes"
@@ -41,7 +40,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
41
40
def pickleTree (tree : Tree , isType : Boolean )(implicit ctx : Context ): String =
42
41
tree.show // TODO: replace with TASTY
43
42
44
- private class Reifier extends ImplicitsTransformer {
43
+ private class Reifier extends Transformer {
45
44
46
45
/** A class for collecting the splices of some quoted expression */
47
46
private class Splices {
@@ -83,7 +82,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
83
82
val (trefs, tags) = assocs.unzip
84
83
tags ++=: buf
85
84
typeTagOfRef.clear()
86
- Block (typeDefs, expr) .subst(trefs.map(_.symbol), typeDefs.map(_.symbol))
85
+ Block (typeDefs, expr.subst(trefs.map(_.symbol), typeDefs.map(_.symbol) ))
87
86
}
88
87
}
89
88
@@ -113,39 +112,17 @@ class ReifyQuotes extends MacroTransformWithImplicits {
113
112
* check that its staging level matches the current level. References to types
114
113
* that are phase-incorrect can still be healed as follows.
115
114
*
116
- * If `T` is a reference to a type at the wrong level, and there is an implicit value `tag`
117
- * of type `quoted.Type[T]`, transform `tag` yielding `tag1` and add the binding `T -> tag1`
118
- * to the `typeTagOfRef` map of the current `Splices` structure. These entries will be turned
119
- * info additional type definitions in method `addTags`.
115
+ * If `T` is a reference to a type at the wrong level, heal it by setting things up
116
+ * so that we later add a type definition
117
+ *
118
+ * type T' = ~quoted.Type[T]
119
+ *
120
+ * to the quoted text and rename T to T' in it. This is done later in `reify` via
121
+ * `Splice#addTags`. checkLevel itself only records what needs to be done in the
122
+ * `typeTagOfRef` field of the current `Splice` structure.
120
123
*/
121
124
private def checkLevel (tree : Tree )(implicit ctx : Context ): Tree = {
122
125
123
- /** Try to heal phase-inconsistent reference to type `T` using a local type definition.
124
- * @return None if successful
125
- * @return Some(msg) if unsuccessful where `msg` is a potentially empty error message
126
- * to be added to the "inconsistent phase" message.
127
- */
128
- def heal (tp : Type ): Option [String ] = tp match {
129
- case tp : TypeRef =>
130
- val reqType = defn.QuotedTypeType .appliedTo(tp)
131
- val tag = ctx.typer.inferImplicitArg(reqType, tree.pos)
132
- tag.tpe match {
133
- case fail : SearchFailureType =>
134
- Some (i """
135
- |
136
- | The access would be accepted with the right type tag, but
137
- | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
138
- case _ =>
139
- splicesAtLevel(currentLevel).typeTagOfRef(tp) = {
140
- currentLevel -= 1
141
- try transform(tag) finally currentLevel += 1
142
- }
143
- None
144
- }
145
- case _ =>
146
- Some (" " )
147
- }
148
-
149
126
/** Check reference to `sym` for phase consistency, where `tp` is the underlying type
150
127
* by which we refer to `sym`.
151
128
*/
@@ -160,12 +137,18 @@ class ReifyQuotes extends MacroTransformWithImplicits {
160
137
else if (sym.exists && ! sym.isStaticOwner &&
161
138
! ctx.owner.ownersIterator.exists(_.isInlineMethod) &&
162
139
levelOf.getOrElse(sym, currentLevel) != currentLevel)
163
- heal(tp) match {
164
- case Some (errMsg) =>
140
+ tp match {
141
+ case tp : TypeRef =>
142
+ // Legalize reference to phase-inconstent type
143
+ splicesAtLevel(currentLevel).typeTagOfRef(tp) = {
144
+ currentLevel -= 1
145
+ val tag = New (defn.QuotedTypeType .appliedTo(tp), Nil )
146
+ try transform(tag) finally currentLevel += 1
147
+ }
148
+ case _ =>
165
149
ctx.error(em """ access to $symStr from wrong staging level:
166
150
| - the definition is at level ${levelOf(sym)},
167
- | - but the access is at level $currentLevel. $errMsg""" , tree.pos)
168
- case None =>
151
+ | - but the access is at level $currentLevel. """ , tree.pos)
169
152
}
170
153
}
171
154
0 commit comments