File tree 7 files changed +17
-4
lines changed
compiler/src/dotty/tools/dotc 7 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -94,4 +94,6 @@ object Mode {
94
94
/** We are in the IDE */
95
95
val Interactive = newMode(20 , " Interactive" )
96
96
97
+ /** Allow instantiating type variables after Typer */
98
+ val AllowTypevarsInstantiation = newMode(21 , " AllowTypevarsInstantiation" )
97
99
}
Original file line number Diff line number Diff line change @@ -310,6 +310,9 @@ object Phases {
310
310
*/
311
311
def isTyper = false
312
312
313
+ /** Is this phase an instance of TreeChecker ? */
314
+ def isTreeChecker = false
315
+
313
316
/** Can this transform create or delete non-private members? */
314
317
def changesMembers : Boolean = false
315
318
Original file line number Diff line number Diff line change @@ -3384,7 +3384,11 @@ object Types {
3384
3384
* uninstantiated
3385
3385
*/
3386
3386
def instanceOpt (implicit ctx : Context ): Type =
3387
- if (inst.exists) inst else ctx.typerState.instType(this )
3387
+ if (inst.exists) inst else {
3388
+ assert(ctx.phase.isTyper || ctx.phase.isTreeChecker || ctx.mode.is(Mode .AllowTypevarsInstantiation ),
3389
+ s " Detected uninstantiated type variable $this in phase ${ctx.phase}" )
3390
+ ctx.typerState.instType(this )
3391
+ }
3388
3392
3389
3393
/** Is the variable already instantiated? */
3390
3394
def isInstantiated (implicit ctx : Context ) = instanceOpt.exists
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class PatternMatcher extends MiniPhase {
32
32
val translated = new Translator (tree.tpe, this ).translateMatch(tree)
33
33
34
34
// check exhaustivity and unreachability
35
- val engine = new patmat.SpaceEngine
35
+ val engine = new patmat.SpaceEngine (ctx)
36
36
37
37
if (engine.checkable(tree)) {
38
38
engine.checkExhaustivity(tree)
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ class PatternMatcherOld extends MiniPhase with DenotTransformer {
51
51
val translated = new Translator ()(ctx).translator.translateMatch(tree)
52
52
53
53
// check exhaustivity and unreachability
54
- val engine = new SpaceEngine
54
+ val engine = new SpaceEngine (ctx)
55
55
if (engine.checkable(tree)) {
56
56
engine.checkExhaustivity(tree)
57
57
engine.checkRedundancy(tree)
Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ class TreeChecker extends Phase with SymTransformer {
49
49
import ast .tpd ._
50
50
import TreeChecker ._
51
51
52
+ override def isTreeChecker = true
53
+
52
54
private val seenClasses = collection.mutable.HashMap [String , Symbol ]()
53
55
private val seenModuleVals = collection.mutable.HashMap [String , Symbol ]()
54
56
Original file line number Diff line number Diff line change @@ -279,9 +279,11 @@ trait SpaceLogic {
279
279
}
280
280
281
281
/** Scala implementation of space logic */
282
- class SpaceEngine (implicit ctx : Context ) extends SpaceLogic {
282
+ class SpaceEngine (ictx : Context ) extends SpaceLogic {
283
283
import tpd ._
284
284
285
+ implicit val ctx : Context = ictx.addMode(Mode .AllowTypevarsInstantiation )
286
+
285
287
private val scalaSomeClass = ctx.requiredClass(" scala.Some" )
286
288
private val scalaSeqFactoryClass = ctx.requiredClass(" scala.collection.generic.SeqFactory" )
287
289
private val scalaListType = ctx.requiredClassRef(" scala.collection.immutable.List" )
You can’t perform that action at this time.
0 commit comments