diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 13 | ||||
-rw-r--r-- | test/files/neg/t6227.check | 4 | ||||
-rw-r--r-- | test/files/neg/t6227.scala | 6 | ||||
-rw-r--r-- | test/files/pos/t5667.scala | 2 |
4 files changed, 23 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 77d1260564..adced9d8c9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -192,6 +192,10 @@ trait Namers extends MethodSynthesis { if (!allowsOverload(sym)) { val prev = scope.lookupEntry(sym.name) if ((prev ne null) && prev.owner == scope && conflict(sym, prev.sym)) { + if (sym.isSynthetic || prev.sym.isSynthetic) { + handleSyntheticNameConflict(sym, prev.sym) + handleSyntheticNameConflict(prev.sym, sym) + } DoubleDefError(sym, prev.sym) sym setInfo ErrorType scope unlink prev.sym // let them co-exist... @@ -202,6 +206,14 @@ trait Namers extends MethodSynthesis { scope enter sym } + /** Logic to handle name conflicts of synthetically generated symbols + * We handle right now: t6227 + */ + def handleSyntheticNameConflict(sym1: Symbol, sym2: Symbol) = { + if (sym1.isImplicit && sym1.isMethod && sym2.isModule && sym2.companionClass.isCaseClass) + validate(sym2.companionClass) + } + def enterSym(tree: Tree): Context = { def dispatch() = { var returnContext = this.context @@ -1390,6 +1402,7 @@ trait Namers extends MethodSynthesis { fail(ImplicitAtToplevel) } if (sym.isClass) { + checkNoConflict(IMPLICIT, CASE) if (sym.isAnyOverride && !sym.hasFlag(TRAIT)) fail(OverrideClass) } else { diff --git a/test/files/neg/t6227.check b/test/files/neg/t6227.check new file mode 100644 index 0000000000..5e3c636712 --- /dev/null +++ b/test/files/neg/t6227.check @@ -0,0 +1,4 @@ +t6227.scala:2: error: illegal combination of modifiers: implicit and case for: class IntOps + implicit case class IntOps( i: Int ) { + ^ +one error found diff --git a/test/files/neg/t6227.scala b/test/files/neg/t6227.scala new file mode 100644 index 0000000000..46416839d1 --- /dev/null +++ b/test/files/neg/t6227.scala @@ -0,0 +1,6 @@ +object Test { + implicit case class IntOps( i: Int ) { + def twice = i * 2 + } +} + diff --git a/test/files/pos/t5667.scala b/test/files/pos/t5667.scala index 513de5b663..353eec93d6 100644 --- a/test/files/pos/t5667.scala +++ b/test/files/pos/t5667.scala @@ -1,6 +1,4 @@ object Main { implicit class C(val s: String) extends AnyVal implicit class C2(val s: String) extends AnyRef - - implicit case class Foo(i: Int) } |