summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-06-17 09:25:36 +0000
committerMartin Odersky <odersky@gmail.com>2003-06-17 09:25:36 +0000
commitc4335d55bc2a71c1689b9f377c9f83b568b19db8 (patch)
tree14a6fd22d0106b292ab4d47e666ca440ec282bfd /sources
parenta495f88f49f6dcb17b0cbb82209784f324a0bd90 (diff)
downloadscala-c4335d55bc2a71c1689b9f377c9f83b568b19db8.tar.gz
scala-c4335d55bc2a71c1689b9f377c9f83b568b19db8.tar.bz2
scala-c4335d55bc2a71c1689b9f377c9f83b568b19db8.zip
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/ast/parser/Parser.java3
-rw-r--r--sources/scalac/symtab/Type.java2
-rw-r--r--sources/scalac/typechecker/Analyzer.java51
-rw-r--r--sources/scalac/typechecker/RefCheck.java58
-rw-r--r--sources/scalac/util/Names.java3
5 files changed, 63 insertions, 54 deletions
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java
index e483f09c04..ceb25b4140 100644
--- a/sources/scalac/ast/parser/Parser.java
+++ b/sources/scalac/ast/parser/Parser.java
@@ -1386,6 +1386,9 @@ public class Parser implements Tokens {
t = make.Select(pos, t, name);
pos = accept(DOT);
} else {
+ if (name == Names.ASTERISK)
+ s.unit.warning(
+ pos, "this imports only the identifier `*';\nuse `import xyz._' to import all members of `xyz'.");
return make.Import(startpos, t, new Name[]{name, name});
}
}
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index 3855e86634..7303605764 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -911,7 +911,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
if (pre == NoType || clazz.kind != CLASS)
return this;
Symbol ownclass = sym.owner().primaryConstructorClass();
- if (ownclass.isSubClass(clazz) &&
+ if (ownclass == clazz &&
pre.widen().symbol().isSubClass(ownclass)) {
switch (pre.baseType(ownclass)) {
case TypeRef(_, Symbol basesym, Type[] baseargs):
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 057180d8d6..0d0af93425 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -364,54 +364,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
}
}
- /** 1. Check that only traits are inherited several times (except if the
- * inheriting instance is a compund type).
- * 2. Check that later type instances in the base-type sequence
- * of a class are subtypes of earlier type instances of the same trait.
- * 3. Check that case classes do not inherit from case classes.
- */
- void validateBaseTypes(Symbol clazz) {
- validateBaseTypes(clazz, clazz.type().parents(),
- new Type[clazz.closure().length], 0);
- }
- //where
- void validateBaseTypes(Symbol clazz, Type[] tps, Type[] seen, int start) {
- for (int i = tps.length - 1; i >= start; i--) {
- validateBaseTypes(clazz, tps[i].unalias(), seen, i == 0 ? 0 : 1);
- }
- }
-
- void validateBaseTypes(Symbol clazz, Type tp, Type[] seen, int start) {
- Symbol baseclazz = tp.symbol();
- if (baseclazz.kind == CLASS) {
- int index = clazz.closurePos(baseclazz);
- if (index < 0) return;
- if (seen[index] != null) {
- // check that only uniform classes are inherited several times.
- if (!clazz.isCompoundSym() && !baseclazz.isTrait()) {
- error(clazz.pos, "illegal inheritance;\n" + clazz +
- " inherits " + baseclazz + " twice");
- }
- // if there are two different type instances of same class
- // check that second is a subtype of first.
- if (!seen[index].isSubType(tp)) {
- String msg = (clazz.isCompoundSym())
- ? "illegal combination;\n compound type combines"
- : "illegal inheritance;\n " + clazz + " inherits";
- error(clazz.pos, msg + " different type instances of " +
- baseclazz + ":\n" + tp + " and " + seen[index]);
- }
- }
- // check that case classes do not inherit from case classes
- if (clazz.isCaseClass() && baseclazz.isCaseClass())
- error(clazz.pos, "illegal inheritance;\n " + "case " + clazz +
- " inherits from other case " + baseclazz);
-
- seen[index] = tp;
- validateBaseTypes(clazz, tp.parents(), seen, start);
- }
- }
-
/** Check that type is eta-expandable (i.e. no `def' or `*' parameters)
*/
void checkEtaExpandable(int pos, Type tp) {
@@ -1241,6 +1193,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
* @param name The name of the identifier.
*/
Tree transformIdent(Tree tree, Name name) {
+ //System.out.println("transforming " + name);//DEBUG
// find applicable definition and assign to `sym'
Symbol sym = Symbol.NONE;
Type pre;
@@ -1482,7 +1435,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
transformConstrInvocationArgs(parents);
if (owner.kind != ERROR) {
validateParentClasses(parents, owner.info().parents(), owner.typeOfThis());
- validateBaseTypes(owner);
}
pushContext(templ, owner, owner.members());
templ.setSymbol(gen.localDummy(templ.pos, owner));
@@ -2140,7 +2092,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
Scope members = new Scope();
Type self = Type.compoundType(ptypes, members);
Symbol clazz = self.symbol();
- validateBaseTypes(clazz);
pushContext(tree, clazz, members);
for (int i = 0; i < refinements.length; i++) {
enterSym(refinements[i]).flags |= OVERRIDE;
diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java
index dc6cfe73f2..e9d2a2f205 100644
--- a/sources/scalac/typechecker/RefCheck.java
+++ b/sources/scalac/typechecker/RefCheck.java
@@ -209,6 +209,56 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
: name;
}
+// Basetype Checking --------------------------------------------------------
+
+ /** 1. Check that only traits are inherited several times (except if the
+ * inheriting instance is a compund type).
+ * 2. Check that later type instances in the base-type sequence
+ * of a class are subtypes of earlier type instances of the same trait.
+ * 3. Check that case classes do not inherit from case classes.
+ */
+ void validateBaseTypes(Symbol clazz) {
+ validateBaseTypes(clazz, clazz.type().parents(),
+ new Type[clazz.closure().length], 0);
+ }
+ //where
+ void validateBaseTypes(Symbol clazz, Type[] tps, Type[] seen, int start) {
+ for (int i = tps.length - 1; i >= start; i--) {
+ validateBaseTypes(clazz, tps[i].unalias(), seen, i == 0 ? 0 : 1);
+ }
+ }
+
+ void validateBaseTypes(Symbol clazz, Type tp, Type[] seen, int start) {
+ Symbol baseclazz = tp.symbol();
+ if (baseclazz.kind == CLASS) {
+ int index = clazz.closurePos(baseclazz);
+ if (index < 0) return;
+ if (seen[index] != null) {
+ // check that only uniform classes are inherited several times.
+ if (!clazz.isCompoundSym() && !baseclazz.isTrait()) {
+ unit.error(clazz.pos, "illegal inheritance;\n" + clazz +
+ " inherits " + baseclazz + " twice");
+ }
+ // if there are two different type instances of same class
+ // check that second is a subtype of first.
+ if (!seen[index].isSubType(tp)) {
+ String msg = (clazz.isCompoundSym())
+ ? "illegal combination;\n compound type combines"
+ : "illegal inheritance;\n " + clazz + " inherits";
+ unit.error(clazz.pos, msg + " different type instances of " +
+ baseclazz + ":\n" + tp + " and " + seen[index]);
+ }
+ }
+ // check that case classes do not inherit from case classes
+ if (clazz.isCaseClass() && baseclazz.isCaseClass())
+ unit.error(clazz.pos, "illegal inheritance;\n " + "case " + clazz +
+ " inherits from other case " + baseclazz);
+
+ seen[index] = tp;
+ validateBaseTypes(clazz, tp.parents(), seen, start);
+ }
+ }
+
// Variance Checking --------------------------------------------------------
private final int
@@ -784,7 +834,9 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
Tree[] bases1 = transform(bases);
Tree[] body1 = transformStats(body);
if (sym.kind == VAL) {
- checkAllOverrides(tree.pos, tree.symbol().owner());
+ Symbol owner = tree.symbol().owner();
+ validateBaseTypes(owner);
+ checkAllOverrides(tree.pos, owner);
}
return copy.Template(tree, bases1, body1);
@@ -826,7 +878,9 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
return elimTypeNode(super.transform(tree));
case CompoundType(_, _):
- checkAllOverrides(tree.pos, tree.type.symbol());
+ Symbol clazz = tree.type.symbol();
+ validateBaseTypes(clazz);
+ checkAllOverrides(tree.pos, clazz);
return elimTypeNode(super.transform(tree));
case Ident(Name name):
diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java
index f2cfab763d..526dfe7943 100644
--- a/sources/scalac/util/Names.java
+++ b/sources/scalac/util/Names.java
@@ -21,9 +21,10 @@ public class Names {
public static final Name _EQ = encode("_=");
public static final Name MINUS = encode("-");
public static final Name PLUS = encode("+");
- public static final Name BANG = encode("!");
+ public static final Name ASTERISK = encode("*");
public static final Name TILDE = encode("~");
public static final Name EQEQ = encode("==");
+ public static final Name BANG = encode("!");
public static final Name BANGEQ = encode("!=");
public static final Name BARBAR = encode("||");
public static final Name AMPAMP = encode("&&");