diff options
author | Martin Odersky <odersky@gmail.com> | 2004-01-15 16:17:59 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2004-01-15 16:17:59 +0000 |
commit | 399482a6ba2e61f379703c05aeb47c6c39f0fdfa (patch) | |
tree | 54afc8ff65d5c1a56539ad3af5955034a1f9e6a9 /sources | |
parent | 08ab698c371a7cf5e0621c3c2d9c882721d79aa8 (diff) | |
download | scala-399482a6ba2e61f379703c05aeb47c6c39f0fdfa.tar.gz scala-399482a6ba2e61f379703c05aeb47c6c39f0fdfa.tar.bz2 scala-399482a6ba2e61f379703c05aeb47c6c39f0fdfa.zip |
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/tools/scalac/ast/parser/Parser.scala | 2 | ||||
-rw-r--r-- | sources/scala/tools/scalac/typechecker/Analyzer.scala | 15 | ||||
-rw-r--r-- | sources/scalac/symtab/Type.java | 62 |
3 files changed, 68 insertions, 11 deletions
diff --git a/sources/scala/tools/scalac/ast/parser/Parser.scala b/sources/scala/tools/scalac/ast/parser/Parser.scala index 830c507e44..6cd6effa88 100644 --- a/sources/scala/tools/scalac/ast/parser/Parser.scala +++ b/sources/scala/tools/scalac/ast/parser/Parser.scala @@ -690,7 +690,7 @@ class Parser(unit: Unit) { s.nextToken(); ts.append(simpleType()); } - val rs = /*if (s.token == LBRACE) refinement() else*/ Tree.EMPTY_ARRAY; + val rs = if (s.token == LBRACE) refinement() else Tree.EMPTY_ARRAY; make.CompoundType(pos, ts.toArray(), rs) } else { t diff --git a/sources/scala/tools/scalac/typechecker/Analyzer.scala b/sources/scala/tools/scalac/typechecker/Analyzer.scala index 5fd7997e9d..76355d1a6e 100644 --- a/sources/scala/tools/scalac/typechecker/Analyzer.scala +++ b/sources/scala/tools/scalac/typechecker/Analyzer.scala @@ -2283,7 +2283,6 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( val parentTypes = clazz.info().parents(); val refinement: Scope = new Scope(); val base: Type = Type.compoundTypeWithOwner(context.enclClass.owner, parentTypes, Scope.EMPTY); - /* val it: Scope$SymbolIterator = clazz.members().iterator(); while (it.hasNext()) { val sym1: Symbol = it.next(); @@ -2293,7 +2292,6 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( .isSameAs(sym1.getType())) refinement.enter(sym1); } - */ val owntype = if (refinement.isEmpty() && parentTypes.length == 1) parentTypes(0) @@ -2764,16 +2762,23 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer( case Tree$CompoundType(parents, refinements) => val parents1 = transform(parents, TYPEmode); - val ptypes = Tree.typeOf(parents); + val ptypes = new Array[Type](parents1.length); + { var i = 0; while (i < parents1.length) { + val tp = parents(i).getType(); + if (i > 0 || tp.unalias().symbol().kind != TYPE) + checkClassType(parents(i).pos, tp); + ptypes(i) = tp; + i = i + 1 + }} val members: Scope = new Scope(); val self: Type = Type.compoundTypeWithOwner(context.enclClass.owner, ptypes, members); val clazz: Symbol = self.symbol(); pushContext(tree, clazz, members); - var i = 0; while (i < refinements.length) { + { var i = 0; while (i < refinements.length) { val m = enterSym(refinements(i)); m.flags = m.flags | OVERRIDE; i = i + 1 - } + }} val refinements1 = transformStatSeq(refinements, Symbol.NONE); popContext(); copy.CompoundType(tree, parents1, refinements1) diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index b8b03a9ffb..e9665e13d8 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -1658,6 +1658,11 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { case ThisType(Symbol sym): if (sym == from) return to; else return t; + case TypeRef(Type pre, Symbol sym, Type[] args): + Type pre1 = apply(pre); + Type[] args1 = map(args); + if (pre1 == pre && args1 == args) return t; + else return typeRef(pre1, pre1.rebind(sym), args1); default: return map(t); } @@ -2579,9 +2584,36 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { } } + static int recCount = 0; + static boolean giveUp = false; + static int recLimit = 10; + + public static Type lub(Type[] tps) { + if (recCount == recLimit) { + giveUp = true; + return Global.instance.definitions.ANY_TYPE(); + } else { + recCount++; + Type result = lub0(tps); + recCount--; + if (recCount == 0) { + if (giveUp) { + giveUp = false; + throw new Error("failure to compute least upper bound of types " + + ArrayApply.toString(tps, "", " and ", ";\n") + + "an approximation is: " + result + ";\n" + + "additional type annotations are needed"); + } else { + giveUp = false; + } + } + return result; + } + } + /** Return the least upper bound of non-empty array of types `tps'. */ - public static Type lub(Type[] tps) { + public static Type lub0(Type[] tps) { //System.out.println("lub" + ArrayApply.toString(tps));//DEBUG if (tps.length == 0) return Global.instance.definitions.ALL_TYPE(); @@ -2754,6 +2786,29 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { } public static Type glb(Type[] tps) { + if (recCount == recLimit) { + giveUp = true; + return Global.instance.definitions.ALL_TYPE(); + } else { + recCount++; + Type result = glb0(tps); + recCount--; + if (recCount == 0) { + if (giveUp) { + giveUp = false; + throw new Error("failure to compute greatest lower bound of types " + + ArrayApply.toString(tps, "", " and ", ";\n") + + "an approximation is: " + result + ";\n" + + "additional type annotations are needed"); + } else { + giveUp = false; + } + } + return result; + } + } + + public static Type glb0(Type[] tps) { if (tps.length == 0) return Global.instance.definitions.ANY_TYPE(); // step one: eliminate redunandant types; return if one one is left @@ -2769,10 +2824,8 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { treftl = new Type.List(tps[i], treftl); break; case CompoundType(Type[] parents, Scope members): - /* if (!members.isEmpty()) comptl = new Type.List(tps[i], comptl); - */ for (int j = 0; j < parents.length; j++) treftl = new Type.List(parents[j], treftl); break; @@ -2787,7 +2840,7 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { Type glbThisType = glbType.narrow(); // step 3: compute glb of all refinements. - /* + Scope members = Scope.EMPTY; if (comptl != List.EMPTY) { Type[] comptypes = comptl.toArrayReverse(); Scope[] refinements = new Scope[comptypes.length]; @@ -2801,7 +2854,6 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { Global.instance.definitions.ALLREF_TYPE(), treftl); } } - */ // eliminate redudant typerefs Type[] treftypes = elimRedundant(treftl.toArrayReverse(), false); |