Permalink
Browse files

SI-5877 Support implicit classes in package objects

This used to crash, as both the package and the package object
had the synthetic method in `decls`, and the typer tried to add
the tree to both places.

Now, synthetics in the package object are excluded from the pacakge
itself.
  • Loading branch information...
retronym committed Dec 4, 2012
1 parent 65c1ae5 commit 96e5c402a6d48de699fe48cd0eaf33d0575eaac7
@@ -2828,7 +2828,10 @@ trait Typers extends Modes with Adaptations with Tags {
var moreToAdd = true
while (moreToAdd) {
val initElems = scope.elems
- for (sym <- scope)
+ // SI-5877 The decls of a package include decls of the package object. But we don't want to add
+ // the corresponding synthetics to the package itself.
+ def isPackageObjectSym(sym: Symbol) = sym.owner.isPackageObjectClass && context.owner.isPackage
+ for (sym <- scope if !isPackageObjectSym(sym))
for (tree <- context.unit.synthetics get sym) {
newStats += typedStat(tree) // might add even more synthetics to the scope
context.unit.synthetics -= sym
View
@@ -0,0 +1,14 @@
+package foo {
+ class Foo
+
+ object Test {
+ new Foo().huzzah
+ }
+}
+
+package object foo {
+ // Crasher: No synthetics for method PimpedFoo2: synthetics contains
+ implicit class PimpedFoo2(value: Foo) {
+ def huzzah = ""
+ }
+}
@@ -0,0 +1,13 @@
+package foo
+
+class Foo
+
+object Test {
+ new Foo().huzzah
+}
+
+object `package` {
+ implicit class PimpedFoo2(value: Foo) {
+ def huzzah = ""
+ }
+}

0 comments on commit 96e5c40

Please sign in to comment.