diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-06-15 15:03:20 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-06-15 15:03:20 +0000 |
commit | 7337db9c59daeac26e81e22cfea4f7d8b43a0747 (patch) | |
tree | fdf3fa7868907040432296e889f8030010c7b3e6 /src | |
parent | a907772ff59f7150637494f46b60665ca6e21163 (diff) | |
download | scala-7337db9c59daeac26e81e22cfea4f7d8b43a0747.tar.gz scala-7337db9c59daeac26e81e22cfea4f7d8b43a0747.tar.bz2 scala-7337db9c59daeac26e81e22cfea4f7d8b43a0747.zip |
allow using named / default arguments in self- ...
allow using named / default arguments in self- and super constructor
calls. fixes #2050 and #2052.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/AddInterfaces.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala | 18 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala index f009f69f4a..ccae9578b9 100644 --- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala +++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala @@ -294,7 +294,8 @@ abstract class AddInterfaces extends InfoTransform { } (tree: @unchecked) match { case Block(stats, expr) => - val (presuper, supercall :: rest) = stats span (_.symbol.hasFlag(PRESUPER)) + // needs `hasSymbol' check because `supercall' could be a block (named / default args) + val (presuper, supercall :: rest) = stats span (t => t.hasSymbol && t.symbol.hasFlag(PRESUPER)) //assert(supercall.symbol.isClassConstructor, supercall) treeCopy.Block(tree, presuper ::: (supercall :: mixinConstructorCalls ::: rest), expr) } diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index b104bed2c7..0ede740b00 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -179,13 +179,23 @@ trait NamesDefaults { self: Analyzer => assert(treeInfo.isPureExpr(qual), qual) blockWithoutQualifier(baseFun1, defaultQual) + // super constructor calls + + case Select(Super(_, _), _) if isConstr => + blockWithoutQualifier(baseFun1, None) + + // self constructor calls (in secondary constructors) + + case Select(qual, name) if isConstr => + assert(treeInfo.isPureExpr(qual), qual) + blockWithoutQualifier(baseFun1, None) + // other method calls case Ident(_) => blockWithoutQualifier(baseFun1, None) case Select(qual, name) => - assert(!isConstr, baseFun1) if (treeInfo.isPureExpr(qual)) blockWithoutQualifier(baseFun1, Some(qual.duplicate)) else @@ -224,11 +234,7 @@ trait NamesDefaults { self: Analyzer => } // begin transform - if (treeInfo.isSelfConstrCall(tree)) { - errorTree(tree, "using named or default arguments in a self constructor call is not allowed") - } else if (treeInfo.isSuperConstrCall(tree)) { - errorTree(tree, "using named or default arguments in a super constructor call is not allowed") - } else if (isNamedApplyBlock(tree)) { + if (isNamedApplyBlock(tree)) { context.namedApplyBlockInfo.get._1 } else tree match { // we know that Apply(Apply(...)) can only be an application of a curried method; |