From afb541ade2fc83f47661e1d94cee00f7a4b32178 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Apr 2014 14:49:40 +0200 Subject: Fix of TyperState#instType If a type variable TV1 is instantiated to a poly param, and the poly param is itself accomanied by a type variable TV2, then the instance of TV1 should be TV2 and not the original poly param. Otherwise we lose instantiations. This is demonstrated by running dotc on the .scala files in the dotc directory itself with option -Ycheck. --- src/dotty/tools/dotc/core/Constraint.scala | 5 ++++- src/dotty/tools/dotc/core/TyperState.scala | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/Constraint.scala b/src/dotty/tools/dotc/core/Constraint.scala index 64fb8764e..d3d19ec30 100644 --- a/src/dotty/tools/dotc/core/Constraint.scala +++ b/src/dotty/tools/dotc/core/Constraint.scala @@ -66,7 +66,10 @@ class Constraint(val myMap: SimpleMap[PolyType, Array[Type]]) extends Showable { def typeVarOfParam(param: PolyParam): Type = { val entries = myMap(param.binder) if (entries == null) NoType - else typeVar(entries, param.paramNum) + else { + val tvar = typeVar(entries, param.paramNum) + if (tvar != null) tvar else NoType + } } /** A new constraint which is derived from this constraint by adding or replacing diff --git a/src/dotty/tools/dotc/core/TyperState.scala b/src/dotty/tools/dotc/core/TyperState.scala index a4b365b17..65cebf967 100644 --- a/src/dotty/tools/dotc/core/TyperState.scala +++ b/src/dotty/tools/dotc/core/TyperState.scala @@ -27,6 +27,9 @@ class TyperState(val reporter: Reporter) extends DotClass with Showable { */ def instType(tvar: TypeVar): Type = constraint.at(tvar.origin) match { case _: TypeBounds => NoType + case tp: PolyParam => + var tvar1 = constraint.typeVarOfParam(tp) + if (tvar1.exists) tvar1 else tp case tp => tp } -- cgit v1.2.3