Skip to content

Commit cb37548

Browse files
committed
Symbol substutition must consider ClassInfoType#parents
An upcoming change to uncurry, in which I plan to make substitution of `lambda params -> apply method params` requires that I first to fix a problem in symbol substition. This situation can arise when the body of this definition: def owner1(a: A) = { class C extends M[a.B] } is transplanted into a new owner that has a different symbol for `a`. I speculated that value classes might also be prone to the fact that symbol substitution neglected `ClassInfoType#parents`. We can test change with Value Classes: Partial Functions that are dependent on value class param type used to fail with a spurious overriding error, now they work correctly.
1 parent d7d63e9 commit cb37548

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,12 @@ private[internal] trait TypeMaps {
717717
else appliedType(tcon.typeConstructor, args)
718718
case SingleType(NoPrefix, sym) =>
719719
substFor(sym)
720+
case ClassInfoType(parents, decls, sym) =>
721+
val parents1 = parents mapConserve this
722+
// We don't touch decls here; they will be touched when an enclosing TreeSubstitutor
723+
// transforms the tree that defines them.
724+
if (parents1 eq parents) tp
725+
else ClassInfoType(parents1, decls, sym)
720726
case _ =>
721727
tp
722728
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class C
2+
class A { class C }
3+
4+
object Test {
5+
def main(args: Array[String]) {
6+
val a = new A
7+
8+
new VC("").foo(a)
9+
}
10+
}
11+
12+
class VC(val a: Any) extends AnyVal {
13+
def foo(a: A) = {
14+
val pf: PartialFunction[a.C, Any] = { case x => x }
15+
(pf: PartialFunction[Null, Any]).isDefinedAt(null)
16+
}
17+
}
18+
19+
// 2.11.0-M6
20+
// test/files/run/value-class-partial-func-depmet.scala:14: error: overriding method applyOrElse in trait PartialFunction of type [A1 <: a.C, B1 >: Any](x: A1, default: A1 => B1)B1;
21+
// method applyOrElse has incompatible type
22+
// val pf: PartialFunction[a.C, Any] = { case x => x }
23+
// ^
24+
// one error found

0 commit comments

Comments
 (0)