Skip to content

Commit acb3dba

Browse files
authored
Fix superType of SuperType (#17574)
I am not quite sure about 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 ``` def superType = underlying ``` in this case. Fixes #17555
2 parents 62479c9 + d1a7346 commit acb3dba

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
@@ -3026,7 +3026,8 @@ object Types {
30263026
abstract case class SuperType(thistpe: Type, supertpe: Type) extends CachedProxyType with SingletonType {
30273027
override def underlying(using Context): Type = supertpe
30283028
override def superType(using Context): Type =
3029-
thistpe.baseType(supertpe.typeSymbol)
3029+
if supertpe.typeSymbol.exists then thistpe.baseType(supertpe.typeSymbol)
3030+
else super.superType
30303031
def derivedSuperType(thistpe: Type, supertpe: Type)(using Context): Type =
30313032
if ((thistpe eq this.thistpe) && (supertpe eq this.supertpe)) this
30323033
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)