diff options
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/ast/parser/Parser.java | 11 | ||||
-rw-r--r-- | sources/scalac/transformer/LambdaLift.java | 2 | ||||
-rw-r--r-- | sources/scalac/transformer/UnCurry.java | 15 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 23 | ||||
-rw-r--r-- | sources/scalac/typechecker/Context.java | 4 |
5 files changed, 37 insertions, 18 deletions
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index 6aee3fc844..4f4b47a416 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -1781,11 +1781,14 @@ public class Parser implements Tokens { Tree constrExpr() { if (s.token == LBRACE) { int pos = s.skipToken(); - TreeList stats = new TreeList(); - stats.append(selfInvocation()); + TreeList statlist = new TreeList(); + statlist.append(selfInvocation()); + Tree[] stats; if (s.token == SEMI) { s.nextToken(); - stats = blockStatSeq(stats); + stats = blockStatSeq(statlist); + } else { + stats = statlist.toArray(); } accept(RBRACE); return make.Block(pos, stats); @@ -1800,7 +1803,7 @@ public class Parser implements Tokens { int pos = s.pos; accept(THIS); return make.Apply( - s.pos, make.Ident(pos, Names.CONSTRUCTOR, argumentExprs())); + s.pos, make.Ident(pos, Names.CONSTRUCTOR), argumentExprs()); } /** TypeDef ::= Id `=' Type diff --git a/sources/scalac/transformer/LambdaLift.java b/sources/scalac/transformer/LambdaLift.java index 61eb290c40..c12b7c8a79 100644 --- a/sources/scalac/transformer/LambdaLift.java +++ b/sources/scalac/transformer/LambdaLift.java @@ -473,7 +473,7 @@ public class LambdaLift extends OwnerTransformer for (int i = 0; i < params.length; i++) { params[i] = freevars[i].cloneSymbol(owner); params[i].pos = owner.pos; - params[i].flags &= ~CAPTURED; + params[i].flags &= CAPTURED; params[i].flags |= PARAM | SYNTHETIC; params[i].setInfo(freevars[i].type()); } diff --git a/sources/scalac/transformer/UnCurry.java b/sources/scalac/transformer/UnCurry.java index f7d8ec796f..c317267842 100644 --- a/sources/scalac/transformer/UnCurry.java +++ b/sources/scalac/transformer/UnCurry.java @@ -17,9 +17,18 @@ import scalac.symtab.*; import Tree.*; import scalac.typechecker.DeSugarize ; -/** (1) Make all functions into one-argument functions - * (2) Convert `def' parameters to closures - * (3) Convert matches with non-visitor arguments to postfix applications +/** - uncurry all symbol and tree types (@see UnCurryPhase) + * - for every curried parameter list: (ps_1) ... (ps_n) ==> (ps_1, ..., ps_n) + * - for every curried application: f(args_1)...(args_n) ==> f(args_1, ..., args_n) + * - for every type application: f[Ts] ==> f[Ts]() unless followed by parameters + * - for every use of a parameterless function: f ==> f() and q.f ==> q.f() + * - for every def-parameter: def x: T ==> x: () => T + * - for every use of a def-parameter: x ==> x.apply() + * - for every argument to a def parameter `def x: T': + * if argument is not a reference to a def parameter: + * convert argument `e' to (expansion of) `() => e' + * - for every argument list that corresponds to a repeated parameter + * (a_1, ..., a_n) => (Sequence(a_1, ..., a_n)) */ public class UnCurry extends OwnerTransformer implements Modifiers { diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index c456a33f7a..f840da0c30 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -1834,10 +1834,14 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree tpe1 = (tpe == Tree.Empty) ? gen.mkType(tree.pos, sym.type().resultType()) : transform(tpe, TYPEmode); - Tree rhs1 = transform( - rhs, - (name == Names.CONSTRUCTOR) ? CONSTRmode : EXPRmode, - tpe1.type); + Tree rhs1 = rhs; + if (rhs1 != Tree.Empty) { + rhs1 = transform( + rhs, + (name == Names.CONSTRUCTOR) ? CONSTRmode : EXPRmode, + tpe1.type); + } + popContext(); context.enclClass.owner.flags &= ~INCONSTRUCTOR; sym.flags |= LOCKED; checkNonCyclic(tree.pos, tpe1.type); @@ -1889,8 +1893,10 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree[] stats1 = desugarize.Statements(stats, true); enterSyms(stats1); context.imports = context.outer.imports; - if (mode == CONSTRmode) { - stats1[0] = transform(stats1[0], mode, pt); + Type owntype; + int curmode = mode; + if ((curmode & CONSTRmode) != 0) { + stats1[0] = transform(stats1[0], curmode, pt); context.enclClass.owner.flags &= ~INCONSTRUCTOR; for (int i = 1; i < stats1.length; i++) stats1[i] = transform(stats1[i], EXPRmode); @@ -1898,10 +1904,9 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } else { for (int i = 0; i < stats1.length - 1; i++) stats1[i] = transform(stats1[i], EXPRmode); - Type owntype; - if (stats1.length > start) { + if (stats1.length > 0) { stats1[stats1.length - 1] = - transform(stats1[stats1.length - 1], EXPRmode, pt); + transform(stats1[stats1.length - 1], curmode & ~FUNmode, pt); owntype = checkNoEscape(tree.pos, stats1[stats1.length - 1].type); } else { owntype = definitions.UNIT_TYPE; diff --git a/sources/scalac/typechecker/Context.java b/sources/scalac/typechecker/Context.java index 4c5f761c1f..61bf0a8299 100644 --- a/sources/scalac/typechecker/Context.java +++ b/sources/scalac/typechecker/Context.java @@ -20,6 +20,7 @@ public class Context { Context enclClass = this; // The next outer context whose tree // is a class template int variance; // Variance relative to enclosing class. + Symbol constructorClass; // Class for auxiliary constructor public Context() {} @@ -29,13 +30,14 @@ public class Context { public Context(Tree tree, Symbol owner, Scope scope, Context outer) { this.tree = tree; -Pa this.owner = owner; + this.owner = owner; this.scope = scope; this.imports = outer.imports; if (tree instanceof Tree.Template || tree instanceof Tree.CompoundType) this.enclClass = this; else this.enclClass = outer.enclClass; this.variance = outer.variance; + this.constructorClass = outer.constructorClass; this.outer = outer; } |