Skip to content

Commit df8d21a

Browse files
committed
SI-9074 Fix generic substitution with package objects, overloading
Takes a leaf out of dotty's book [1] and makes `asSeenFrom` tranaparently change the prefix from the package class to the package object when needed. This fixes generic subsitution during overload resolution, as reported in SI-9074. It also lets us remove the fix for SI-6225. [1] scala/scala3#282
1 parent 333dfbd commit df8d21a

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -807,12 +807,7 @@ trait Contexts { self: Analyzer =>
807807
val qual = imp.qual
808808

809809
val qualSym = qual.tpe.typeSymbol
810-
val pre =
811-
if (qualSym.isPackageClass)
812-
// SI-6225 important if the imported symbol is inherited by the the package object.
813-
qualSym.packageObject.typeOfThis
814-
else
815-
qual.tpe
810+
val pre = qual.tpe
816811
def collect(sels: List[ImportSelector]): List[ImplicitInfo] = sels match {
817812
case List() =>
818813
List()

src/reflect/scala/reflect/internal/tpe/TypeMaps.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,10 @@ private[internal] trait TypeMaps {
433433
(pre eq NoType) || (pre eq NoPrefix) || !isPossiblePrefix(clazz)
434434
)
435435

436-
def newAsSeenFromMap(pre: Type, clazz: Symbol): AsSeenFromMap =
437-
new AsSeenFromMap(pre, clazz)
436+
def newAsSeenFromMap(pre: Type, clazz: Symbol): AsSeenFromMap = {
437+
val pre1 = if (pre.termSymbolDirect.hasPackageFlag && !clazz.hasPackageFlag) pre.packageObject.typeOfThis else pre
438+
new AsSeenFromMap(pre1, clazz)
439+
}
438440

439441
/** A map to compute the asSeenFrom method.
440442
*/

test/files/pos/t9074.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package blam {
2+
3+
package foo {
4+
5+
trait F[T] {
6+
def f(d: Double, t: T): T = ???
7+
def f(d: Int, t: T): T = ???
8+
def f(d: String, t: T): T = ???
9+
10+
def g[A](a: T): T = ???
11+
def g(a: Int) = ???
12+
}
13+
}
14+
15+
package object foo extends foo.F[Double] {
16+
override def f(d: Double, t: Double): Double = ???
17+
}
18+
}
19+
20+
object Test {
21+
import blam._
22+
foo.f("3", 4.0)
23+
foo.g[Any](1d) : Double
24+
}

0 commit comments

Comments
 (0)