Skip to content

The base type sequence of ThisType is inconsistent #166

Open
@retronym

Description

@retronym

Consider:

class ThisType {
    // TODO: should
    override def baseTypeSeq: BaseTypeSeq = {
      if (Statistics.canEnable) Statistics.incCounter(singletonBaseTypeSeqCount)
      val elem0 = if (sym.hasSelfType) SingleType(NoPrefix, sym.thisSym) else this
      underlying.baseTypeSeq prepend elem0
    }

Motivated by:

  @Test
  def thisTypeBaseTypeSeq(): Unit = {
    import rootMirror.EmptyPackageClass
    // trait T { self: U => }; trait U extends T
    val UClass = EmptyPackageClass.newClass("U")
    val TClass = EmptyPackageClass.newClass("T")
    TClass.setInfo(ClassInfoType(ObjectTpe :: Nil, newScope, TClass))
    UClass.setInfo(ClassInfoType(TClass.tpeHK :: Nil, newScope, UClass))
    TClass.typeOfThis = UClass.tpeHK
    val bts = TClass.thisType.baseTypeSeq
    println(bts)
    assertEquals(1, TClass.thisType.baseTypeIndex(UClass))
  }

The workaround is currently is to use widen.baseTypeIndex or .widen.typeSymbol.isSubclass in AsSeenFrom. We could eliminate the workaround if we fixed the problem at its core.

It would be interesting to add logging to baseTypeIndex, isSubclass etc to find potential bugs. We could validate the base type sequence that we're inspecting.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions