summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-05-27 12:50:48 +0000
committerMartin Odersky <odersky@gmail.com>2003-05-27 12:50:48 +0000
commit5745978304c16a3bc1e077260fc636f6ed5d8cec (patch)
treefb9abab162c93efec7fc4ce6e84fb5a2ca367f12
parent9bad87da03ffeda487fb1a0e1369113d8c107b95 (diff)
downloadscala-5745978304c16a3bc1e077260fc636f6ed5d8cec.tar.gz
scala-5745978304c16a3bc1e077260fc636f6ed5d8cec.tar.bz2
scala-5745978304c16a3bc1e077260fc636f6ed5d8cec.zip
*** empty log message ***
-rw-r--r--sources/examples/expressions/expressions-current.scala2
-rw-r--r--sources/scala/Symbol.scala4
-rw-r--r--sources/scalac/ast/TreeGen.java45
-rw-r--r--sources/scalac/symtab/Modifiers.java5
-rw-r--r--sources/scalac/symtab/classfile/ClassfileParser.java5
-rw-r--r--sources/scalac/typechecker/Analyzer.java12
-rw-r--r--sources/scalac/typechecker/Infer.java12
-rw-r--r--test/files/run/imports.check12
-rw-r--r--test/files/run/imports.scala95
9 files changed, 58 insertions, 134 deletions
diff --git a/sources/examples/expressions/expressions-current.scala b/sources/examples/expressions/expressions-current.scala
index abfb3a6ad4..748fbca2da 100644
--- a/sources/examples/expressions/expressions-current.scala
+++ b/sources/examples/expressions/expressions-current.scala
@@ -59,5 +59,7 @@ object Main {
val sref = new Ref("");
System.out.println("eval: " + { e2.visit(new l2.Eval2(iref)); iref.elem });
System.out.println("show: " + { e2.visit(new l2.Show2(sref)); sref.elem });
+ e2.visit(new l1.Eval(iref));
+ e1.visit(new l2.Show2(sref));
}
}
diff --git a/sources/scala/Symbol.scala b/sources/scala/Symbol.scala
index e180b93125..a02abaffa3 100644
--- a/sources/scala/Symbol.scala
+++ b/sources/scala/Symbol.scala
@@ -1,4 +1,6 @@
package scala;
-case class Symbol(name: String) {}
+case class Symbol(name: String) {
+ override def toString() = "'" + name;
+}
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java
index 12c6926769..7fef0be2b8 100644
--- a/sources/scalac/ast/TreeGen.java
+++ b/sources/scalac/ast/TreeGen.java
@@ -12,6 +12,7 @@ import java.io.*;
import java.util.*;
import scalac.*;
import scalac.symtab.*;
+import scalac.typechecker.Infer;
import scalac.util.*;
import Tree.*;
@@ -38,6 +39,10 @@ public class TreeGen implements Kinds, Modifiers {
*/
public TreeFactory make;
+ /** the type inferencer
+ */
+ Infer infer;
+
/************************************************************************/
/************************************************************************/
/** CONSTRUCTORS **/
@@ -46,6 +51,7 @@ public class TreeGen implements Kinds, Modifiers {
this.global = global;
this.definitions = global.definitions;
this.make = make;
+ this.infer = new Infer(global, this, make);
}
public TreeGen(Global global) {
@@ -353,12 +359,19 @@ public class TreeGen implements Kinds, Modifiers {
* and argument trees.
*/
public Tree Apply(int pos, Tree fn, Tree[] args) {
- switch (fn.type) {
- case Type.MethodType(Symbol[] vparams, Type restpe):
- return make.Apply(pos, fn, args).setType(restpe);
- default:
- throw new ApplicationError("method type required", fn.type);
- }
+ try {
+ switch (fn.type) {
+ case Type.OverloadedType(Symbol[] alts, Type[] alttypes):
+ infer.methodAlternative(fn, alts, alttypes,
+ Tree.typeOf(args), Type.AnyType);
+ }
+ switch (fn.type) {
+ case Type.MethodType(Symbol[] vparams, Type restpe):
+ return make.Apply(pos, fn, args).setType(restpe);
+ }
+ } catch (Type.Error ex) {
+ }
+ throw new ApplicationError("method type required", fn.type);
}
public Tree Apply(Tree fn, Tree[] args) {
@@ -369,13 +382,19 @@ public class TreeGen implements Kinds, Modifiers {
* and argument trees.
*/
public Tree TypeApply(int pos, Tree fn, Tree[] args) {
- switch (fn.type) {
- case Type.PolyType(Symbol[] tparams, Type restpe):
- return make.TypeApply(pos, fn, args)
- .setType(restpe.subst(tparams, Tree.typeOf(args)));
- default:
- throw new ApplicationError("poly type required", fn.type);
- }
+ try {
+ switch (fn.type) {
+ case Type.OverloadedType(Symbol[] alts, Type[] alttypes):
+ infer.polyAlternative(fn, alts, alttypes, args.length);
+ }
+ switch (fn.type) {
+ case Type.PolyType(Symbol[] tparams, Type restpe):
+ return make.TypeApply(pos, fn, args)
+ .setType(restpe.subst(tparams, Tree.typeOf(args)));
+ }
+ } catch (Type.Error ex) {
+ }
+ throw new ApplicationError("poly type required", fn.type);
}
public Tree TypeApply(Tree fn, Tree[] args) {
diff --git a/sources/scalac/symtab/Modifiers.java b/sources/scalac/symtab/Modifiers.java
index a368b0b6ba..6722096d43 100644
--- a/sources/scalac/symtab/Modifiers.java
+++ b/sources/scalac/symtab/Modifiers.java
@@ -47,8 +47,7 @@ public interface Modifiers {
int ACCESSOR = 0x04000000; // function is an access function for a
// value or variable
- int BRIDGE = 0x0800000; // function is a bridge method.
- int SNDTIME = BRIDGE; // debug
+ int BRIDGE = 0x08000000; // function is a bridge method.
int INTERFACE = 0x10000000; // symbol is a Java interface
int TRAIT = 0x20000000; // symbol is a Trait
@@ -58,7 +57,7 @@ public interface Modifiers {
// masks
int SOURCEFLAGS = 0x00000077 | DEF | REPEATED | MODUL | MUTABLE | PACKAGE | PARAM | TRAIT | COVARIANT | CONTRAVARIANT; // these modifiers can be set in source programs.
- int ACCESSFLAGS = PRIVATE | PROTECTED;
+ int ACCESSFLAGS = PRIVATE | PROTECTED;
public static class Helper {
diff --git a/sources/scalac/symtab/classfile/ClassfileParser.java b/sources/scalac/symtab/classfile/ClassfileParser.java
index 170c340fbe..15a0eca111 100644
--- a/sources/scalac/symtab/classfile/ClassfileParser.java
+++ b/sources/scalac/symtab/classfile/ClassfileParser.java
@@ -203,10 +203,9 @@ public class ClassfileParser implements ClassfileConstants {
Type type = readType(in.nextChar());
if (CONSTR_N.equals(name)) {
Symbol s = TermSymbol.newConstructor(c, transFlags(flags));
- // kick out protected, package visible or
+ // kick out package visible or
// private constructors
- if (((flags & 0x0004) != 0) ||
- ((flags & 0x0002) != 0) ||
+ if (((flags & 0x0002) != 0) ||
((flags & 0x0007) == 0)) {
attrib.readAttributes(s, type, METH_ATTR);
return;
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index cd000ec715..61276309b6 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -317,7 +317,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
if (!checkClassType(constrs[i].pos, parents[i])) return;
Symbol bsym = parents[i].symbol();
if (i == 0) {
- if ((bsym.flags & INTERFACE) != 0)
+ if ((bsym.flags & (JAVA | INTERFACE)) == (JAVA | INTERFACE))
error(constrs[0].pos, "superclass may not be a Java interface");
} else {
if ((bsym.flags & (JAVA | INTERFACE)) == JAVA)
@@ -1599,10 +1599,16 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
Type[] argtypes = new Type[args.length];
switch (methtype) {
case MethodType(Symbol[] params, Type restp):
+ if (meth.isConstructor() &&
+ params.length == 1 && params[0] == Symbol.NONE) {
+ error(pos, meth + " is inaccessible");
+ return null;
+ }
Type[] formals = infer.formalTypes(params, args.length);
if (formals.length != args.length) {
- error(pos, "wrong number of arguments" +
- (meth == null ? "" : " for " + meth));
+ error(pos, "wrong number of arguments for " +
+ (meth == null ? "<function>" : meth) +
+ ArrayApply.toString(formals, "(", ",", ")"));
return null;
}
if (tparams.length == 0) {
diff --git a/sources/scalac/typechecker/Infer.java b/sources/scalac/typechecker/Infer.java
index 5170292d10..c060ca8067 100644
--- a/sources/scalac/typechecker/Infer.java
+++ b/sources/scalac/typechecker/Infer.java
@@ -23,14 +23,18 @@ public class Infer implements Modifiers, Kinds {
TreeFactory make;
Substituter substituter;
- public Infer(Transformer trans) {
- this.global = trans.global;
+ public Infer(Global global, TreeGen gen, TreeFactory make) {
+ this.global = global;
this.definitions = global.definitions;
- this.gen = trans.gen;
- this.make = trans.make;
+ this.gen = gen;
+ this.make = make;
this.substituter = new Substituter(global, gen);
}
+ public Infer(Transformer trans) {
+ this(trans.global, trans.gen, trans.make);
+ }
+
// Error messages -------------------------------------------------------------
String applyErrorMsg(String msg1, Tree fn,
diff --git a/test/files/run/imports.check b/test/files/run/imports.check
deleted file mode 100644
index 56f5e23d45..0000000000
--- a/test/files/run/imports.check
+++ /dev/null
@@ -1,12 +0,0 @@
-In C_ico, v_ico .toString() returns C_ico -> ok
-In C_ico, field .toString() returns C_ico -> ok
-In C_ico, method.toString() returns C_ico -> ok
-
-In C_ioc, v_ioc .toString() returns C_ioc -> ok
-In C_ioc, field .toString() returns C_ioc -> ok
-In C_ioc, method.toString() returns C_ioc -> ok
-
-In C_oic, v_oic .toString() returns C_oic -> ok
-In C_oic, field .toString() returns C_oic -> ok
-In C_oic, method.toString() returns C_oic -> ok
-
diff --git a/test/files/run/imports.scala b/test/files/run/imports.scala
deleted file mode 100644
index 0eb342b984..0000000000
--- a/test/files/run/imports.scala
+++ /dev/null
@@ -1,95 +0,0 @@
-//############################################################################
-// Import statements
-//############################################################################
-// $Id$
-
-//############################################################################
-
-object checker {
- def check(where: String, what: String, value: Any): Unit = {
- System.out.print("In " + where + ", " + what + ".toString() returns ");
- System.out.flush();
- val string: String = if (value == null) "null" else value.toString();
- val test = if (string == where) "ok" else "KO";
- System.out.println(string + " -> " + test);
- System.out.flush();
- }
-}
-
-import checker.check;
-
-//############################################################################
-
-import o_ico.v_ico;
-
-class C_ico() {
- o_ico.v_ico = this;
- override def toString(): String = "C_ico";
- def method: C_ico = v_ico;
- val field: C_ico = v_ico;
-
- check("C_ico", "v_ico ", v_ico);
- check("C_ico", "field ", field);
- check("C_ico", "method", method);
- System.out.println();
-}
-
-object o_ico {
- var v_ico: C_ico = null;
- new C_ico();
-}
-
-//############################################################################
-
-import o_ioc.v_ioc;
-
-object o_ioc {
- var v_ioc: C_ioc = null;
- new C_ioc();
-}
-
-class C_ioc() {
- o_ioc.v_ioc = this;
- override def toString(): String = "C_ioc";
- def method: C_ioc = v_ioc;
- val field: C_ioc = v_ioc;
-
- check("C_ioc", "v_ioc ", v_ioc);
- check("C_ioc", "field ", field);
- check("C_ioc", "method", method);
- System.out.println();
-}
-
-//############################################################################
-
-object o_oic {
- var v_oic: C_oic = null;
- new C_oic();
-}
-
-import o_oic.v_oic;
-
-class C_oic() {
- o_oic.v_oic = this;
- override def toString(): String = "C_oic";
- def method: C_oic = v_oic;
- val field: C_oic = v_oic;
-
- check("C_oic", "v_oic ", v_oic);
- check("C_oic", "field ", field);
- check("C_oic", "method", method);
- System.out.println();
-}
-
-//############################################################################
-
-object Test {
- def main(args: Array[String]): Unit = {
- o_ico;
- o_ioc;
- o_oic;
- ()
- }
-}
-
-//############################################################################