Skip to content

Commit

Permalink
Fix superType of SuperType (#17574)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
odersky authored May 25, 2023
2 parents 62479c9 + d1a7346 commit acb3dba
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 @@ -3026,7 +3026,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 =
assert(C().toString == "B")
assert(D().toString == "B")

0 comments on commit acb3dba

Please sign in to comment.