summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-05-03 20:58:38 -0700
committerPaul Phillips <paulp@improving.org>2012-05-03 21:35:53 -0700
commit5c84dc85bf1a19aedf1ad96c9b8007c1368dd79f (patch)
tree43efea9054c3c8fc23caf74fd4816903c1f00557 /src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
parent043ce6d0565c9d5d960d4c09926014d51b9c5b70 (diff)
downloadscala-5c84dc85bf1a19aedf1ad96c9b8007c1368dd79f.tar.gz
scala-5c84dc85bf1a19aedf1ad96c9b8007c1368dd79f.tar.bz2
scala-5c84dc85bf1a19aedf1ad96c9b8007c1368dd79f.zip
Fix for implicit class / value class collision.
New this week, on SCALA. Implicit class: "Spin me up an implicit method with my name." Value class: "I need a companion object, pronto." Narrator: "All was well with this arrangement... UNTIL." What happens when these two wacky SIPs get together in the very same class? You'll laugh until, eventually, you cry! Weeknights at 9:30pm, only on SCALA. Closes SI-5667.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
index 7dc105690c..cf94f7d4d6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
@@ -234,11 +234,16 @@ trait MethodSynthesis {
// TODO: need to shuffle annotations between wrapper and class.
val wrapper = ImplicitClassWrapper(cd)
val meth = wrapper.derivedSym
- val mdef = context.unit.synthetics(meth)
- context.unit.synthetics -= meth
- meth setAnnotations deriveAnnotations(annotations, MethodTargetClass, false)
- cd.symbol setAnnotations deriveAnnotations(annotations, ClassTargetClass, true)
- List(cd, mdef)
+ context.unit.synthetics get meth match {
+ case Some(mdef) =>
+ context.unit.synthetics -= meth
+ meth setAnnotations deriveAnnotations(annotations, MethodTargetClass, false)
+ cd.symbol setAnnotations deriveAnnotations(annotations, ClassTargetClass, true)
+ List(cd, mdef)
+ case _ =>
+ // Shouldn't happen, but let's give ourselves a reasonable error when it does
+ abort("No synthetics for " + meth + ": synthetics contains " + context.unit.synthetics.keys.mkString(", "))
+ }
case _ =>
List(stat)
}
@@ -373,7 +378,9 @@ trait MethodSynthesis {
def completer(sym: Symbol): Type = ??? // not needed
def createAndEnterSymbol(): Symbol = enterSyntheticSym(derivedTree)
def derivedSym: Symbol = {
- val result = enclClass.info decl name
+ // Only methods will do! Don't want to pick up any stray
+ // companion objects of the same name.
+ val result = enclClass.info decl name suchThat (_.isMethod)
assert(result != NoSymbol, "not found: "+name+" in "+enclClass+" "+enclClass.info.decls)
result
}