diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2010-07-13 07:14:37 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2010-07-13 07:14:37 +0000 |
commit | 78d96afa56e51c7ef2ed317ca96b4c4e345ba105 (patch) | |
tree | bcc7f0ff554f5db3cb78cd5e154551594e367947 /src/compiler/scala/tools/nsc/typechecker/Typers.scala | |
parent | ada6cccb3587d6d51703e385faba85d8694c9ccd (diff) | |
download | scala-78d96afa56e51c7ef2ed317ca96b4c4e345ba105.tar.gz scala-78d96afa56e51c7ef2ed317ca96b4c4e345ba105.tar.bz2 scala-78d96afa56e51c7ef2ed317ca96b4c4e345ba105.zip |
close #3648 (again).
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 7d6139c52b..043c41fc10 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2183,6 +2183,17 @@ trait Typers { self: Analyzer => def isNamedApplyBlock(tree: Tree) = context.namedApplyBlockInfo exists (_._1 == tree) + def callToCompanionConstr(context: Context, calledFun: Symbol) = { + if (calledFun.isConstructor) { + val methCtx = context.enclMethod + if (methCtx != NoContext) { + val contextFun = methCtx.tree.symbol + contextFun.isPrimaryConstructor && contextFun.owner.isModuleClass && + companionModuleOf(calledFun.owner, context).moduleClass == contextFun.owner + } else false + } else false + } + def doTypedApply(tree: Tree, fun0: Tree, args: List[Tree], mode: Int, pt: Type): Tree = { var fun = fun0 if (fun.hasSymbol && (fun.symbol hasFlag OVERLOADED)) { @@ -2320,7 +2331,10 @@ trait Typers { self: Analyzer => case _ => false } val (allArgs, missing) = addDefaults(args, qual, targs, previousArgss, params, fun.pos.focus, context) - if (allArgs.length == formals.length) { + val funSym = fun1 match { case Block(_, expr) => expr.symbol } + if (allArgs.length != args.length && callToCompanionConstr(context, funSym)) { + errorTree(tree, "module extending its companion class cannot use default constructor arguments") + } else if (allArgs.length == formals.length) { // useful when a default doesn't match parameter type, e.g. def f[T](x:T="a"); f[Int]() val note = "Error occurred in an application involving default arguments." if (!(context.diagnostic contains note)) context.diagnostic = note :: context.diagnostic |