From 35dbc88841e25ca70b68ac78d5b3e4ab0f23153c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 29 Aug 2012 12:01:41 +0200 Subject: Closes SI-6227 I added some general hook where one can add validation code before a name conflict involving at least one implicit symbol is reported. --- src/compiler/scala/tools/nsc/typechecker/Namers.scala | 13 +++++++++++++ test/files/neg/t6227.scala | 6 ++++++ 2 files changed, 19 insertions(+) create mode 100644 test/files/neg/t6227.scala 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.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 + } +} + -- cgit v1.2.3