Skip to content

Commit

Permalink
Fix superType of SuperType
Browse files Browse the repository at this point in the history
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
  • Loading branch information
odersky committed May 24, 2023
1 parent aa74ac4 commit 810a396
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3005,7 +3005,8 @@ object Types {
abstract case class SuperType(thistpe: Type, supertpe: Type) extends CachedProxyType with SingletonType {
override def underlying(using Context): Type = supertpe
override def superType(using Context): Type =
thistpe.baseType(supertpe.typeSymbol)
if supertpe.typeSymbol.exists then thistpe.baseType(supertpe.typeSymbol)
else super.superType
def derivedSuperType(thistpe: Type, supertpe: Type)(using Context): Type =
if ((thistpe eq this.thistpe) && (supertpe eq this.supertpe)) this
else SuperType(thistpe, supertpe)
Expand Down
17 changes: 17 additions & 0 deletions tests/run/i17555.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Root {
override def toString() = "Root"
}
trait A extends Root with B { }
trait B {
override def toString() = "B"
}
case class C() extends A {
override def toString() = super.toString()
}
class D() extends A, Serializable {
override def toString() = super.toString()
}

@main def Test =
println(C())
println(D())

0 comments on commit 810a396

Please sign in to comment.