diff options
author | Martin Odersky <odersky@gmail.com> | 2007-08-31 17:49:30 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-08-31 17:49:30 +0000 |
commit | 77de72ce86f2fd83c646cfc1c5fd21de26318477 (patch) | |
tree | e28789cd82b5634b7aedf17a20f1ec8ce58e2311 | |
parent | 26109cdb6b024a09783e9ff1e0bb7ac64597a689 (diff) | |
download | scala-77de72ce86f2fd83c646cfc1c5fd21de26318477.tar.gz scala-77de72ce86f2fd83c646cfc1c5fd21de26318477.tar.bz2 scala-77de72ce86f2fd83c646cfc1c5fd21de26318477.zip |
fixed ticket 40 (matcherror with existential ty...
fixed ticket 40 (matcherror with existential types)
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 24 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 3017d0e74b..ad2b0d1559 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -1637,6 +1637,15 @@ A type's typeSymbol should never be inspected directly. } override def kind = "ExistentialType" + + def withTypeVars(op: Type => Boolean): Boolean = { + val tvars = quantified map (tparam => new TypeVar(tparam.tpe, new TypeConstraint)) + val underlying1 = underlying.instantiateTypeParams(quantified, tvars) + op(underlying1) && { + solve(tvars, quantified, quantified map (x => 0), false) + isWithinBounds(NoPrefix, NoSymbol, quantified, tvars map (_.constr.inst)) + } + } } /** A class containing the alternatives and type prefix of an overloaded symbol. @@ -2740,6 +2749,10 @@ A type's typeSymbol should never be inspected directly. //if (tparam.variance == 0 && !(arg1 =:= arg2)) Console.println("inconsistent: "+arg1+"!="+arg2)//DEBUG tparam.variance != 0 || arg1 =:= arg2 } contains false) + case (et: ExistentialType, _) => + et.withTypeVars(isConsistent(_, tp2)) + case (_, et: ExistentialType) => + et.withTypeVars(isConsistent(tp1, _)) } if (tp1.typeSymbol.isClass && tp1.typeSymbol.hasFlag(FINAL)) tp1 <:< tp2 || isNumericValueClass(tp1.typeSymbol) && isNumericValueClass(tp2.typeSymbol) @@ -3083,15 +3096,8 @@ A type's typeSymbol should never be inspected directly. } finally { skolemizationLevel -= 1 } - case (_, ExistentialType(tparams2, res2)) => - val tvars = tparams2 map (tparam => new TypeVar(tparam.tpe, new TypeConstraint)) - val ires2 = res2.instantiateTypeParams(tparams2, tvars) - (tp1 <:< ires2) && { - //println("solve: "+tparams2) - solve(tvars, tparams2, tparams2 map (x => 0), false) - //println("check bounds: "+tparams2+" aginst "+(tvars map (_.constr.inst))) - isWithinBounds(NoPrefix, NoSymbol, tparams2, tvars map (_.constr.inst)) - } + case (_, et: ExistentialType) => + et.withTypeVars(tp1 <:< _) case (RefinedType(parents1, ref1), _) => parents1 exists (_ <:< tp2) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3909b42ead..7d6dc74edd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -16,6 +16,8 @@ import scala.tools.nsc.util.{HashSet, Position, Set, NoPosition} import symtab.Flags._ import util.HashSet +// Suggestion check whether we can do without priminng scopes with symbols of outer scopes, +// like the IDE does. /** This trait provides methods to assign types to trees. * * @author Martin Odersky |