diff options
author | Paul Phillips <paulp@improving.org> | 2012-05-03 09:30:16 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-05-03 10:53:02 -0700 |
commit | ca74659bb06611b87474ffe2fd17b131cd3d34b0 (patch) | |
tree | be3664d400a0b534c1936555b660264ca4c9931d | |
parent | 8068e1208466ab17af40c2670230ba5ac9704e0c (diff) | |
download | scala-ca74659bb06611b87474ffe2fd17b131cd3d34b0.tar.gz scala-ca74659bb06611b87474ffe2fd17b131cd3d34b0.tar.bz2 scala-ca74659bb06611b87474ffe2fd17b131cd3d34b0.zip |
Hardening implicit classes.
Closes SI-5728.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 10 | ||||
-rw-r--r-- | test/files/neg/t5728.check | 4 | ||||
-rw-r--r-- | test/files/neg/t5728.scala | 7 |
3 files changed, 18 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index e4296774a1..6620ef7347 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -608,11 +608,12 @@ trait Namers extends MethodSynthesis { def enterClassDef(tree: ClassDef) { val ClassDef(mods, name, tparams, impl) = tree + val primaryConstructorArity = treeInfo.firstConstructorArgs(impl.body).size tree.symbol = enterClassSymbol(tree) tree.symbol setInfo completerOf(tree) if (mods.isCase) { - if (treeInfo.firstConstructorArgs(impl.body).size > MaxFunctionArity) + if (primaryConstructorArity > MaxFunctionArity) MaxParametersCaseClassError(tree) val m = ensureCompanionObject(tree, caseModuleDef) @@ -636,8 +637,11 @@ trait Namers extends MethodSynthesis { // Suggested location only. if (mods.isImplicit) { - log("enter implicit wrapper "+tree+", owner = "+owner) - enterImplicitWrapper(tree) + if (primaryConstructorArity == 1) { + log("enter implicit wrapper "+tree+", owner = "+owner) + enterImplicitWrapper(tree) + } + else context.unit.error(tree.pos, "implicit classes must accept exactly one primary constructor parameter") } } diff --git a/test/files/neg/t5728.check b/test/files/neg/t5728.check new file mode 100644 index 0000000000..14f9c42ae0 --- /dev/null +++ b/test/files/neg/t5728.check @@ -0,0 +1,4 @@ +t5728.scala:3: error: implicit classes must accept exactly one primary constructor parameter + implicit class Foo + ^ +one error found diff --git a/test/files/neg/t5728.scala b/test/files/neg/t5728.scala new file mode 100644 index 0000000000..99337d06d4 --- /dev/null +++ b/test/files/neg/t5728.scala @@ -0,0 +1,7 @@ +object Test { + + implicit class Foo + + implicit def Foo = new Foo + +} |