diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-26 23:18:34 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-26 23:18:34 -0700 |
commit | 0aaf59149871f817a67c1fefcc3b0457fcb5e4fc (patch) | |
tree | 6796671a9632e563c24541c71a8d403a4918fbc7 | |
parent | 738405a9aae7c117d3974c05269f6bbd2ac2ae3e (diff) | |
parent | d882ec053c9a70d29e668bc80bb3f1aa830c0281 (diff) | |
download | scala-0aaf59149871f817a67c1fefcc3b0457fcb5e4fc.tar.gz scala-0aaf59149871f817a67c1fefcc3b0457fcb5e4fc.tar.bz2 scala-0aaf59149871f817a67c1fefcc3b0457fcb5e4fc.zip |
Merge pull request #2979 from retronym/ticket/7870
SI-7870 Detect default getter clashes in constructors
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 8 | ||||
-rw-r--r-- | test/files/neg/t7870.check | 4 | ||||
-rw-r--r-- | test/files/neg/t7870.scala | 3 |
3 files changed, 12 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 32e908e03b..61759a9f00 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -121,13 +121,13 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans var checkedCombinations = Set[List[Type]]() // only one overloaded alternative is allowed to define default arguments - private def checkOverloadedRestrictions(clazz: Symbol): Unit = { + private def checkOverloadedRestrictions(clazz: Symbol, defaultClass: Symbol): Unit = { // Using the default getters (such as methodName$default$1) as a cheap way of // finding methods with default parameters. This way, we can limit the members to // those with the DEFAULTPARAM flag, and infer the methods. Looking for the methods // directly requires inspecting the parameter list of every one. That modification // shaved 95% off the time spent in this method. - val defaultGetters = clazz.info.findMembers(0L, DEFAULTPARAM) + val defaultGetters = defaultClass.info.findMembers(0L, DEFAULTPARAM) val defaultMethodNames = defaultGetters map (sym => nme.defaultGetterToMethod(sym.name)) defaultMethodNames.toList.distinct foreach { name => @@ -1638,7 +1638,9 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans case Template(parents, self, body) => localTyper = localTyper.atOwner(tree, currentOwner) validateBaseTypes(currentOwner) - checkOverloadedRestrictions(currentOwner) + checkOverloadedRestrictions(currentOwner, currentOwner) + // SI-7870 default getters for constructors live in the companion module + checkOverloadedRestrictions(currentOwner, currentOwner.companionModule) val bridges = addVarargBridges(currentOwner) checkAllOverrides(currentOwner) checkAnyValSubclass(currentOwner) diff --git a/test/files/neg/t7870.check b/test/files/neg/t7870.check new file mode 100644 index 0000000000..d9db911ac1 --- /dev/null +++ b/test/files/neg/t7870.check @@ -0,0 +1,4 @@ +t7870.scala:1: error: in class C, multiple overloaded alternatives of constructor C define default arguments. +class C(a: Int = 0, b: Any) { + ^ +one error found diff --git a/test/files/neg/t7870.scala b/test/files/neg/t7870.scala new file mode 100644 index 0000000000..5d48d43b3a --- /dev/null +++ b/test/files/neg/t7870.scala @@ -0,0 +1,3 @@ +class C(a: Int = 0, b: Any) { + def this(a: Int = 0) = this(???, ???) +} |