diff options
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/ast/TreeGen.java | 45 | ||||
-rw-r--r-- | sources/scalac/symtab/Modifiers.java | 5 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/ClassfileParser.java | 5 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 12 | ||||
-rw-r--r-- | sources/scalac/typechecker/Infer.java | 12 |
5 files changed, 53 insertions, 26 deletions
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, |