diff options
-rw-r--r-- | sources/meta/scala/MetaFunction.java | 2 | ||||
-rw-r--r-- | sources/meta/scalac/ast/Tree.java | 8 | ||||
-rw-r--r-- | sources/scala/PartialFunction.scala | 2 | ||||
-rw-r--r-- | sources/scalac/ast/parser/Parser.java | 26 | ||||
-rw-r--r-- | sources/scalac/ast/printer/TextTreePrinter.java | 5 | ||||
-rw-r--r-- | sources/scalac/backend/jvm/GenJVM.java | 1 | ||||
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 4 | ||||
-rw-r--r-- | sources/scalac/symtab/SymbolMapApplier.java | 3 | ||||
-rw-r--r-- | sources/scalac/symtab/Type.java | 178 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/AttributeParser.java | 9 | ||||
-rw-r--r-- | sources/scalac/transformer/AddInterfaces.java | 2 | ||||
-rw-r--r-- | sources/scalac/transformer/Erasure.java | 1 | ||||
-rw-r--r-- | sources/scalac/transformer/PatternMatcher.java | 2 | ||||
-rw-r--r-- | sources/scalac/transformer/matching/PatternMatcher.java | 2 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 36 | ||||
-rw-r--r-- | sources/scalac/typechecker/DeSugarize.java | 32 | ||||
-rw-r--r-- | sources/scalac/typechecker/Infer.java | 27 | ||||
-rw-r--r-- | sources/scalac/util/Debug.java | 6 |
18 files changed, 56 insertions, 290 deletions
diff --git a/sources/meta/scala/MetaFunction.java b/sources/meta/scala/MetaFunction.java index 3bcf4cc4c6..4f8c441e72 100644 --- a/sources/meta/scala/MetaFunction.java +++ b/sources/meta/scala/MetaFunction.java @@ -38,7 +38,7 @@ public class MetaFunction extends AbstractJavaExpander { public void printClassScalaTParams() { for (int i = 0; i < arity; i++) writer.print("?A").print(i).print(", "); - writer.print("?R"); + writer.print("+ ?R"); } public void printApplyScalaSignature() { diff --git a/sources/meta/scalac/ast/Tree.java b/sources/meta/scalac/ast/Tree.java index 02bb466d08..d596549522 100644 --- a/sources/meta/scalac/ast/Tree.java +++ b/sources/meta/scalac/ast/Tree.java @@ -100,8 +100,7 @@ public class Tree { n_SelectFromType = node("SelectFromType", Type, HasSym), n_FunType = node("FunType" , Type, NoSym), n_CompoundType = node("CompoundType" , Type, NoSym), - n_AppliedType = node("AppliedType" , Type, NoSym), - n_CovariantType = node("CovariantType" , Type, NoSym); + n_AppliedType = node("AppliedType" , Type, NoSym); public final TreeNode[] nodes; public int arrays; @@ -323,11 +322,6 @@ public class Tree { addField(t_TypeTree, "tpe"). addField(t_TypeTrees, "args"); - n_CovariantType. - setDescription("Covariant type"). - setRange(Phase.PARSER, Phase.ANALYZER). - addField(t_TypeTree, "tpe"); - } //######################################################################## diff --git a/sources/scala/PartialFunction.scala b/sources/scala/PartialFunction.scala index 9d8f8adbad..58e797b3f4 100644 --- a/sources/scala/PartialFunction.scala +++ b/sources/scala/PartialFunction.scala @@ -9,7 +9,7 @@ // $Id$ package scala { - trait PartialFunction[A, B] { + trait PartialFunction[A, +B] { def apply(x: A): B; def isDefinedAt(x: A): scala.Boolean; } diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index 589d33c31c..de959552dd 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -616,7 +616,7 @@ public class Parser implements Tokens { if (s.token == HASH) t = make.SelectFromType(s.skipToken(), t, ident().toTypeName()); else if (s.token == LBRACKET) - t = make.AppliedType(pos, t, varTypeArgs());//todo: change to typeArgs + t = make.AppliedType(pos, t, typeArgs()); else break; } return t; @@ -631,30 +631,6 @@ public class Parser implements Tokens { return ts; } - /** VarTypeArgs ::= `[' VarType {`,' VarType} `]' - */ - Tree[] varTypeArgs() { - int pos = accept(LBRACKET); - TreeList ts = new TreeList(); - ts.append(varType()); - while (s.token == COMMA) { - s.nextToken(); - ts.append(varType()); - } - accept(RBRACKET); - return ts.toArray(); - } - - /** VarType ::= [`+'] Type - */ - Tree varType() { - int pos = s.pos; - if (s.token == IDENTIFIER && s.name == PLUS) - return make.CovariantType(s.skipToken(), type()); - else - return type(); - } - //////// EXPRESSIONS //////////////////////////////////////////////////////// /** EqualsExpr ::= `=' Expr diff --git a/sources/scalac/ast/printer/TextTreePrinter.java b/sources/scalac/ast/printer/TextTreePrinter.java index 54f2764dab..5c6e04ddc9 100644 --- a/sources/scalac/ast/printer/TextTreePrinter.java +++ b/sources/scalac/ast/printer/TextTreePrinter.java @@ -527,11 +527,6 @@ public class TextTreePrinter implements TreePrinter { print(TXT_RIGHT_BRACKET); break; - case CovariantType(Tree tpe): - print(TXT_PLUS); - print(tpe); - break; - case Template(Tree[] parents, Tree[] body): Debug.abort("unexpected case", tree); break; diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java index c4b4909e75..ed8d40023e 100644 --- a/sources/scalac/backend/jvm/GenJVM.java +++ b/sources/scalac/backend/jvm/GenJVM.java @@ -462,7 +462,6 @@ class GenJVM { case TypeApply(_, _): case FunType(_, _): case CompoundType(_, _): - case CovariantType(_): case AppliedType(_,_): break; diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index 5f2bf4735c..b2dc7ac8ae 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -424,7 +424,7 @@ public class Definitions { public Type functionType(Type[] argtps, Type restp) { Type[] argtps1 = new Type[argtps.length + 1]; System.arraycopy(argtps, 0, argtps1, 0, argtps.length); - argtps1[argtps.length] = Type.covarType(restp); + argtps1[argtps.length] = restp; return Type.appliedType( getType(Name.fromString("scala.Function" + argtps.length)), argtps1); @@ -433,7 +433,7 @@ public class Definitions { public Type partialFunctionType(Type argtpe, Type restpe) { Type[] argtps1 = new Type[2]; argtps1[0] = argtpe; - argtps1[1] = Type.covarType(restpe); + argtps1[1] = restpe; return Type.appliedType(PARTIALFUNCTION_CLASS.typeConstructor(), argtps1); } diff --git a/sources/scalac/symtab/SymbolMapApplier.java b/sources/scalac/symtab/SymbolMapApplier.java index b8f0b6978f..56d01ff9e6 100644 --- a/sources/scalac/symtab/SymbolMapApplier.java +++ b/sources/scalac/symtab/SymbolMapApplier.java @@ -71,9 +71,6 @@ public class SymbolMapApplier { case OverloadedType(Symbol[] alts, Type[] alttypes): return new Type.OverloadedType(apply(alts), apply(alttypes)); - case CovarType(Type result): - return Type.CovarType(apply(result)); - default: throw new ApplicationError("unknown type " + type); } diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index f61720c44d..ae0f830304 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -41,12 +41,6 @@ public class Type implements Modifiers, Kinds, TypeTags { public case PolyType(Symbol[] tparams, Type result); public case OverloadedType(Symbol[] alts, Type[] alttypes); - /** Type such as +T. Only used as type arguments. - */ - public case CovarType(Type tp) { - assert !(tp instanceof CovarType); - } - /** Hidden case to implement delayed evaluation of types. * No need to pattern match on this type; it will never come up. */ @@ -100,11 +94,6 @@ public class Type implements Modifiers, Kinds, TypeTags { } } - public static CovarType covarType(Type tp) { - if (tp instanceof CovarType) return (CovarType)tp; - else return CovarType(tp); - } - public static CompoundType compoundType(Type[] parts, Scope members, Symbol clazz) { ExtCompoundType res = new ExtCompoundType(parts, members); @@ -445,19 +434,6 @@ public class Type implements Modifiers, Kinds, TypeTags { return this; } - /** If this is a covariant type, its underlying type, otherwise the type itself. - */ - public Type dropVariance() { - switch (this) { - case CovarType(Type tp): return tp; - default: return this; - } - } - - public static Map dropVarianceMap = new Map() { - public Type apply(Type t) { return t.dropVariance(); } - }; - // Tests -------------------------------------------------------------------- /** Is this type a this type or singleton type? @@ -504,17 +480,6 @@ public class Type implements Modifiers, Kinds, TypeTags { } } - /** Is this type a covariant type? - */ - public boolean isCovarType() { - switch (this) { - case CovarType(_): - return true; - default: - return false; - } - } - /** Is this type of the form scala.FunctionN[T_1, ..., T_n, +T] or * scala.Object with scala.FunctionN[T_1, ..., T_n, +T]? */ @@ -522,9 +487,7 @@ public class Type implements Modifiers, Kinds, TypeTags { switch (this) { case TypeRef(Type pre, Symbol sym, Type[] args): if (sym.fullName().startsWith(Names.scala_Function)) { - for (int i = 0; i < args.length - 1; i++) - if (args[i].isCovarType()) return false; - return args.length > 0; // !!! && args[args.length - 1].isCovarType(); + return args.length > 0; } break; case CompoundType(Type[] parents, Scope members): @@ -626,8 +589,6 @@ public class Type implements Modifiers, Kinds, TypeTags { */ public abstract static class Map { - boolean covariantOK = true; - public abstract Type apply(Type t); /** Apply map to all top-level components of this type. @@ -677,16 +638,12 @@ public class Type implements Modifiers, Kinds, TypeTags { } case MethodType(Symbol[] vparams, Type result): - covariantOK = false; Symbol[] vparams1 = map(vparams); - covariantOK = true; Type result1 = apply(result); if (vparams1 == vparams && result1 == result) return tp; else return MethodType(vparams1, result1); case PolyType(Symbol[] tparams, Type result): - covariantOK = false; Symbol[] tparams1 = map(tparams); - covariantOK = true; Type result1 = apply(result); if (tparams1 != tparams) result1 = result1.subst(tparams, tparams1); if (tparams1 == tparams && result1 == result) return tp; @@ -695,10 +652,6 @@ public class Type implements Modifiers, Kinds, TypeTags { Type[] alttypes1 = map(alttypes); if (alttypes1 == alttypes) return tp; else return OverloadedType(alts, alttypes1); - case CovarType(Type t): - Type t1 = apply(t); - if (t1 == t) return tp; - else return covarType(t1); case UnboxedArrayType(Type elemtp): Type elemtp1 = apply(elemtp); if (elemtp1 == elemtp) return tp; @@ -831,8 +784,6 @@ public class Type implements Modifiers, Kinds, TypeTags { private Type pre; private Symbol clazz; - private Type illegalType = NoType; - private boolean typeArg = false; AsSeenFromMap(Type pre, Symbol clazz) { this.pre = pre; this.clazz = clazz; @@ -858,24 +809,13 @@ public class Type implements Modifiers, Kinds, TypeTags { assert sym.kind == TYPE; Type t1 = t.toInstance(pre, clazz); //System.out.println(t + ".toInstance(" + pre + "," + clazz + ") = " + t1);//DEBUG - switch (t1) { - case CovarType(Type tp): - if (!covariantOK) { - if (illegalType == NoType) illegalType = t1; - } else if (!typeArg) { - t1 = tp; - } - } return t1; } else { //Type prefix1 = prefix.toPrefix(pre, clazz); Type prefix1 = apply(prefix); Symbol sym1 = (prefix1 == prefix || (sym.flags & MODUL) != 0) ? sym : prefix1.rebind(sym); - boolean prevTypeArg = typeArg; - typeArg = true; Type[] args1 = map(args); - typeArg = prevTypeArg; if (prefix1 == prefix && args1 == args) return t; else return typeRef(prefix1, sym1, args1); } @@ -893,14 +833,6 @@ public class Type implements Modifiers, Kinds, TypeTags { return map(t); } } - - void checkLegal(Type tp) { - if (illegalType != NoType) { - throw new ApplicationError( - "malformed type: " + tp + "; " + - illegalType + " does not occur in covariant position"); - } - } } //where Type toInstance(Type pre, Symbol clazz) { @@ -944,20 +876,13 @@ public class Type implements Modifiers, Kinds, TypeTags { */ public Type asSeenFrom(Type pre, Symbol clazz) { //System.out.println("computing asseenfrom of " + this + " with " + pre + "," + clazz);//DEBUG - AsSeenFromMap f = new AsSeenFromMap(pre, clazz); - Type t = f.apply(this); - f.checkLegal(t); - return t; + return new AsSeenFromMap(pre, clazz).apply(this); } /** Types `these' as seen from prefix `pre' and class `clazz'. */ public static Type[] asSeenFrom(Type[] these, Type pre, Symbol clazz) { - AsSeenFromMap f = new AsSeenFromMap(pre, clazz); - Type[] these1 = f.map(these); - for (int i = 0; i < these1.length; i++) - f.checkLegal(these1[i]); - return these1; + return new AsSeenFromMap(pre, clazz).map(these); } /** The info of `sym', seen as a member of this type. @@ -1337,7 +1262,7 @@ public class Type implements Modifiers, Kinds, TypeTags { //todo: should we test for equality with origin? if (constr.inst != NoType) { return this.isSubType(constr.inst); - } else if (!this.isCovarType()) { + } else { constr.lobounds = new List(this, constr.lobounds); return true; } @@ -1358,8 +1283,7 @@ public class Type implements Modifiers, Kinds, TypeTags { if (constr.inst != NoType) { return constr.inst.isSubType(that); } else { - constr.hibounds = new List(that.dropVariance(), constr.hibounds); - assert that.dropVariance().symbol() != Global.instance.definitions.ALL_CLASS;//debug + constr.hibounds = new List(that, constr.hibounds); return true; } @@ -1412,23 +1336,12 @@ public class Type implements Modifiers, Kinds, TypeTags { static boolean isSubArgs(Type[] these, Type[] those, Symbol[] tparams) { if (these.length != those.length) return false; for (int i = 0; i < these.length; i++) { - switch (those[i]) { - case CovarType(Type tp1): - switch (these[i]) { - case CovarType(Type tp): - if (!tp.isSubType(tp1)) return false; - break; - default: - if (!these[i].isSubType(tp1)) return false; - } - break; - default: - if (these[i].isCovarType()) return false; - if ((tparams[i].flags & COVARIANT) != 0) { - if (!these[i].isSubType(those[i])) return false; - } else { - if (!these[i].isSameAs(those[i])) return false; - } + if ((tparams[i].flags & COVARIANT) != 0) { + if (!these[i].isSubType(those[i])) return false; + } else if ((tparams[i].flags & CONTRAVARIANT) != 0) { + if (!those[i].isSubType(these[i])) return false; + } else { + if (!these[i].isSameAs(those[i])) return false; } } return true; @@ -1539,7 +1452,7 @@ public class Type implements Modifiers, Kinds, TypeTags { case TypeRef(Type pre, Symbol sym, Type[] args): switch (that) { case TypeRef(Type pre1, Symbol sym1, Type[] args1): - if (sym == sym1 && pre.isSameAs(pre1) && isSameArgs(args, args1)) + if (sym == sym1 && pre.isSameAs(pre1) && isSameAs(args, args1)) return true; } break; @@ -1610,23 +1523,19 @@ public class Type implements Modifiers, Kinds, TypeTags { case NoType: return false; case TypeVar(Type origin, Constraint constr): - if (constr.inst != NoType) - return constr.inst.isSameAs(this); - else if (!this.isCovarType()) - return constr.instantiate(this.any2typevar()); + if (constr.inst != NoType) return constr.inst.isSameAs(this); + else return constr.instantiate(this.any2typevar()); } switch (this) { case NoType: return false; - case TypeVar(Type origin, Constraint constr): - if (constr.inst != NoType) - return constr.inst.isSameAs(that); - else if (!that.isCovarType()) - return constr.instantiate(that.any2typevar()); - break; case TypeRef(_, Symbol sym, _): if (sym.kind == ALIAS) return this.unalias().isSameAs(that); + break; + case TypeVar(Type origin, Constraint constr): + if (constr.inst != NoType) return constr.inst.isSameAs(that); + else return constr.instantiate(that.any2typevar()); } switch (that) { @@ -1637,19 +1546,6 @@ public class Type implements Modifiers, Kinds, TypeTags { return false; } - /** Is this type argument that same as `that'? - */ - public boolean isSameArg(Type that) { - switch (this) { - case CovarType(Type tp): - switch (that) { - case CovarType(Type tp1): - return tp.isSameAs(tp1); - } - } - return this.isSameAs(that); - } - /** Are types `these' the same as corresponding types `those'? */ public static boolean isSameAs(Type[] these, Type[] those) { @@ -1660,16 +1556,6 @@ public class Type implements Modifiers, Kinds, TypeTags { return true; } - /** Are type arguments `these' the same as corresponding types `those'? - */ - public static boolean isSameArgs(Type[] these, Type[] those) { - if (these.length != those.length) return false; - for (int i = 0; i < these.length; i++) { - if (!these[i].isSameArg(those[i])) return false; - } - return true; - } - /** Do scopes `s1' and `s2' define he same symbols with the same kinds and infos? */ public boolean isSameAs(Scope s1, Scope s2) { @@ -1852,14 +1738,10 @@ public class Type implements Modifiers, Kinds, TypeTags { } } for (int j = 0; j < args.length; j++) { - if ((tparams[j].flags & COVARIANT) != 0) { - args[j] = commonType(argss[j]); - if (args[j] == NoType) - args[j] = lub(argss[j]); - } else { //todo: test if all same, return notype otherwise. - args[j] = commonType(argss[j]); - if (args[j] == NoType) - args[j] = CovarType(lub(argss[j])); + args[j] = commonType(argss[j]); + if (args[j] == NoType) { + if ((tparams[j].flags & COVARIANT) != 0) args[j] = lub(argss[j]); + else return NoType; } } return typeRef(pre, sym, args); @@ -2139,8 +2021,6 @@ public class Type implements Modifiers, Kinds, TypeTags { case CompoundType(Type[] parents, _): if (parents.length > 0) return parents[0].erasure(); else return this; - case CovarType(Type tp): - return tp.erasure(); // note: needed because of UnboxedArrayType case MethodType(Symbol[] params, Type tp): Symbol[] params1 = erasureMap.map(params); Type tp1 = tp.fullErasure(); @@ -2198,7 +2078,7 @@ public class Type implements Modifiers, Kinds, TypeTags { Type[] params = new Type[args.length - 1]; System.arraycopy(args, 0, params, 0, params.length); return ArrayApply.toString(params, "(", ",", ") => ") + - args[params.length].dropVariance(); + args[params.length]; } else if (sym.isAnonymousClass()) { return "<template: " + ArrayApply.toString( @@ -2245,8 +2125,6 @@ public class Type implements Modifiers, Kinds, TypeTags { case PolyType(Symbol[] tparams, Type result): return ArrayApply.toString(Symbol.defString(tparams), "[", ",", "]") + result; - case CovarType(Type tp): - return "+" + tp; case OverloadedType(Symbol[] alts, Type[] alttypes): return ArrayApply.toString(alttypes, "", " <and> ", ""); case TypeVar(Type origin, Constraint constr): @@ -2344,9 +2222,6 @@ public class Type implements Modifiers, Kinds, TypeTags { return POLYtpe ^ (hashCode(tparams) * 41) ^ (result.hashCode() * (41 * 41)); - case CovarType(Type tp): - return COVARtpe - ^ (tp.hashCode() * (41)); case OverloadedType(Symbol[] alts, Type[] alttypes): return OVERLOADEDtpe ^ (hashCode(alts) * 41) @@ -2428,12 +2303,6 @@ public class Type implements Modifiers, Kinds, TypeTags { return equals(tparams, tparams1) && result.equals(result1); default: return false; } - case CovarType(Type tp): - switch (that) { - case CovarType(Type tp1): - return tp.equals(tp1); - default: return false; - } case OverloadedType(Symbol[] alts, Type[] alttypes): switch (that) { case OverloadedType(Symbol[] alts1, Type[] alttypes1): @@ -2559,6 +2428,5 @@ public class Type implements Modifiers, Kinds, TypeTags { case MethodType(Symbol[] vparams, Type result): case PolyType(Symbol[] tparams, Type result): case OverloadedType(Symbol[] alts, Type[] alttypes): - case CovarType(Type tp): */ diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java index dba5daa3de..0d585bf836 100644 --- a/sources/scalac/symtab/classfile/AttributeParser.java +++ b/sources/scalac/symtab/classfile/AttributeParser.java @@ -232,10 +232,19 @@ public class AttributeParser implements ClassfileConstants { Vector syms = new Vector(); do { nextToken(); + int vflag = 0; + if (token.equals("+")) { + nextToken(); + vflag = Modifiers.COVARIANT; + } else if (token.equals("-")) { + nextToken(); + vflag = Modifiers.CONTRAVARIANT; + } assert token.startsWith("?"); Symbol s = getTVar(token); if (s == Symbol.NONE) return defaultType; + s.flags |= vflag; nextToken(); //System.out.println("new var " + s + ", " + token);//DEBUG if (token.equals("<")) { diff --git a/sources/scalac/transformer/AddInterfaces.java b/sources/scalac/transformer/AddInterfaces.java index e3d93217d8..71a3a3db52 100644 --- a/sources/scalac/transformer/AddInterfaces.java +++ b/sources/scalac/transformer/AddInterfaces.java @@ -268,8 +268,6 @@ class AddInterfaces extends SubstTransformer { return new Type.PolyType(tparams, apply(result)); case OverloadedType(Symbol[] alts, Type[] alttypes): return new Type.OverloadedType(alts, apply(alttypes)); - case CovarType(Type t): - return new Type.CovarType(apply(t)); case NoType: return tp; default: diff --git a/sources/scalac/transformer/Erasure.java b/sources/scalac/transformer/Erasure.java index a890c37498..413dae1609 100644 --- a/sources/scalac/transformer/Erasure.java +++ b/sources/scalac/transformer/Erasure.java @@ -485,7 +485,6 @@ public class Erasure extends Transformer implements Modifiers { case FunType(_,_): case CompoundType(_,_): case AppliedType(_, _): - case CovariantType(_): throw Debug.abort("illegal case", tree); default: diff --git a/sources/scalac/transformer/PatternMatcher.java b/sources/scalac/transformer/PatternMatcher.java index 1ab354301e..8d8a5922fa 100644 --- a/sources/scalac/transformer/PatternMatcher.java +++ b/sources/scalac/transformer/PatternMatcher.java @@ -509,7 +509,7 @@ public class PatternMatcher { if (casted.pos == Position.NOPOS) { Symbol atSym = casted.type().lookup(AT_N); //System.out.println("casted type = " + typeOf(casted)); - Type seqType = casted.type().baseType(defs.SEQ_CLASS).typeArgs()[0].dropVariance(); + Type seqType = casted.type().baseType(defs.SEQ_CLASS).typeArgs()[0]; Tree t = make.Select( pat.pos, make.Ident(pat.pos, casted.name) diff --git a/sources/scalac/transformer/matching/PatternMatcher.java b/sources/scalac/transformer/matching/PatternMatcher.java index 1ab354301e..8d8a5922fa 100644 --- a/sources/scalac/transformer/matching/PatternMatcher.java +++ b/sources/scalac/transformer/matching/PatternMatcher.java @@ -509,7 +509,7 @@ public class PatternMatcher { if (casted.pos == Position.NOPOS) { Symbol atSym = casted.type().lookup(AT_N); //System.out.println("casted type = " + typeOf(casted)); - Type seqType = casted.type().baseType(defs.SEQ_CLASS).typeArgs()[0].dropVariance(); + Type seqType = casted.type().baseType(defs.SEQ_CLASS).typeArgs()[0]; Tree t = make.Select( pat.pos, make.Ident(pat.pos, casted.name) diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index 63d1c31317..5190f2da97 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -743,9 +743,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { break; case OverloadedType(Symbol[] alts, Type[] alttypes): validateVariance(base, all, alttypes, variance); - break; - case CovarType(Type tp1): - validateVariance(base, all, tp1, CoVariance); } } @@ -1741,7 +1738,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } } else if (clazz.isSubClass(definitions.SEQ_CLASS)) { // set type to instantiated sequence class constructor - Type seqtp = dropVarArgs(pt.baseType(clazz)); + Type seqtp = pt.baseType(clazz); if (seqtp != Type.NoType) { tree.type = seqConstructorType(seqtp, pt); } else { @@ -1826,26 +1823,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } } - Type dropVarArgs(Type tp) { - switch (tp) { - case TypeRef(Type pre, Symbol sym, Type[] targs): - Type[] targs1 = targs; - for (int i = 0; i < targs.length; i++) { - Type targ = targs[i]; - Type targ1 = targ.dropVariance(); - if (targ != targ1 && targs1 == targs) { - targs1 = new Type[targs.length]; - System.arraycopy(targs, 0, targs1, 0, i); - } - targs1[i] = targ1; - } - if (targs1 == targs) return tp; - else return Type.TypeRef(pre, sym, targs1); - default: - return tp; - } - } - Type seqConstructorType(Type paramtp, Type resulttp) { Symbol constr = resulttp.symbol().constructor(); Symbol param = new TermSymbol( @@ -2019,8 +1996,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree tree1 = transformVisitor(tree, pattpe, restpe); if (!infer.isFullyDefined(restpe)) restpe = tree1.type; return transform( - desugarize.partialFunction( - tree, pattpe, restpe.dropVariance())); + desugarize.partialFunction(tree, pattpe, restpe)); } else { return error(tree.pos, "expected pattern type of cases could not be determined"); } @@ -2139,8 +2115,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (!infer.isFullyDefined(restype)) restype = body1.type; popContext(); Tree tree1 = copy.Function(tree, vparams, body1); - Tree tree2 = transform(desugarize.Function(tree1, restype)); - return desugarize.postFunction(tree2); + return transform(desugarize.Function(tree1, restype)); case TypeApply(Tree fn, Tree[] args): Tree fn1 = transform(fn, EXPRmode | FUNmode, Type.AnyType); @@ -2317,11 +2292,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } return make.TypeTerm(tree.pos).setType(owntype); - case CovariantType(Tree tpe): - Tree tpe1 = transform(tpe, TYPEmode); - return make.TypeTerm(tree.pos) - .setType(Type.covarType(tpe1.type)); - case FunType(_, _): return transform(desugarize.FunType(tree)); diff --git a/sources/scalac/typechecker/DeSugarize.java b/sources/scalac/typechecker/DeSugarize.java index 13e9ad4564..07c2e4a234 100644 --- a/sources/scalac/typechecker/DeSugarize.java +++ b/sources/scalac/typechecker/DeSugarize.java @@ -110,7 +110,7 @@ public class DeSugarize implements Kinds, Modifiers { case FunType(Tree[] argtpes, Tree restpe): Tree[] types = new Tree[argtpes.length + 1]; System.arraycopy(argtpes, 0, types, 0, argtpes.length); - types[argtpes.length] = make.CovariantType(restpe.pos, restpe); + types[argtpes.length] = restpe; return make.AppliedType(tree.pos, make.Select(tree.pos, make.Ident(tree.pos, Names.scala), @@ -151,7 +151,7 @@ public class DeSugarize implements Kinds, Modifiers { ptargs.length == vparams.length + 1) { for (int i = 0; i < vparams.length; i++) assignType(vparams[i], ptargs[i]); - return ptargs[vparams.length].dropVariance(); + return ptargs[vparams.length]; } } return Type.AnyType; @@ -171,7 +171,6 @@ public class DeSugarize implements Kinds, Modifiers { * T_i's might be missing in the original tree. */ public Tree Function(Tree tree, Type restype) { - assert !restype.isCovarType(); switch (tree) { case Function(ValDef[] vparams, Tree body): int length = vparams.length; @@ -213,30 +212,11 @@ public class DeSugarize implements Kinds, Modifiers { } } - /** e of type FunctionN[T_1,...,T_N, T] --> - * (e: FunctionN[T_1,...,T_n, +T]) - */ - Tree postFunction(Tree tree) { - Type[] targs = tree.type.typeArgs(); - if (targs.length >= 1) { - Type[] targs1 = new Type[targs.length - 1]; - System.arraycopy(targs, 0, targs1, 0, targs1.length); - Tree result = gen.Typed( - tree, - global.definitions.functionType(targs1, targs[targs1.length])); - print(tree, "postfun", result); - return result; - } else { - print(tree, "postfun", tree); - return tree; - } - } - /** Cases, Argtpe, Restpe ==> - * (new scala.PartialFunction[Argtpe, Restpe]() { + * new scala.PartialFunction[Argtpe, Restpe]() { * def apply(x: Argtpe): Restpe = x match {Cases} * def isDefinedAt(x: Argtpe): scala.Boolean = x match {Cases'} - * }: scala.PartialFunction[Argtpe, +Restpe]) + * } * WHERE * case P1 if G1 => E1, ..., Pn if Gn => En) = Cases * Cases' = case P1 if G1 => True, ..., Pn if Gn => True, _ => False @@ -278,10 +258,6 @@ public class DeSugarize implements Kinds, Modifiers { make.Template( tree.pos, new Tree[]{constr}, new Tree[]{applyDef, isDefinedAtDef})); - //Tree result = make.Typed(tree.pos, - // newTree, - // gen.mkType(tree.pos, - // global.definitions.partialFunctionType(targs[0], targs[1]))); print(tree, "partialfun", result); return result; } diff --git a/sources/scalac/typechecker/Infer.java b/sources/scalac/typechecker/Infer.java index d6bfe57384..ab8c98e544 100644 --- a/sources/scalac/typechecker/Infer.java +++ b/sources/scalac/typechecker/Infer.java @@ -220,15 +220,7 @@ public class Infer implements Modifiers, Kinds { private boolean isWithinBounds(Symbol[] tparams, Type[] targs) { // check that covariant types do not appear in F-bounds. for (int i = 0; i < targs.length; i++) { - if (targs[i].isCovarType()) { - for (int j = 0; j < tparams.length; j++) - if (tparams[j].info().contains(tparams[i])) - return false; - } - } - for (int i = 0; i < targs.length; i++) { - if (!targs[i].dropVariance().isSubType( - tparams[i].info().subst(tparams, targs))) + if (!targs[i].isSubType(tparams[i].info().subst(tparams, targs))) return false; } return true; @@ -458,16 +450,15 @@ public class Infer implements Modifiers, Kinds { return true; } - /** Does given `tparam' occur only covariantly in argument types? + /** Does given `tvar' occur only covariantly in argument types `tps' for formal + * type parameetrs `tparams'? */ - private boolean isCovariantArgs(Symbol tparam, Type[] tps) { + private boolean isCovariantArgs(Symbol tvar, Type[] tps, Symbol[] tparams) { for (int i = 0; i < tps.length; i++) { - switch (tps[i]) { - case CovarType(Type t): - if (!isCovariant(tparam, t)) return false; - break; - default: - if (tps[i].contains(tparam)) return false; + if ((tparams[i].flags & COVARIANT) != 0) { + if (!isCovariant(tvar, tps[i])) return false; + } else { + if (tps[i].contains(tvar)) return false; } } return true; @@ -483,7 +474,7 @@ public class Infer implements Modifiers, Kinds { case ThisType(Symbol sym): return true; case TypeRef(Type pre, Symbol sym, Type[] args): - return isCovariant(tparam, pre) && isCovariantArgs(tparam, args); + return isCovariant(tparam, pre) && isCovariantArgs(tparam, args, sym.typeParams()); case SingleType(Type pre, Symbol sym): return !pre.contains(tparam); case CompoundType(Type[] parts, Scope members): diff --git a/sources/scalac/util/Debug.java b/sources/scalac/util/Debug.java index 6bb2c75e52..24e087b3bc 100644 --- a/sources/scalac/util/Debug.java +++ b/sources/scalac/util/Debug.java @@ -385,12 +385,6 @@ public class DebugType extends DebugAbstractHandler { buffer.append(')'); return; - case CovarType(Type tp): - buffer.append("CovarType("); - Debug.append(buffer, tp); - buffer.append(')'); - return; - case LazyType(): buffer.append("LazyType()"); return; |