Skip to content

Commit adbf639

Browse files
committed
Fix NPE when TypeVar tries to instantiate already instantiated variable with given type.
1 parent 8b78497 commit adbf639

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import Decorators._
1717
import Denotations._
1818
import Periods._
1919
import Designators._
20-
import util.Positions.{Position, NoPosition}
2120
import util.Stats._
2221
import util.DotClass
2322
import reporting.diagnostic.Message
@@ -26,16 +25,14 @@ import ast.tpd._
2625
import ast.TreeTypeMap
2726
import printing.Texts._
2827
import ast.untpd
29-
import dotty.tools.dotc.transform.Erasure
3028
import printing.Printer
3129
import Hashable._
3230
import Uniques._
33-
import collection.{mutable, Seq, breakOut}
31+
import collection.{mutable, Seq}
3432
import config.Config
3533
import annotation.tailrec
3634
import Flags.FlagSet
3735
import language.implicitConversions
38-
import scala.util.hashing.{ MurmurHash3 => hashing }
3936
import config.Printers.{core, typr, cyclicErrors}
4037
import java.lang.ref.WeakReference
4138

@@ -936,7 +933,7 @@ object Types {
936933
}
937934

938935
/** If this type contains embedded union types, replace them by their joins.
939-
* "Embedded" means: inside intersectons or recursive types, or in prefixes of refined types.
936+
* "Embedded" means: inside intersections or recursive types, or in prefixes of refined types.
940937
* If an embedded union is found, we first try to simplify or eliminate it by
941938
* re-lubbing it while allowing type parameters to be constrained further.
942939
* Any remaining union types are replaced by their joins.
@@ -3295,7 +3292,7 @@ object Types {
32953292
* @param creatorState The typer state in which the variable was created.
32963293
* @param bindingTree The TypeTree which introduces the type variable, or EmptyTree
32973294
* if the type variable does not correspond to a source term.
3298-
* @paran owner The current owner if the context where the variable was created.
3295+
* @param owner The current owner if the context where the variable was created.
32993296
*
33003297
* `owningTree` and `owner` are used to determine whether a type-variable can be instantiated
33013298
* at some given point. See `Inferencing#interpolateUndetVars`.
@@ -3332,7 +3329,7 @@ object Types {
33323329
private def instantiateWith(tp: Type)(implicit ctx: Context): Type = {
33333330
assert(tp ne this, s"self instantiation of ${tp.show}, constraint = ${ctx.typerState.constraint.show}")
33343331
typr.println(s"instantiating ${this.show} with ${tp.show}")
3335-
if ((ctx.typerState eq owningState.get) && !ctx.typeComparer.subtypeCheckInProgress)
3332+
if (owningState != null && (ctx.typerState eq owningState.get) && !ctx.typeComparer.subtypeCheckInProgress)
33363333
inst = tp
33373334
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
33383335
tp

0 commit comments

Comments
 (0)