From 7337db9c59daeac26e81e22cfea4f7d8b43a0747 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Mon, 15 Jun 2009 15:03:20 +0000 Subject: allow using named / default arguments in self- ... allow using named / default arguments in self- and super constructor calls. fixes #2050 and #2052. --- .../scala/tools/nsc/transform/AddInterfaces.scala | 3 ++- .../scala/tools/nsc/typechecker/NamesDefaults.scala | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/compiler') 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; -- cgit v1.2.3