Skip to content

Commit 451cab9

Browse files
committed
SI-6225 Fix import of inherited package object implicits
The prefix in the ImplicitInfo must be com.acme.`package`.type, rather than com.acme.
1 parent 6537d79 commit 451cab9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,14 @@ trait Contexts { self: Analyzer =>
644644
new ImplicitInfo(sym.name, pre, sym)
645645

646646
private def collectImplicitImports(imp: ImportInfo): List[ImplicitInfo] = {
647-
val pre = imp.qual.tpe
647+
val qual = imp.qual
648+
649+
val pre =
650+
if (qual.tpe.typeSymbol.isPackageClass)
651+
// SI-6225 important if the imported symbol is inherited by the the package object.
652+
singleType(qual.tpe, qual.tpe member nme.PACKAGE)
653+
else
654+
qual.tpe
648655
def collect(sels: List[ImportSelector]): List[ImplicitInfo] = sels match {
649656
case List() =>
650657
List()

test/files/pos/t6225.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
package library.x {
3+
class X {
4+
class Foo
5+
implicit val foo: Foo = new Foo
6+
}
7+
}
8+
package library {
9+
package object y extends library.x.X
10+
}
11+
12+
object ko {
13+
import library.y.{Foo, foo}
14+
implicitly[Foo]
15+
}
16+
17+
object ko2 {
18+
import library.y._
19+
implicitly[Foo]
20+
}

0 commit comments

Comments
 (0)