diff options
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/tools/scalai/Compiler.java | 2 | ||||
-rw-r--r-- | sources/scala/tools/scalai/Environment.java | 10 | ||||
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 8 | ||||
-rw-r--r-- | sources/scalac/symtab/Symbol.java | 16 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/PackageParser.java | 12 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/Pickle.java | 2 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 21 | ||||
-rw-r--r-- | sources/scalac/typechecker/RefCheck.java | 8 | ||||
-rw-r--r-- | sources/scalac/util/Names.java | 1 |
9 files changed, 53 insertions, 27 deletions
diff --git a/sources/scala/tools/scalai/Compiler.java b/sources/scala/tools/scalai/Compiler.java index 9590877a5f..4474d641bc 100644 --- a/sources/scala/tools/scalai/Compiler.java +++ b/sources/scala/tools/scalai/Compiler.java @@ -316,7 +316,7 @@ public class Compiler { private void getTypes(Set supertypes, List interfaces, Symbol type) { if (supertypes.contains(type)) return; else supertypes.add(type); - if (!type.isPreloaded()) { + if (!type.isExternal()) { Type[] basetypes = type.parents(); for (int i = 0; i < basetypes.length; i++) { getTypes(supertypes, interfaces, basetypes[i].symbol()); diff --git a/sources/scala/tools/scalai/Environment.java b/sources/scala/tools/scalai/Environment.java index bc16c12a08..c5640e49d7 100644 --- a/sources/scala/tools/scalai/Environment.java +++ b/sources/scala/tools/scalai/Environment.java @@ -98,7 +98,7 @@ public class Environment { assert symbol.isType() : Debug.show(symbol); Object value = templates.get(symbol); if (value != null) return (Template)value; - if (symbol.isPreloaded()) { + if (symbol.isExternal()) { Template template = Template.JavaClass(mirror.getClass(symbol)); return insertTemplate(symbol, template); } else { @@ -110,7 +110,7 @@ public class Environment { assert symbol.isTerm() : Debug.show(symbol); Object value = functions.get(symbol); if (value != null) return (Function)value; - if (symbol.isPreloaded()) { + if (symbol.isExternal()) { Function function = (symbol.name == Names.CONSTRUCTOR) ? Function.JavaConstructor(mirror.getConstructor(symbol)) : Function.JavaMethod(mirror.getMethod(symbol)); @@ -129,7 +129,7 @@ public class Environment { Class clasz = mirror.getClass(symbol.moduleClass()); Variable variable = Variable.Global(clasz); return insertVariable(symbol, variable); - } else if (symbol.isPreloaded()) { + } else if (symbol.isExternal()) { Variable variable = Variable.JavaField(mirror.getField(symbol)); return insertVariable(symbol, variable); } else { @@ -157,7 +157,7 @@ public class Environment { private void loadOwner(String what, Symbol symbol) { assert Debug.log("search ", what, ": ", symbol); assert symbol.owner().isType() : Debug.show(symbol); - assert!symbol.owner().isPreloaded() : Debug.show(symbol); + assert!symbol.owner().isExternal() : Debug.show(symbol); loadTemplate(symbol.owner()); } @@ -198,7 +198,7 @@ public class Environment { private void loadMethodOverride(Type[] bases, Symbol symbol) { if (!symbol.isMethod()) return; Override override = Override.empty().insert(symbol); - if (symbol.isPreloaded()) override.insert(mirror.getMethod(symbol)); + if (symbol.isExternal()) override.insert(mirror.getMethod(symbol)); for (int i = 0; i < bases.length; i++) { Symbol overridden = symbol.overriddenSymbol(bases[i]); if (overridden == Symbol.NONE) continue; diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index 9e269348c6..e8450ef265 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -67,6 +67,7 @@ public class Definitions { public final Symbol EQEQ; public final Symbol BANGEQ; public final Symbol EQUALS; + public final Symbol EQ; public final Symbol TOSTRING; public final Symbol HASHCODE; @@ -230,6 +231,7 @@ public class Definitions { // the scala.ANYVAL class ANYVAL_CLASS = getClass(Names.scala_AnyVal); + ANYVAL_CLASS.flags |= Modifiers.SEALED; ANYVAL_TYPE = ANYVAL_CLASS.typeConstructor(); // the scala.ALL class @@ -347,6 +349,12 @@ public class Definitions { BOOLEAN_TYPE)); ANY_CLASS.members().enter(EQUALS); + EQ = new TermSymbol( + Position.NOPOS, Names.eq, ANY_CLASS, 0); + EQ.setInfo(Type.MethodType(new Symbol[]{newParameter(EQ, JAVA_OBJECT_TYPE)}, + BOOLEAN_TYPE)); + ANY_CLASS.members().enter(EQ); + TOSTRING = new TermSymbol( Position.NOPOS, Names.toString, ANY_CLASS, 0); TOSTRING.setInfo(Type.MethodType(Symbol.EMPTY_ARRAY, STRING_TYPE)); diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index 18b14c087d..751aa93863 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -399,18 +399,18 @@ public abstract class Symbol implements Modifiers, Kinds { return isConstructor() && this == primaryConstructorClass().primaryConstructor(); } - public boolean isGenerated() { + public final boolean isGenerated() { return name.pos((byte)'$') < name.length(); } /** Symbol was preloaded from package */ - public boolean isPreloaded() { + public final boolean isExternal() { return pos == Position.NOPOS; } /** Is this symbol an overloaded symbol? */ - public boolean isOverloaded() { + public final boolean isOverloaded() { switch (info()) { case OverloadedType(_,_): return true; default : return false; @@ -418,7 +418,7 @@ public abstract class Symbol implements Modifiers, Kinds { } /** Does this symbol denote a label? */ - public boolean isLabel() { + public final boolean isLabel() { return (flags & LABEL) != 0; } @@ -1020,7 +1020,7 @@ public class TermSymbol extends Symbol { public static TermSymbol define( int pos, Name name, Symbol owner, int flags, Scope scope) { Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == VAL) { + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == VAL) { TermSymbol sym = (TermSymbol) e.sym; sym.update(pos, flags); return sym; @@ -1145,7 +1145,7 @@ public class TypeSymbol extends Symbol { public static TypeSymbol define( int pos, Name name, Symbol owner, int flags, Scope scope) { Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == ALIAS) { + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == ALIAS) { TypeSymbol sym = (TypeSymbol) e.sym; sym.update(pos, flags); return sym; @@ -1316,7 +1316,7 @@ public class AbsTypeSymbol extends TypeSymbol { public static AbsTypeSymbol define( int pos, Name name, Symbol owner, int flags, Scope scope) { Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == TYPE) { + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == TYPE) { AbsTypeSymbol sym = (AbsTypeSymbol) e.sym; sym.update(pos, flags); return sym; @@ -1401,7 +1401,7 @@ public class ClassSymbol extends TypeSymbol { public static ClassSymbol define( int pos, Name name, Symbol owner, int flags, Scope scope) { Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == CLASS) { + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == CLASS) { ClassSymbol sym = (ClassSymbol) e.sym; sym.update(pos, flags); sym.template = null; diff --git a/sources/scalac/symtab/classfile/PackageParser.java b/sources/scalac/symtab/classfile/PackageParser.java index 1b29c7a0ef..9d62fb1009 100644 --- a/sources/scalac/symtab/classfile/PackageParser.java +++ b/sources/scalac/symtab/classfile/PackageParser.java @@ -66,11 +66,13 @@ public class PackageParser extends Type.LazyType { if (previous == Symbol.NONE || previous.isPackage()) return true; if (previous.pos != Position.NOPOS) return false; AbstractFile pf = (AbstractFile) symFile.get(previous); - if (!global.separate) { - if (f.getName().endsWith(".scala") && - pf.getName().endsWith(".class")) return true; - if (f.getName().endsWith(".class") && - pf.getName().endsWith(".scala")) return false; + if (f.getName().endsWith(".scala")) { + if (pf.getName().endsWith(".scala")) return false; + if (!global.separate) return true; + } + if (f.getName().endsWith(".class")) { + if (pf.getName().endsWith(".class")) return false; + if (!global.separate) return false; } return f.lastModified() > pf.lastModified(); } diff --git a/sources/scalac/symtab/classfile/Pickle.java b/sources/scalac/symtab/classfile/Pickle.java index bae101668d..ec75241842 100644 --- a/sources/scalac/symtab/classfile/Pickle.java +++ b/sources/scalac/symtab/classfile/Pickle.java @@ -46,7 +46,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags { /** Pickle all symbols descending from `root'. */ public void add(Symbol root) { - if (root.pos != Position.NOPOS) { + if (!root.isExternal()) { if (Global.instance.debug) System.out.println("pickling " + root); if (index.get(root) == null) { this.rootname = root.name.toTermName(); diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index 3c3812c573..519cb58c7e 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -13,7 +13,9 @@ // todo: emit warnings for unchecked. // todo: synchronize on module instantiation. // todo: type select operator for superclass term access. - +// todo: implement EQ +// todo: for (Tuplen(...) <- ...) +// todo: empty package package scalac.typechecker; @@ -211,7 +213,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { else return "value " + NameTransformer.decode(name); } - /** Check that `sym' accessible as a member of tree `site' in current context. + /** Check that `sym' is accessible as a member of tree `site' in current context. */ void checkAccessible(int pos, Symbol sym, Tree site) { if (!isAccessible(sym, site)) { @@ -815,7 +817,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (sym == other) { if (global.debug) global.log("redefined: " + sym + ":" + sym.rawInfo()); } else if (e.owner == context.scope) { - if (other.isPreloaded()) { + if (other.isExternal()) { assert false : sym + " " + other; // symbol was preloaded from package; // need to overwrite definition. @@ -1378,7 +1380,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { pre = Type.localThisType; } } - } else if (sym.kind != NONE && !sym.isPreloaded()) { + } else if (sym.kind != NONE && !sym.isExternal()) { return error(tree.pos, "reference to " + name + " is ambiguous;\n" + "it is both defined in " + sym.owner() + @@ -1547,7 +1549,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Symbol c = f.primaryConstructorClass(); if (c.kind == CLASS) { c.initialize();//to detect cycles - if (i > 0 && (c.flags & JAVA) == 0 && c.pos == Position.NOPOS) { + if (i > 0 && (c.flags & JAVA) == 0 && c.isExternal()) { // need to load tree for mixins new SourceCompleter(global).complete(c); } @@ -1943,7 +1945,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree applyVisitor = transformVisitor(tree, pattype, restype); if (!infer.isFullyDefined(restype)) restype = applyVisitor.type; - if (definitions.PARTIALFUNCTION_CLASS.pos == Position.NOPOS) + if (definitions.PARTIALFUNCTION_CLASS.isExternal()) // need to load tree for mixins new SourceCompleter(global).complete( definitions.PARTIALFUNCTION_CLASS); @@ -2249,7 +2251,12 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { case Ident(Name name): if (name == Names.this_.toTypeName()) { - return transform(make.Ident(tree.pos, pt.symbol().name)); + Tree tree1 = transform(make.Ident(tree.pos, pt.symbol().name)); + Symbol constr = tree1.symbol(); + if (constr != null && constr.kind == VAL && constr.pos > tree.pos) + error(tree.pos, + "illegal forward reference to self constructor"); + return tree1; } else if (((mode & (PATTERNmode | FUNmode)) == PATTERNmode) && name.isVariable()) { diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java index 3b5b9f7d78..00279759ec 100644 --- a/sources/scalac/typechecker/RefCheck.java +++ b/sources/scalac/typechecker/RefCheck.java @@ -136,6 +136,14 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { overrideError(pos, member, other, "needs `override' modifier"); } else if (other.isStable() && !member.isStable()) { overrideError(pos, member, other, "needs to be an immutable value"); + } else if ((member.flags & DEFERRED) == 0 && (other.flags & DEFERRED) == 0 && + member.owner() != clazz && + !clazz.parents()[0].symbol().isSubClass(other.owner())) { + unit.error(pos, "conflict between concrete members " + + member + member.locationString() + " and " + + other + other.locationString() + + ":\n both are inherited from mixin classes; " + + "\n an overriding definition in the current template is required"); } else { Type self = clazz.thisType(); switch (other.kind) { diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java index c059218230..8c7ecdb5c4 100644 --- a/sources/scalac/util/Names.java +++ b/sources/scalac/util/Names.java @@ -131,6 +131,7 @@ public class Names { public static final Name scala_Unit = Name.fromString("scala.Unit"); public static final Name scala_runtime = Name.fromString("scala.runtime"); public static final Name scala_runtime_RunTime = Name.fromString("scala.runtime.RunTime"); + public static final Name eq = Name.fromString("eq"); public static final Name equals = Name.fromString("equals"); public static final Name toString = Name.fromString("toString"); public static final Name that = Name.fromString("that"); |