Skip to content

Commit 810a396

Browse files
committed
Fix superType of SuperType
I am not quite sure abput he previous definition of superType in SuperType. I believe it's probably needed for something. But it's clearly wrong if the `supertpe` argument does not have a symbol. We now fall back to the default `superType = underlying` in this case. Fixes $17555
1 parent aa74ac4 commit 810a396

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
@@ -3005,7 +3005,8 @@ object Types {
30053005
abstract case class SuperType(thistpe: Type, supertpe: Type) extends CachedProxyType with SingletonType {
30063006
override def underlying(using Context): Type = supertpe
30073007
override def superType(using Context): Type =
3008-
thistpe.baseType(supertpe.typeSymbol)
3008+
if supertpe.typeSymbol.exists then thistpe.baseType(supertpe.typeSymbol)
3009+
else super.superType
30093010
def derivedSuperType(thistpe: Type, supertpe: Type)(using Context): Type =
30103011
if ((thistpe eq this.thistpe) && (supertpe eq this.supertpe)) this
30113012
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+
println(C())
17+
println(D())

0 commit comments

Comments
 (0)