diff options
author | Martin Odersky <odersky@gmail.com> | 2005-12-02 18:58:51 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-12-02 18:58:51 +0000 |
commit | 1d724260bdae745cf6961a7fe15a501611cd2035 (patch) | |
tree | b2120e5ac629abfb6a54a6cc3131985bc06f1767 | |
parent | 7cd71254b00e2414235f5255869c4e752b8b4d10 (diff) | |
download | scala-1d724260bdae745cf6961a7fe15a501611cd2035.tar.gz scala-1d724260bdae745cf6961a7fe15a501611cd2035.tar.bz2 scala-1d724260bdae745cf6961a7fe15a501611cd2035.zip |
*** empty log message ***
-rwxr-xr-x | sources/scala/tools/nsc/ast/parser/Parsers.scala | 3 | ||||
-rw-r--r-- | sources/scala/tools/nsc/symtab/Flags.scala | 14 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Symbols.scala | 6 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/transform/LambdaLift.scala | 4 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/transform/UnCurry.scala | 8 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/Namers.scala | 2 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/Typers.scala | 7 | ||||
-rwxr-xr-x | test-nsc/files/run/bugs.scala | 17 |
8 files changed, 42 insertions, 19 deletions
diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala index 0c926df35f..68025a25ab 100755 --- a/sources/scala/tools/nsc/ast/parser/Parsers.scala +++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala @@ -1141,7 +1141,8 @@ import Tokens._; } val name = ident(); accept(COLON); - ValDef(mods | implicitmod, name, paramType(), EmptyTree) + val bynamemod = if (in.token == ARROW) Flags.BYNAMEPARAM else 0; + ValDef(mods | implicitmod | bynamemod, name, paramType(), EmptyTree) } } def paramClause(): List[ValDef] = { diff --git a/sources/scala/tools/nsc/symtab/Flags.scala b/sources/scala/tools/nsc/symtab/Flags.scala index d47551b893..666501a83a 100644 --- a/sources/scala/tools/nsc/symtab/Flags.scala +++ b/sources/scala/tools/nsc/symtab/Flags.scala @@ -51,10 +51,11 @@ object Flags { final val PARAMACCESSOR = 0x20000000; // for value definitions: is an access method for a final val parameter // for parameters: is a val parameter - final val LABEL = 0x40000000; // method symbol is a label. Set by TailCall - final val INCONSTRUCTOR = 0x40000000; // class symbol is defined in this/superclass constructor. + final val CAPTURED = 0x40000000; // variable is accessed from nested function. Set by LambdaLift + final val BYNAMEPARAM = 0x40000000; // parameter is by name - final val CAPTURED = 0x80000000L; // variable is accessed from nested function. Set by LambdaLift + final val LABEL = 0x80000000L; // method symbol is a label. Set by TailCall + final val INCONSTRUCTOR = 0x80000000L; // class symbol is defined in this/superclass constructor. final val IS_ERROR = 0x100000000L; // symbol is an error symbol final val OVERLOADED = 0x200000000L; // symbol is overloaded @@ -84,6 +85,7 @@ object Flags { final val notPROTECTED = (PROTECTED: long) << AntiShift; final val notABSTRACT = (ABSTRACT: long) << AntiShift; final val notOVERRIDE = (OVERRIDE: long) << AntiShift; + final val notMETHOD = (METHOD: long) << AntiShift; final val STATICMODULE = lateMODULE; final val STATICMEMBER = notOVERRIDE; @@ -99,7 +101,7 @@ object Flags { final val PrintableFlags = // these modifiers appear in TreePrinter output. ExplicitFlags | LOCAL | SYNTHETIC | STABLE | CASEACCESSOR | ACCESSOR | - SUPERACCESSOR | PARAMACCESSOR | LABEL | BRIDGE | STATIC; + SUPERACCESSOR | PARAMACCESSOR | BRIDGE | STATIC; final val FieldFlags = MUTABLE | CASEACCESSOR | PARAMACCESSOR | STATIC | FINAL; @@ -119,7 +121,7 @@ object Flags { .filter("" !=).mkString("", " ", ""); private def flagToString(flag: long): String = { - if (flag == CAPTURED) "<captured>" + if (flag == LABEL) "<label>" else if (flag == INTERFACE) "<interface>" else if (flag == IS_ERROR) "<is-error>" else if (flag == OVERLOADED) "<overloaded>" @@ -166,8 +168,8 @@ object Flags { case SUPERACCESSOR => "<superaccessor>" case PARAMACCESSOR => "<paramaccessor>" - case LABEL => "<label>" case BRIDGE => "<bridge>" + case CAPTURED => "<captured>" case _ => "" } diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 132dafd6b2..f0a7132f79 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -137,9 +137,7 @@ import Flags._; final def isValue = isTerm && !(isModule && hasFlag(PACKAGE | JAVA)); final def isVariable = isTerm && hasFlag(MUTABLE) && !isMethod; - - // XXX: Seems like this is what we really want for variables???? - final def isVariableX = isTerm && hasFlag(MUTABLE); + final def isCapturedVariable = isVariable && hasFlag(CAPTURED); final def isSetter = isTerm && hasFlag(ACCESSOR) && nme.isSetterName(name); //todo: make independent of name, as this can be forged. @@ -176,7 +174,7 @@ import Flags._; /** Does this symbol denote a stable value? */ final def isStable = - isTerm && !hasFlag(MUTABLE) && (!hasFlag(METHOD) || hasFlag(STABLE)); + isTerm && !hasFlag(MUTABLE) && (!hasFlag(METHOD | BYNAMEPARAM) || hasFlag(STABLE)); /** Does this symbol denote the primary constructor * of its enclosing class or trait? */ diff --git a/sources/scala/tools/nsc/transform/LambdaLift.scala b/sources/scala/tools/nsc/transform/LambdaLift.scala index 49330e728e..9acf89d9c2 100755 --- a/sources/scala/tools/nsc/transform/LambdaLift.scala +++ b/sources/scala/tools/nsc/transform/LambdaLift.scala @@ -275,7 +275,7 @@ abstract class LambdaLift extends InfoTransform { val tree1 = addFreeParams(tree, sym); if (sym.isLocal) liftDef(tree1) else tree1 case ValDef(mods, name, tpt, rhs) => - if (sym hasFlag CAPTURED) { + if (sym.isCapturedVariable) { val tpt1 = TypeTree(sym.tpe) setPos tpt.pos; val rhs1 = atPos(rhs.pos) { @@ -310,7 +310,7 @@ abstract class LambdaLift extends InfoTransform { atPos(tree.pos)(proxyRef(sym)) else tree else tree; - if (sym hasFlag CAPTURED) + if (sym.isCapturedVariable) atPos(tree.pos) { val tp = tree.tpe; val elemTree = typed { Select(tree1 setType sym.tpe, nme.elem) } diff --git a/sources/scala/tools/nsc/transform/UnCurry.scala b/sources/scala/tools/nsc/transform/UnCurry.scala index c778be212d..7bd12fb359 100755 --- a/sources/scala/tools/nsc/transform/UnCurry.scala +++ b/sources/scala/tools/nsc/transform/UnCurry.scala @@ -59,13 +59,15 @@ abstract class UnCurry extends InfoTransform { /** - return symbol's transformed type, * - if symbol is a def parameter with transformed type T, return () => T */ - def transformInfo(sym: Symbol, tp: Type): Type = if (sym.isType) tp else uncurry(tp); + def transformInfo(sym: Symbol, tp: Type): Type = + if (sym.isType) tp + else uncurry(tp); class UnCurryTransformer(unit: CompilationUnit) extends Transformer { private var needTryLift = false; private var inPattern = false; - private var inConstructorFlag = 0; + private var inConstructorFlag = 0L; override def transform(tree: Tree): Tree = try { //debug postTransform(mainTransform(tree)); @@ -207,7 +209,7 @@ abstract class UnCurry extends InfoTransform { t } - def withInConstructorFlag(inConstructorFlag: int)(f: => Tree): Tree = { + def withInConstructorFlag(inConstructorFlag: long)(f: => Tree): Tree = { val savedInConstructorFlag = this.inConstructorFlag; this.inConstructorFlag = inConstructorFlag; val t = f; diff --git a/sources/scala/tools/nsc/typechecker/Namers.scala b/sources/scala/tools/nsc/typechecker/Namers.scala index a40a6ea5d8..5ba18eb7a9 100755 --- a/sources/scala/tools/nsc/typechecker/Namers.scala +++ b/sources/scala/tools/nsc/typechecker/Namers.scala @@ -305,7 +305,7 @@ trait Namers: Analyzer { def enterValueParams(owner: Symbol, vparamss: List[List[ValDef]]): List[List[Symbol]] = { def enterValueParam(param: ValDef): Symbol = { param.symbol = owner.newValueParameter(param.pos, param.name) - .setInfo(typeCompleter(param)).setFlag(param.mods & IMPLICIT); + .setInfo(typeCompleter(param)).setFlag(param.mods & (BYNAMEPARAM | IMPLICIT)); context.scope enter param.symbol; param.symbol } diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala index 9f4532a762..9a6d6dab4b 100755 --- a/sources/scala/tools/nsc/typechecker/Typers.scala +++ b/sources/scala/tools/nsc/typechecker/Typers.scala @@ -1351,6 +1351,7 @@ import collection.mutable.HashMap; } else if (tparams.length == 0) { errorTree(tree, "" + tpt1.tpe + " does not take type parameters") } else { + //System.out.println("\{tpt1}:\{tpt1.symbol}:\{tpt1.symbol.info}"); System.out.println("" + tpt1 + ":" + tpt1.symbol + ":" + tpt1.symbol.info);//debug errorTree(tree, "wrong number of type arguments for " + tpt1.tpe + ", should be " + tparams.length) } @@ -1452,9 +1453,11 @@ import collection.mutable.HashMap; tree = Ident(info.name) setPos pos; if (!local) tree setSymbol info.sym; tree = typed1(tree, EXPRmode, pt); - if (settings.debug.value) log("typed implicit " + tree + ":" + tree.tpe + ", pt = " + pt);//debug + if (settings.debug.value) + log("typed implicit " + tree + ":" + tree.tpe + ", pt = " + pt);//debug val tree1 = adapt(tree, EXPRmode, pt); - if (settings.debug.value) log("adapted implicit " + tree.symbol + ":" + tree1.tpe + " to " + pt);//debug + if (settings.debug.value) + log("adapted implicit " + tree.symbol + ":" + tree1.tpe + " to " + pt);//debug if (info.sym == tree.symbol) tree1 else fail("syms differ: " + tree.symbol + " " + info.sym) } catch { diff --git a/test-nsc/files/run/bugs.scala b/test-nsc/files/run/bugs.scala index 659b49f825..95e66877bd 100755 --- a/test-nsc/files/run/bugs.scala +++ b/test-nsc/files/run/bugs.scala @@ -303,6 +303,23 @@ object Bug250Test { // Bug 257 object Bug257Test { + def sayhello(): Unit = { Console.println("I should come 1st and 2nd"); }; + def sayhi(): Unit = { Console.println("I should come last"); }; + + def f1(x: Unit): Unit = (); + def f2(x: Unit)(y: Unit): Unit = (); + + def f(x: => Unit) = { + f1(x); + f2(x); + } + + def main(args: Array[String]): Unit = { + f(sayhello())(sayhi()) + } +} + +object Bug257Test { def sayhello(): Unit = { Console.println("hello"); }; def f1(x: Unit): Unit = (); |