From adbf6392b1cbc0434c14b082f01b45c81a726fe0 Mon Sep 17 00:00:00 2001 From: Yevgen Date: Tue, 14 Nov 2017 09:58:21 +0100 Subject: [PATCH 1/2] Fix NPE when TypeVar tries to instantiate already instantiated variable with given type. --- compiler/src/dotty/tools/dotc/core/Types.scala | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 897b8a4b65b9..334170c19065 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -17,7 +17,6 @@ import Decorators._ import Denotations._ import Periods._ import Designators._ -import util.Positions.{Position, NoPosition} import util.Stats._ import util.DotClass import reporting.diagnostic.Message @@ -26,16 +25,14 @@ import ast.tpd._ import ast.TreeTypeMap import printing.Texts._ import ast.untpd -import dotty.tools.dotc.transform.Erasure import printing.Printer import Hashable._ import Uniques._ -import collection.{mutable, Seq, breakOut} +import collection.{mutable, Seq} import config.Config import annotation.tailrec import Flags.FlagSet import language.implicitConversions -import scala.util.hashing.{ MurmurHash3 => hashing } import config.Printers.{core, typr, cyclicErrors} import java.lang.ref.WeakReference @@ -936,7 +933,7 @@ object Types { } /** If this type contains embedded union types, replace them by their joins. - * "Embedded" means: inside intersectons or recursive types, or in prefixes of refined types. + * "Embedded" means: inside intersections or recursive types, or in prefixes of refined types. * If an embedded union is found, we first try to simplify or eliminate it by * re-lubbing it while allowing type parameters to be constrained further. * Any remaining union types are replaced by their joins. @@ -3295,7 +3292,7 @@ object Types { * @param creatorState The typer state in which the variable was created. * @param bindingTree The TypeTree which introduces the type variable, or EmptyTree * if the type variable does not correspond to a source term. - * @paran owner The current owner if the context where the variable was created. + * @param owner The current owner if the context where the variable was created. * * `owningTree` and `owner` are used to determine whether a type-variable can be instantiated * at some given point. See `Inferencing#interpolateUndetVars`. @@ -3332,7 +3329,7 @@ object Types { private def instantiateWith(tp: Type)(implicit ctx: Context): Type = { assert(tp ne this, s"self instantiation of ${tp.show}, constraint = ${ctx.typerState.constraint.show}") typr.println(s"instantiating ${this.show} with ${tp.show}") - if ((ctx.typerState eq owningState.get) && !ctx.typeComparer.subtypeCheckInProgress) + if (owningState != null && (ctx.typerState eq owningState.get) && !ctx.typeComparer.subtypeCheckInProgress) inst = tp ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp) tp From 34337896440345ba06b421007d4a390cedb805bc Mon Sep 17 00:00:00 2001 From: Yevgen Date: Wed, 15 Nov 2017 19:02:18 +0100 Subject: [PATCH 2/2] Add unit test for i3470 --- tests/neg/i3470.scala | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/neg/i3470.scala diff --git a/tests/neg/i3470.scala b/tests/neg/i3470.scala new file mode 100644 index 000000000000..78672fc7d100 --- /dev/null +++ b/tests/neg/i3470.scala @@ -0,0 +1,4 @@ +trait Factory[T <: Int]{ + def size: T + def create: Array[T] = Array.ofDim(size) // error +}