From fe9d7cc9ec4e55d42a09b149d60d6cf2f8be09af Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 3 Mar 2003 17:41:08 +0000 Subject: *** empty log message *** --- sources/examples/parsers1.scala | 16 ++--- sources/scala/PartialFunction.scala | 6 +- sources/scalac/ast/LazyTreeFactory.java | 8 ++- sources/scalac/ast/StrictTreeFactory.java | 10 ++- sources/scalac/ast/Transformer.java | 8 ++- sources/scalac/ast/Traverser.java | 6 +- sources/scalac/ast/Tree.java | 23 ++++--- sources/scalac/ast/TreeCopyFactory.java | 3 +- sources/scalac/ast/TreeCreator.java | 9 ++- sources/scalac/ast/TreeFactory.java | 3 +- sources/scalac/ast/TreeGen.java | 77 ++++++------------------ sources/scalac/ast/TreeInfo.java | 6 +- sources/scalac/ast/parser/Parser.java | 11 ++-- sources/scalac/ast/printer/TextTreePrinter.java | 8 ++- sources/scalac/backend/jvm/GenJVM.java | 2 +- sources/scalac/checkers/CheckOwners.java | 7 +-- sources/scalac/transformer/AddInterfaces.java | 2 +- sources/scalac/transformer/Erasure.java | 2 +- sources/scalac/transformer/LambdaLift.java | 15 +++-- sources/scalac/transformer/LambdaLiftPhase.java | 6 ++ sources/scalac/transformer/OwnerTransformer.java | 8 +-- sources/scalac/transformer/UnCurry.java | 2 +- sources/scalac/typechecker/Analyzer.java | 67 +++++++++++++-------- test/files/pos/lambda.scala | 2 +- test/files/pos/philippe2.scala | 2 + test/pos/lambda.scala | 2 +- test/pos/philippe2.scala | 2 + 27 files changed, 159 insertions(+), 154 deletions(-) diff --git a/sources/examples/parsers1.scala b/sources/examples/parsers1.scala index cf2d02d076..bbd0a0dbe0 100644 --- a/sources/examples/parsers1.scala +++ b/sources/examples/parsers1.scala @@ -7,35 +7,35 @@ case class Binop(op: Char, l: Tree, r: Tree): Tree extends Tree {} module Parse { - type Result[b] = Option[Pair[b, List[Char]]]; + trait Parser[p] { - trait Parser[p] extends Function1[List[Char], Result[p]] { + type Result = Option[Pair[p, List[Char]]]; - def apply(in: List[Char]): Result[p]; + def apply(in: List[Char]): Result; def filter(p: p => Boolean) = new Parser[p] { - def apply(in: List[Char]): Result[p] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case Some(Pair(x, in1)) => if (p(x)) Some(Pair(x, in1)) else None() case n => n } } def map[b](f: p => b) = new Parser[b] { - def apply(in: List[Char]): Result[b] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case Some(Pair(x, in1)) => Some(Pair(f(x), in1)) case None() => None() } } def flatMap[b](f: p => Parser[b]) = new Parser[b] { - def apply(in: List[Char]): Result[b] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case Some(Pair(x, in1)) => f(x)(in1) case None() => None() } } def ||| (def p: Parser[p]) = new Parser[p] { - def apply(in: List[Char]): Result[p] = Parser.this.apply(in) match { + def apply(in: List[Char]): Result = Parser.this.apply(in) match { case None() => p(in) case s => s } @@ -64,7 +64,7 @@ module ExprParser { import Parse._; def chrWith(p: Char => Boolean) = new Parser[Char] { - def apply(in: List[Char]): Result[Char] = in match { + def apply(in: List[Char]): Result = in match { case List() => None() case (c :: in1) => if (p(c)) Some(Pair(c, in1)) else None() } diff --git a/sources/scala/PartialFunction.scala b/sources/scala/PartialFunction.scala index 78963f1da7..9d8f8adbad 100644 --- a/sources/scala/PartialFunction.scala +++ b/sources/scala/PartialFunction.scala @@ -9,12 +9,8 @@ // $Id$ package scala { - abstract class PartialFunction[A, B]() { - + trait PartialFunction[A, B] { def apply(x: A): B; - def isDefinedAt(x: A): scala.Boolean; - } - } diff --git a/sources/scalac/ast/LazyTreeFactory.java b/sources/scalac/ast/LazyTreeFactory.java index 26f5f9a98f..4f81a103f8 100644 --- a/sources/scalac/ast/LazyTreeFactory.java +++ b/sources/scalac/ast/LazyTreeFactory.java @@ -123,15 +123,13 @@ public class LazyTreeFactory extends AbstractTreeCopyFactory { public Tree TypeDef(Tree tree, int mods, Name name, - TypeDef[] tparams, Tree rhs) { TypeDef t = (TypeDef)tree; if ((t.mods == mods) && (t.name == name) && - (t.tparams == tparams) && (t.rhs == rhs)) return t; - tree = make.TypeDef(t.pos, mods, name, tparams, rhs); + tree = make.TypeDef(t.pos, mods, name, rhs); attribute(tree, t); return tree; } @@ -351,6 +349,10 @@ public class LazyTreeFactory extends AbstractTreeCopyFactory { return tree; } + public Tree TypeTerm(Tree tree) { + return tree; + } + public Tree SingletonType(Tree tree, Tree ref) { SingletonType t = (SingletonType)tree; diff --git a/sources/scalac/ast/StrictTreeFactory.java b/sources/scalac/ast/StrictTreeFactory.java index c68453424e..e047ca7265 100644 --- a/sources/scalac/ast/StrictTreeFactory.java +++ b/sources/scalac/ast/StrictTreeFactory.java @@ -94,10 +94,9 @@ public class StrictTreeFactory extends AbstractTreeCopyFactory { public Tree TypeDef(Tree tree, int mods, Name name, - TypeDef[] tparams, Tree rhs) { TypeDef t = (TypeDef)tree; - tree = make.TypeDef(t.pos, mods, name, tparams, rhs); + tree = make.TypeDef(t.pos, mods, name, rhs); attribute(tree, t); return tree; } @@ -266,6 +265,13 @@ public class StrictTreeFactory extends AbstractTreeCopyFactory { return tree; } + public Tree TypeTerm(Tree tree) { + TypeTerm t = (TypeTerm) tree; + tree = make.TypeTerm(t.pos); + attribute(tree, t); + return tree; + } + public Tree SingletonType(Tree tree, Tree ref) { SingletonType t = (SingletonType)tree; tree = make.SingletonType(t.pos, ref); diff --git a/sources/scalac/ast/Transformer.java b/sources/scalac/ast/Transformer.java index 5425f2ebf3..aa2135f5be 100644 --- a/sources/scalac/ast/Transformer.java +++ b/sources/scalac/ast/Transformer.java @@ -222,12 +222,10 @@ public class Transformer extends Phase { transform(rhs)); case TypeDef(int mods, Name name, - TypeDef[] tparams, Tree rhs): return copy.TypeDef(tree, mods, name, - transform(tparams), transform(rhs)); case Import(Tree expr, Name[] selectors): return copy.Import(tree, @@ -297,6 +295,8 @@ public class Transformer extends Phase { return copy.Ident(tree, name); case Literal(Object value): return copy.Literal(tree, value); + case TypeTerm(): + return copy.TypeTerm(tree); case SingletonType(Tree ref): return copy.SingletonType(tree, transform(ref)); @@ -340,7 +340,7 @@ public class Transformer extends Phase { case DefDef(int mods, Name name, TypeDef[] tparams, ValDef[][] vparams, Tree tpe, Tree rhs): - case TypeDef(int mods, Name name, TypeDef[] tparams, Tree rhs): + case TypeDef(int mods, Name name, Tree rhs): case Import(Tree expr): @@ -378,6 +378,8 @@ public class Transformer extends Phase { case Literal(int kind, Object value): + case TypeTerm(): + case SingletonType(Tree ref): case SelectFromType(Tree qualifier, Name selector): diff --git a/sources/scalac/ast/Traverser.java b/sources/scalac/ast/Traverser.java index ad40be1f06..d79f1804e4 100644 --- a/sources/scalac/ast/Traverser.java +++ b/sources/scalac/ast/Traverser.java @@ -83,8 +83,7 @@ public class Traverser { traverse(rhs); return; - case TypeDef(int mods, Name name, TypeDef[] tparams, Tree rhs): - traverse(tparams); + case TypeDef(int mods, Name name, Tree rhs): traverse(rhs); return; @@ -167,6 +166,9 @@ public class Traverser { traverse(qualifier); return; + case TypeTerm(): + return; + case SingletonType(Tree ref): traverse(ref); return; diff --git a/sources/scalac/ast/Tree.java b/sources/scalac/ast/Tree.java index 700aca2fd1..da3bcacc84 100644 --- a/sources/scalac/ast/Tree.java +++ b/sources/scalac/ast/Tree.java @@ -136,7 +136,6 @@ public class Tree { */ public case TypeDef(int mods, Name name, - TypeDef[] tparams, Tree rhs) { assert name.isTypeName(); if (!rhs.isType()) @@ -360,10 +359,17 @@ public class Tree { */ public case Literal(Object value); + /** + * TypeTerm + * - introduced by: Analyzer + * - eliminated by: - + */ + public case TypeTerm(); + /** * Singleton type * - introduced by: parser - * - eliminated by: !!! ? (could be done by analyzer ?) + * - eliminated by: Analyzer */ public case SingletonType(Tree ref) { if (!ref.isTerm()) @@ -373,7 +379,7 @@ public class Tree { /** * Type selection * - introduced by: parser - * - eliminated by: !!! ? (could be done by analyzer ?) + * - eliminated by: Analyzer */ public case SelectFromType(Tree qualifier, Name selector) { @@ -385,7 +391,7 @@ public class Tree { /** * Function type * - introduced by: parser - * - eliminated by: !!! ? (could be done by analyzer ?) + * - eliminated by: Analyzer */ public case FunType(Tree[] argtpes, Tree restpe) { @@ -399,7 +405,7 @@ public class Tree { /** * Object type (~ Template) * - introduced by: parser - * - eliminated by: !!! ? (could be done by analyzer ?) + * - eliminated by: Analyzer */ public case CompoundType(Tree[] parents, Tree[] refinements) { @@ -415,7 +421,7 @@ public class Tree { /** * Applied type * - introduced by: parser - * - eliminated by: !!! ? (could be done by analyzer ?) + * - eliminated by: Analyzer */ public case AppliedType(Tree tpe, Tree[] args) { assert tpe.isType() : this; @@ -468,6 +474,7 @@ public class Tree { switch(this) { case Bad(): case Empty: + case TypeTerm(): case SingletonType(_): case SelectFromType(_, _): case CompoundType(_, _): @@ -723,9 +730,9 @@ public class Tree { public static final TypeDef[] EMPTY_ARRAY = new TypeDef[0]; - public ExtTypeDef(int mods, Name name, TypeDef[] tparams, Tree rhs) + public ExtTypeDef(int mods, Name name, Tree rhs) { - super(mods, name, tparams, rhs); + super(mods, name, rhs); } public boolean hasSymbol() { diff --git a/sources/scalac/ast/TreeCopyFactory.java b/sources/scalac/ast/TreeCopyFactory.java index 76294fd583..69f82aa6ca 100644 --- a/sources/scalac/ast/TreeCopyFactory.java +++ b/sources/scalac/ast/TreeCopyFactory.java @@ -64,7 +64,6 @@ public interface TreeCopyFactory { public Tree TypeDef(Tree tree, int mods, Name name, - TypeDef[] tparams, Tree rhs); public Tree Import(Tree tree, @@ -137,6 +136,8 @@ public interface TreeCopyFactory { public Tree Literal(Tree tree, Object value); + public Tree TypeTerm(Tree tree); + public Tree SingletonType(Tree tree, Tree ref); diff --git a/sources/scalac/ast/TreeCreator.java b/sources/scalac/ast/TreeCreator.java index e9bb124465..60d40f6d63 100644 --- a/sources/scalac/ast/TreeCreator.java +++ b/sources/scalac/ast/TreeCreator.java @@ -85,9 +85,8 @@ public class TreeCreator implements TreeFactory { public Tree TypeDef(int pos, int mods, Name name, - TypeDef[] tparams, Tree rhs) { - Tree t = new ExtTypeDef(mods, name, tparams, rhs); + Tree t = new ExtTypeDef(mods, name, rhs); t.pos = pos; return t; } @@ -239,6 +238,12 @@ public class TreeCreator implements TreeFactory { } + public Tree TypeTerm(int pos) { + Tree t = new TypeTerm(); + t.pos = pos; + return t; + } + public Tree SingletonType(int pos, Tree ref) { Tree t = new SingletonType(ref); t.pos = pos; diff --git a/sources/scalac/ast/TreeFactory.java b/sources/scalac/ast/TreeFactory.java index a5d6b914bc..23c40a3004 100644 --- a/sources/scalac/ast/TreeFactory.java +++ b/sources/scalac/ast/TreeFactory.java @@ -55,7 +55,6 @@ public interface TreeFactory { public Tree TypeDef(int pos, int mods, Name name, - TypeDef[] tparams, Tree rhs); public Tree Import(int pos, @@ -128,6 +127,8 @@ public interface TreeFactory { public Tree Literal(int pos, Object value); + public Tree TypeTerm(int pos); + public Tree SingletonType(int pos, Tree ref); diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 1eb59ca0e0..4154710822 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -86,68 +86,25 @@ public class TreeGen implements Kinds, Modifiers { /** Build and attribute tree corresponding to given type. */ public Tree mkType(int pos, Type type) { - Tree tree = mkTycon(pos, type); - switch (type) { - case TypeRef(Type pre, Symbol sym, Type[] args): - if (args.length != 0) - return make.AppliedType(pos, tree, mkType(pos, args)) - .setType(type); - } - return tree; - } - - /** Build and attribute tree corresponding to given type constructor. - */ - public Tree mkTycon(int pos, Type type) { - //System.out.println("making type " + type);//DEBUG - switch (type) { - - case NoType: - return Tree.Empty; - - case ErrorType: - case AnyType: - return make.Bad(pos).setSymbol(Symbol.ERROR).setType(type); - - case ThisType(_): - case SingleType(_, _): - return make.SingletonType(pos, mkStableId(pos, type)).setType(type); - - case TypeRef(Type pre, Symbol sym, Type[] args): - return mkRef(pos, pre, sym); - - case CompoundType(Type[] parents, Scope members): - if (parents.length == 1 && members.elems == Scope.Entry.NONE) - return mkType(pos, parents[0]); - else - return make.CompoundType( - pos, mkType(pos, parents), mkDefs(pos, members.elements())) - .setType(type); - - case CovarType(Type tp): - return make.CovariantType(pos, mkType(pos, tp)) - .setType(type); - - case UnboxedType(_): - case UnboxedArrayType(_): - return make.Ident(pos, Name.fromString(type.toString()).toTypeName()) - .setType(type); - - default: - throw new ApplicationError("illegal type", type); - } + return TypeTerm(pos, type); } /** Build and attribute tree array corresponding to given type array. */ - public Tree[] mkType(int pos, Type[] types) { + public Tree[] mkTypes(int pos, Type[] types) { Tree[] res = new Tree[types.length]; for (int i = 0; i < types.length; i++) { - res[i] = mkType(pos, types[i]); + res[i] = mkType(pos, types[i]); } return res; } + /** Build and attribute tree corresponding to given type. + */ + public Tree TypeTerm(int pos, Type type) { + return make.TypeTerm(pos).setType(type); + } + /** Build and attribute tree corresponding to symbol's declaration. */ public Tree mkDef(int pos, Symbol sym) { @@ -181,7 +138,7 @@ public class TreeGen implements Kinds, Modifiers { case TypeRef(Type pre, Symbol sym, Type[] args): Tree ref = mkRef(pos, pre, sym.constructor()); Tree constr = (args.length == 0) ? ref - : TypeApply(ref, mkType(sym.pos, args)); + : TypeApply(ref, mkTypes(sym.pos, args)); switch (parentType) { case MethodType(Symbol[] params, Type restpe): assert params.length == 0 : parentType; @@ -255,8 +212,7 @@ public class TreeGen implements Kinds, Modifiers { pos, sym.flags & SOURCEFLAGS, sym.name, - mkTypeParams(pos, sym.typeParams()), - mkType(pos, symtype)) + TypeTerm(pos, symtype)) .setSymbol(sym).setType(definitions.UNIT_TYPE); } @@ -301,7 +257,7 @@ public class TreeGen implements Kinds, Modifiers { } public Tree Typed(Tree tree, Type tp) { - return make.Typed(tree.pos, tree, mkType(tree.pos, tp)).setType(tp); + return make.Typed(tree.pos, tree, TypeTerm(tree.pos, tp)).setType(tp); } /** Build and attribute the assignment lhs = rhs @@ -329,7 +285,8 @@ public class TreeGen implements Kinds, Modifiers { public Tree New(int pos, Type pre, Symbol clazz, Type[] targs, Tree[] args) { Tree constr = mkRef(pos, pre, clazz.constructor()); - if (targs.length != 0) constr = TypeApply(constr, mkType(pos, targs)); + if (targs.length != 0) + constr = TypeApply(constr, mkTypes(pos, targs)); Tree base = Apply(constr, args); return New(base); } @@ -435,7 +392,7 @@ public class TreeGen implements Kinds, Modifiers { /** Build and attribute super node with given type. */ public Tree Super(int pos, Type type) { - return make.Super(pos, mkType(pos, type)).setType(type); + return make.Super(pos, TypeTerm(pos, type)).setType(type); } /** Build and attribute value/variable/let definition node whose signature @@ -448,7 +405,7 @@ public class TreeGen implements Kinds, Modifiers { return make.ValDef(pos, sym.flags & SOURCEFLAGS, sym.name, - mkType(pos, symtype), + TypeTerm(pos, symtype), rhs) .setSymbol(sym).setType(definitions.UNIT_TYPE); } @@ -469,7 +426,7 @@ public class TreeGen implements Kinds, Modifiers { sym.name, mkTypeParams(pos, symtype.typeParams()), mkParams(pos, symtype), - mkType(pos, symtype.resultType()), + TypeTerm(pos, symtype.resultType()), body) .setSymbol(sym).setType(definitions.UNIT_TYPE); } diff --git a/sources/scalac/ast/TreeInfo.java b/sources/scalac/ast/TreeInfo.java index 75d6dfa863..e75c1c063c 100644 --- a/sources/scalac/ast/TreeInfo.java +++ b/sources/scalac/ast/TreeInfo.java @@ -44,7 +44,7 @@ public class TreeInfo { case ModuleDef(_, _, _, _): case DefDef(_, _, _, _, _, _): case ValDef(_, _, _, _): - case TypeDef(_, _, _, _): + case TypeDef(_, _, _): case Import(_, _): return true; default: @@ -58,7 +58,7 @@ public class TreeInfo { return rhs == Tree.Empty; case ValDef(_, _, _, Tree rhs): return rhs == Tree.Empty; - case TypeDef(_, _, _, _): + case TypeDef(_, _, _): return true; default: return false; @@ -72,7 +72,7 @@ public class TreeInfo { case ClassDef(_, _, _, _, _, _): case ModuleDef(_, _, _, _): case DefDef(_, _, _, _, _, _): - case TypeDef(_, _, _, _): + case TypeDef(_, _, _): case Import(_, _): return true; case ValDef(int mods, _, _, Tree rhs): diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index 8243d73411..fa2769f8d9 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -1176,8 +1176,7 @@ public class Parser implements Tokens { } else { tp = scalaDot(pos, Names.Any.toTypeName()); } - return make.TypeDef(pos, Modifiers.PARAM, name.toTypeName(), - Tree.ExtTypeDef.EMPTY_ARRAY, tp); + return make.TypeDef(pos, Modifiers.PARAM, name.toTypeName(), tp); } //////// DEFS //////////////////////////////////////////////////////////////// @@ -1454,16 +1453,14 @@ public class Parser implements Tokens { Name name = ident().toTypeName(); if (s.token == SUBTYPE) { s.nextToken(); - return make.TypeDef(pos, mods | Modifiers.DEFERRED, name, - Tree.ExtTypeDef.EMPTY_ARRAY, type()); + return make.TypeDef(pos, mods | Modifiers.DEFERRED, name, type()); } else if (s.token == EQUALS) { s.nextToken(); - return make.TypeDef(pos, mods, name, - Tree.ExtTypeDef.EMPTY_ARRAY, type()); + return make.TypeDef(pos, mods, name, type()); } else if (s.token == SEMI || s.token == COMMA) { return make.TypeDef( pos, mods | Modifiers.DEFERRED, name, - Tree.ExtTypeDef.EMPTY_ARRAY, scalaDot(pos, Names.Any.toTypeName())); + scalaDot(pos, Names.Any.toTypeName())); } else { return syntaxError("`=' or `<:' expected", true); } diff --git a/sources/scalac/ast/printer/TextTreePrinter.java b/sources/scalac/ast/printer/TextTreePrinter.java index 5836e24f0e..26dadcc679 100644 --- a/sources/scalac/ast/printer/TextTreePrinter.java +++ b/sources/scalac/ast/printer/TextTreePrinter.java @@ -308,13 +308,11 @@ public class TextTreePrinter implements TreePrinter { case TypeDef(int mods, Name name, - Tree.TypeDef[] tparams, Tree rhs): printModifiers(mods); print(KW_TYPE); print(Text.Space); printSymbolDefinition(tree.symbol(), name); - printParams(tparams); if ((mods & (Modifiers.DEFERRED | Modifiers.PARAM)) != 0) printOpt(TXT_SUBTYPE, rhs, true); else printOpt(TXT_EQUAL, rhs, true); break; @@ -471,6 +469,10 @@ public class TextTreePrinter implements TreePrinter { printType(tree); break; + case TypeTerm(): + print(tree.type.toString()); + break; + case SingletonType(Tree ref): print(ref); print(TXT_DOT); print(KW_TYPE); @@ -662,7 +664,7 @@ public class TextTreePrinter implements TreePrinter { protected void printParam(Tree tree) { switch (tree) { - case TypeDef(int mods, Name name, _, Tree bound): + case TypeDef(int mods, Name name, Tree bound): printModifiers(mods); printSymbolDefinition(tree.symbol(), name); printOpt(TXT_SUBTYPE, bound, true); diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java index 2c1fe19b50..d9257d6325 100644 --- a/sources/scalac/backend/jvm/GenJVM.java +++ b/sources/scalac/backend/jvm/GenJVM.java @@ -451,7 +451,7 @@ class JVMGenerator { break; case Empty: - case TypeDef(_, _, _, _): + case TypeDef(_, _, _): case TypeApply(_, _): case FunType(_, _): case CompoundType(_, _): diff --git a/sources/scalac/checkers/CheckOwners.java b/sources/scalac/checkers/CheckOwners.java index f23bcb4d7e..4bb82ffdb9 100644 --- a/sources/scalac/checkers/CheckOwners.java +++ b/sources/scalac/checkers/CheckOwners.java @@ -67,7 +67,7 @@ public class CheckOwners extends Checker { case ModuleDef(_,_,_,_): case DefDef(_,_,_,_,_,_): case ValDef(_,_,_,_): - case TypeDef(_,_,_,_): + case TypeDef(_,_,_): traverse(body[i], owner); break; default: @@ -134,9 +134,8 @@ public class CheckOwners extends Checker { traverse(rhs, tree.symbol()); } break; - case TypeDef(int mods, Name name, TypeDef[] tparams, Tree rhs): { + case TypeDef(int mods, Name name, Tree rhs): { check(tree); - traverse(tparams, tree.symbol()); traverse(rhs, tree.symbol()); } break; @@ -152,7 +151,7 @@ public class CheckOwners extends Checker { case ModuleDef(_,_,_,_): case DefDef(_,_,_,_,_,_): case ValDef(_,_,_,_): - case TypeDef(_,_,_,_): { + case TypeDef(_,_,_): { Symbol sym = tree.symbol(); if (sym != null && sym != Symbol.NONE) { checkOwner(tree, sym); diff --git a/sources/scalac/transformer/AddInterfaces.java b/sources/scalac/transformer/AddInterfaces.java index 33aad65d32..2779cc528e 100644 --- a/sources/scalac/transformer/AddInterfaces.java +++ b/sources/scalac/transformer/AddInterfaces.java @@ -440,7 +440,7 @@ class AddInterfaces extends SubstTransformer { List newBody = new LinkedList(); for (int i = 0; i < body.length; ++i) { switch (body[i]) { - case TypeDef(_, _, _, _): + case TypeDef(_, _, _): break; default: newBody.add(transform(body[i])); diff --git a/sources/scalac/transformer/Erasure.java b/sources/scalac/transformer/Erasure.java index 5501d67140..91acf22286 100644 --- a/sources/scalac/transformer/Erasure.java +++ b/sources/scalac/transformer/Erasure.java @@ -345,7 +345,7 @@ public class Erasure extends Transformer implements Modifiers { tree, mods, name, tpe1, rhs1) .setType(owntype); - case TypeDef(_, _, _, _): + case TypeDef(_, _, _): // eliminate return Tree.Empty; diff --git a/sources/scalac/transformer/LambdaLift.java b/sources/scalac/transformer/LambdaLift.java index 3eeb6d15b5..6e893c835a 100644 --- a/sources/scalac/transformer/LambdaLift.java +++ b/sources/scalac/transformer/LambdaLift.java @@ -207,13 +207,19 @@ public class LambdaLift extends OwnerTransformer } return super.transform(tree); - case TypeDef(int mods, Name name, TypeDef[] tparams, Tree rhs): + case TypeDef(int mods, Name name, Tree rhs): // ignore type definition as owner. // reason: it might be in a refinement // todo: handle type parameters? return copy.TypeDef( tree, mods, name, - transform(tparams, currentOwner), + transform(rhs, currentOwner)); + + case ValDef(int mods, Name name, Tree tpe, Tree rhs): + // ignore value definition as owner. + // reason: it might be in a refinement + return copy.ValDef( + tree, mods, name, transform(tpe), transform(rhs, currentOwner)); case Ident(Name name): @@ -354,20 +360,19 @@ public class LambdaLift extends OwnerTransformer transform(rhs, sym)); } - case TypeDef(int mods, Name name, TypeDef[] tparams, Tree rhs): + case TypeDef(int mods, Name name, Tree rhs): // ignore type definition as owner. // reason: it might be in a refinement // todo: handle type parameters? return copy.TypeDef( tree, mods, name, - transform(tparams, currentOwner), transform(rhs, currentOwner)); case ValDef(int mods, Name name, Tree tpe, Tree rhs): Symbol sym = tree.symbol(); Name name1 = sym.name; Tree tpe1 = transform(tpe); - Tree rhs1 = transform(rhs, sym); + Tree rhs1 = transform(rhs, currentOwner); if ((sym.flags & CAPTURED) != 0) { assert sym.isLocal(); Type unboxedType = sym.typeAt(descr.nextPhase); diff --git a/sources/scalac/transformer/LambdaLiftPhase.java b/sources/scalac/transformer/LambdaLiftPhase.java index 1960175ae8..7dff375d6a 100644 --- a/sources/scalac/transformer/LambdaLiftPhase.java +++ b/sources/scalac/transformer/LambdaLiftPhase.java @@ -71,6 +71,9 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers while (i > 0 && (tparams[i-1].flags & SYNTHETIC) != 0) i--; if (i < tparams.length) { + if (global.debug) + global.log("adding proxies for " + sym + ": " + ArrayApply.toString(tparams)); + Type[] targs1 = new Type[tparams.length]; System.arraycopy(map(targs), 0, targs1, 0, targs.length); while (i < tparams.length) { @@ -103,6 +106,9 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers global.log("proxy " + fv + " in " + LambdaLift.asFunction(owner)); Symbol o = owner; while (o.kind != NONE) { + if (global.debug) + global.log("looking in " + LambdaLift.asFunction(o) + " " + + ArrayApply.toString(o.typeParams())); Symbol fowner = LambdaLift.asFunction(o); if (fv.owner() == fowner) return fv; Type ft = (fowner.isUpdated(nextPhase)) ? fowner.typeAt(nextPhase) diff --git a/sources/scalac/transformer/OwnerTransformer.java b/sources/scalac/transformer/OwnerTransformer.java index c723aeb6bb..56abf67be2 100644 --- a/sources/scalac/transformer/OwnerTransformer.java +++ b/sources/scalac/transformer/OwnerTransformer.java @@ -117,13 +117,11 @@ public class OwnerTransformer extends Transformer { case ValDef(int mods, Name name, Tree tpe, Tree rhs): return copy.ValDef( tree, mods, name, transform(tpe), - transform(rhs)); + transform(rhs, tree.symbol())); - case TypeDef(int mods, Name name, TypeDef[] tparams, Tree rhs): + case TypeDef(int mods, Name name, Tree rhs): return copy.TypeDef( - tree, mods, name, - transform(tparams, tree.symbol()), - transform(rhs, tree.symbol())); + tree, mods, name, transform(rhs, tree.symbol())); default: return super.transform(tree); diff --git a/sources/scalac/transformer/UnCurry.java b/sources/scalac/transformer/UnCurry.java index 40e23e7282..461fa150df 100644 --- a/sources/scalac/transformer/UnCurry.java +++ b/sources/scalac/transformer/UnCurry.java @@ -93,7 +93,7 @@ public class UnCurry extends OwnerTransformer Tree tpe1 = gen.mkType(tpe.pos, newtype); return copy.ValDef(tree, mods1, name, tpe1, rhs).setType(newtype); } else { - return tree; + return super.transform(tree); } case TypeApply(Tree fn, Tree[] args): diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index dd8a65ff22..5434867311 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -655,7 +655,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { case DefDef(int mods, Name name, _, _, _, _): return enterSym(tree, new TermSymbol(tree.pos, name, owner, mods)); - case TypeDef(int mods, Name name, _, _): + case TypeDef(int mods, Name name, _): int kind = (mods & (DEFERRED | PARAM)) != 0 ? TYPE : ALIAS; return enterSym(tree, new TypeSymbol(kind, tree.pos, name, owner, mods)); @@ -798,6 +798,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { case ValDef(int mods, Name name, Tree tpe, Tree rhs): if (tpe == Tree.Empty) { + pushContext(tree, sym, context.scope); if (rhs == Tree.Empty) { if ((sym.owner().flags & ACCESSOR) != 0) { // this is the paremeter of a variable setter method. @@ -813,6 +814,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { ((ValDef) tree).rhs = rhs = transform(rhs, EXPRmode); owntype = rhs.type.widen(); } + popContext(); } else { owntype = transform(tpe, TYPEmode).type; } @@ -835,7 +837,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { owntype = makeMethodType(tparamSyms, vparamSyms, restpe); break; - case TypeDef(int mods, Name name, Tree.TypeDef[] tparams, Tree rhs): + case TypeDef(int mods, Name name, Tree rhs): //todo: alwyas have context.owner as owner. if (sym.kind == TYPE) { pushContext(rhs, context.owner, context.scope); @@ -1073,8 +1075,15 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { qual.type.isStable()) symtype = Type.singleType(qual.type, sym); //System.out.println(qual.type + ".member: " + sym + ":" + symtype);//DEBUG - return copy.Select(tree, qual, name) - .setSymbol(sym).setType(symtype); + switch (tree) { + case Select(_, _): + return copy.Select(tree, qual, name) + .setSymbol(sym).setType(symtype); + case SelectFromType(_, _): + return make.TypeTerm(tree.pos).setType(symtype); + default: + throw new ApplicationError(); + } } } @@ -1600,7 +1609,9 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { tpe1 = gen.mkType(rhs1.pos, rhs.type.widen()); // rhs already attributed by defineSym in this case } else if (rhs != Tree.Empty) { + pushContext(tree, sym, context.scope); rhs1 = transform(rhs1, EXPRmode, sym.type()); + popContext(); } return copy.ValDef(tree, mods, name, tpe1, rhs1) .setType(definitions.UNIT_TYPE); @@ -1624,15 +1635,13 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { return copy.DefDef(tree, mods, name, tparams1, vparams1, tpe1, rhs1) .setType(definitions.UNIT_TYPE); - case TypeDef(int mods, Name name, Tree.TypeDef[] tparams, Tree rhs): + case TypeDef(int mods, Name name, Tree rhs): pushContext(tree, sym, new Scope(context.scope)); - reenterParams(tparams); - Tree.TypeDef[] tparams1 = transform(tparams); int mode = TYPEmode; if (sym.kind == ALIAS) mode |= FUNmode; Tree rhs1 = transform(rhs, mode); popContext(); - return copy.TypeDef(tree, mods, name, tparams1, rhs1) + return copy.TypeDef(tree, mods, name, rhs1) .setType(definitions.UNIT_TYPE); case Import(Tree expr, Name[] selectors): @@ -1913,9 +1922,12 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { case Literal(Object value): return tree.setType(definitions.getType(value2TypeName(value))); + case TypeTerm(): + return tree; + case SingletonType(Tree ref): Tree ref1 = transform(ref, EXPRmode, Type.AnyType); - return copy.SingletonType(tree, ref1) + return make.TypeTerm(tree.pos) .setType(checkObjectType(tree.pos, ref1.type)); case SelectFromType(Tree qual, Name name): @@ -1936,40 +1948,43 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree[] refinements1 = transformStatSeq(refinements, Symbol.NONE); checkAllOverrides(clazz); popContext(); - return copy.CompoundType(tree, parents1, refinements1) + return make.TypeTerm(tree.pos) .setType(self); case AppliedType(Tree tpe, Tree[] args): Tree tpe1 = transform(tpe, TYPEmode | FUNmode); Tree[] args1 = transform(args, TYPEmode); Type[] argtypes = Tree.typeOf(args); - Symbol[] tparams = tpe1.type.typeParams(); + //todo: this needs to be refined. + Symbol[] tparams = + (Type.isSameAs(tpe1.type.typeArgs(), Symbol.type(tpe1.type.typeParams()))) + ? tpe1.type.typeParams() + : Symbol.EMPTY_ARRAY; + Type owntype = Type.ErrorType; if (tpe1.type != Type.ErrorType) { - if (tparams.length != args.length) { - if (tparams.length == 0) - return error(tree, tpe1.type + - " does not take type parameters"); - else - return error(tree, - "wrong number of type arguments for " + - tpe1.type); - } else { + if (tparams.length == args.length) { try { if (!context.delayArgs) infer.checkBounds(tparams, argtypes, ""); + owntype = Type.appliedType(tpe1.type, argtypes); } catch (Type.Error ex) { - return error(tree, ex.msg); + error(tree.pos, ex.msg); } + } else { + if (tparams.length == 0) + error(tree.pos, tpe1.type + + " does not take type parameters"); + else + error(tree.pos, + "wrong number of type arguments for " + + tpe1.type); } - return copy.AppliedType(tree, tpe1, args1) - .setType(Type.appliedType(tpe1.type, argtypes)); - } else { - return tpe1; } + return make.TypeTerm(tree.pos).setType(owntype); case CovariantType(Tree tpe): Tree tpe1 = transform(tpe, TYPEmode); - return copy.CovariantType(tree, tpe1) + return make.TypeTerm(tree.pos) .setType(Type.covarType(tpe1.type)); case FunType(_, _): diff --git a/test/files/pos/lambda.scala b/test/files/pos/lambda.scala index 0c85672ac1..27c273cc3c 100644 --- a/test/files/pos/lambda.scala +++ b/test/files/pos/lambda.scala @@ -4,5 +4,5 @@ module test { def twice[a](f: a => a): a => a = x: a => f(f(x)); - def main = apply[Int,Int](twice@[Int](x: Int => x))(1); + def main = apply[Int,Int](twice[Int](x: Int => x))(1); } \ No newline at end of file diff --git a/test/files/pos/philippe2.scala b/test/files/pos/philippe2.scala index 2f61fc46ca..0dc896ebfd 100644 --- a/test/files/pos/philippe2.scala +++ b/test/files/pos/philippe2.scala @@ -1,3 +1,5 @@ + +import scala._; class m1() { def n() = 0; def foo(i: Int)(j: Int): Unit = (); diff --git a/test/pos/lambda.scala b/test/pos/lambda.scala index 0c85672ac1..27c273cc3c 100644 --- a/test/pos/lambda.scala +++ b/test/pos/lambda.scala @@ -4,5 +4,5 @@ module test { def twice[a](f: a => a): a => a = x: a => f(f(x)); - def main = apply[Int,Int](twice@[Int](x: Int => x))(1); + def main = apply[Int,Int](twice[Int](x: Int => x))(1); } \ No newline at end of file diff --git a/test/pos/philippe2.scala b/test/pos/philippe2.scala index 2f61fc46ca..0dc896ebfd 100644 --- a/test/pos/philippe2.scala +++ b/test/pos/philippe2.scala @@ -1,3 +1,5 @@ + +import scala._; class m1() { def n() = 0; def foo(i: Int)(j: Int): Unit = (); -- cgit v1.2.3