Skip to content

Commit f2d5539

Browse files
authored
Backport "Fix superType of SuperType" to LTS (#18942)
Backports #17574 to the LTS branch. PR submitted by the release tooling.
2 parents 7fbe032 + 548513d commit f2d5539

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,8 @@ object Types {
30373037
abstract case class SuperType(thistpe: Type, supertpe: Type) extends CachedProxyType with SingletonType {
30383038
override def underlying(using Context): Type = supertpe
30393039
override def superType(using Context): Type =
3040-
thistpe.baseType(supertpe.typeSymbol)
3040+
if supertpe.typeSymbol.exists then thistpe.baseType(supertpe.typeSymbol)
3041+
else super.superType
30413042
def derivedSuperType(thistpe: Type, supertpe: Type)(using Context): Type =
30423043
if ((thistpe eq this.thistpe) && (supertpe eq this.supertpe)) this
30433044
else SuperType(thistpe, supertpe)

tests/run/i17555.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Root {
2+
override def toString() = "Root"
3+
}
4+
trait A extends Root with B { }
5+
trait B {
6+
override def toString() = "B"
7+
}
8+
case class C() extends A {
9+
override def toString() = super.toString()
10+
}
11+
class D() extends A, Serializable {
12+
override def toString() = super.toString()
13+
}
14+
15+
@main def Test =
16+
assert(C().toString == "B")
17+
assert(D().toString == "B")

0 commit comments

Comments
 (0)