Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix superType of SuperType #17574

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 =
assert(C().toString == "B")
assert(D().toString == "B")