diff options
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/ast/parser/Parser.java | 17 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 47 | ||||
-rw-r--r-- | sources/scalac/typechecker/Infer.java | 9 |
3 files changed, 45 insertions, 28 deletions
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index 73ca7fc747..eea0637f47 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -1209,24 +1209,19 @@ public class Parser implements Tokens { * | Pattern2 */ Tree pattern1() { - int base = sp; - Tree top = simplePattern(); - if (s.token == COLON) { - if (TreeInfo.isVarPattern(top)) { - return make.Typed(s.skipToken(), top, type1()); - } + Tree p = pattern2(); + if (s.token == COLON && TreeInfo.isVarPattern(p)) { + return make.Typed(s.skipToken(), p, type1()); } - return pattern1rest(base, top); + return p; } /* Pattern2 ::= SimplePattern [ '*' | '?' | '+' ] * | SimplePattern {Id SimplePattern} // op2 must not be empty */ Tree pattern2() { - return pattern1rest(sp, simplePattern()); - } - - Tree pattern1rest(int base, Tree top) { + int base = sp; + Tree top = simplePattern(); if (s.token == IDENTIFIER) { if (s.name == STAR) { /* p* becomes z@( |(p,z)) */ s.nextToken(); diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index aa3bab9691..3834f4ddb0 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -199,6 +199,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } } } + //throw ex;//DEBUG return error(pos, ex.msg); } @@ -507,6 +508,14 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } }; + /** Check that there are no dependent parameter types among parameters + */ + void checkNoEscapeParams(ValDef[][] vparams) { + for (int i = 0; i < vparams.length; i++) + for (int j = 0; j < vparams[i].length; j++) + checkNoEscape(vparams[i][j].pos, vparams[i][j].tpe.type); + } + /** Check that tree represents a pure definition. */ void checkPureDef(Tree tree, Symbol clazz) { @@ -1174,6 +1183,31 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { // Attribution and Transform ------------------------------------------------- + /** Turn tree type into stable type if possible and required by + * context. + */ + Tree mkStable(Tree tree, Type pre, int mode, Type pt) { + if ((pt != null && pt.isStable() || (mode & QUALmode) != 0) && + pre.isStable()) { + Symbol sym = tree.symbol(); + switch (tree.type) { + case OverloadedType(Symbol[] alts, Type[] alttypes): + if ((mode & FUNmode) == 0) { + try { + infer.exprAlternative(tree, alts, alttypes, pt); + sym = tree.symbol(); + } catch (Type.Error ex) { + reportTypeError(tree.pos, ex); + } + } + } + if (sym.isStable()) { + tree.setType(Type.singleType(pre, sym)); + } + } + return tree; + } + /** Adapt tree to given mode and given prototype */ Tree adapt(Tree tree, int mode, Type pt) { @@ -1442,12 +1476,8 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { symtype = checkAccessible(tree.pos, sym, symtype, qual); if (symtype == Type.NoType) return error(tree.pos, "not found: " + decode(name)); - if ((pt != null && pt.isStable() || (mode & QUALmode) != 0) && sym.isStable()) { - //System.out.println("making single " + sym + ":" + symtype);//DEBUG - symtype = Type.singleType(pre, sym); - } //System.out.println(name + ":" + symtype);//DEBUG - return tree.setSymbol(sym).setType(symtype); + return mkStable(tree.setSymbol(sym).setType(symtype), pre, mode, pt); } /** Attribute a selection where `tree' is `qual.name'. @@ -1483,9 +1513,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { symtype = Type.PolyType(uninst, symtype); } } - if ((pt != null && pt.isStable() || (mode & QUALmode) != 0) && - sym.isStable() && qual.type.isStable()) - symtype = Type.singleType(qual.type, sym); //System.out.println(qual.type + ".member: " + sym + ":" + symtype);//DEBUG Tree tree1; switch (tree) { @@ -1498,7 +1525,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { default: throw new ApplicationError(); } - return tree1.setType(symtype); + return mkStable(tree1.setType(symtype), qual.type, mode, pt); } } @@ -1815,6 +1842,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { reenterParams(tparams, vparams, sym.primaryConstructor().type()); Tree.AbsTypeDef[] tparams1 = transform(tparams); Tree.ValDef[][] vparams1 = transform(vparams); + checkNoEscapeParams(vparams1); Tree tpe1 = transform(tpe, TYPEmode); if ((sym.flags & CASE) != 0 && vparams.length > 0 && templ.type == null) templ.body = desugarize.addCaseElements(templ.body, vparams[0]); @@ -1842,6 +1870,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { context.enclClass.owner.flags |= INCONSTRUCTOR; Tree.AbsTypeDef[] tparams1 = transform(tparams); Tree.ValDef[][] vparams1 = transform(vparams); + checkNoEscapeParams(vparams1); Tree tpe1 = (tpe == Tree.Empty) ? gen.mkType(tree.pos, sym.type().resultType()) : transform(tpe, TYPEmode); diff --git a/sources/scalac/typechecker/Infer.java b/sources/scalac/typechecker/Infer.java index 05d8916d66..befd1d151c 100644 --- a/sources/scalac/typechecker/Infer.java +++ b/sources/scalac/typechecker/Infer.java @@ -926,14 +926,7 @@ public class Infer implements Modifiers, Kinds { if (i == alts.length) throw new Type.Error("missing arguments for " + alts[0]); } - /* - // then catch the case of a single alternative. - if (alts.length == 1) { - tree.setSymbol(alts[0]).setType(alttypes[0]); - return; - } - */ - // finally, do the normal case. + // second, do the normal case. int best = -1; for (int i = 0; i < alttypes.length; i++) { if (isCompatible(alttypes[i], pt) && |