Skip to content

Commit

Permalink
Fix scala3doc Hierarchy test
Browse files Browse the repository at this point in the history
Also, drop code that's no longer needed since we made Matchable an empty trait
  • Loading branch information
odersky committed Dec 8, 2020
1 parent 2009dc3 commit ac2ad69
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CommunityBuildTestA extends CommunityBuildTest:
@Test def ujson = projects.ujson.run()
@Test def upickle = projects.upickle.run()
@Test def utest = projects.utest.run()
@Test def zio = projects.zio.run()
@Test def zio = projects.zio.run()
end CommunityBuildTestA

@Category(Array(classOf[TestCategory]))
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
else
singleton(tp).equal(tree)
case _ =>
tree.ensureConforms(defn.MatchableType)
.select(defn.Any_isInstanceOf)
.appliedToType(tp)
tree.select(defn.Any_isInstanceOf).appliedToType(tp)
}

/** tree.asInstanceOf[`tp`] */
Expand Down
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ class Definitions {
Final,
bounds = TypeBounds.lower(AnyClass.thisType))

def AnyMethods: List[TermSymbol] = List(Any_==, Any_!=, Any_equals, Any_hashCode, Any_getClass,
Any_toString, Any_##, Any_isInstanceOf, Any_asInstanceOf, Any_typeTest, Any_typeCast)
def AnyMethods: List[TermSymbol] = List(Any_==, Any_!=, Any_equals, Any_hashCode,
Any_toString, Any_##, Any_getClass, Any_isInstanceOf, Any_asInstanceOf, Any_typeTest, Any_typeCast)

@tu lazy val ObjectClass: ClassSymbol = {
val cls = requiredClass("java.lang.Object")
Expand Down Expand Up @@ -436,7 +436,7 @@ class Definitions {
def ObjectMethods: List[TermSymbol] = List(Object_eq, Object_ne, Object_synchronized, Object_clone,
Object_finalize, Object_notify, Object_notifyAll, Object_wait, Object_waitL, Object_waitLI)

/** Methods in Object, Matchable, and Any that do not have a side effect */
/** Methods in Object and Any that do not have a side effect */
@tu lazy val pureMethods: List[TermSymbol] = List(Any_==, Any_!=, Any_equals, Any_hashCode,
Any_toString, Any_##, Any_getClass, Any_isInstanceOf, Any_typeTest, Object_eq, Object_ne)

Expand Down Expand Up @@ -1174,7 +1174,6 @@ class Definitions {

// ----- Symbol sets ---------------------------------------------------

@tu lazy val AnyOrMatchable: Set[Symbol] = Set(AnyClass, MatchableClass)
@tu lazy val topClasses: Set[Symbol] = Set(AnyClass, MatchableClass, ObjectClass, AnyValClass)

@tu lazy val AbstractFunctionType: Array[TypeRef] = mkArityArray("scala.runtime.AbstractFunction", MaxImplementedFunctionArity, 0)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ object SymDenotations {
def matchNullaryLoosely(using Context): Boolean = {
def test(sym: Symbol) =
sym.is(JavaDefined) ||
defn.AnyOrMatchable.contains(sym.owner) ||
sym.owner == defn.AnyClass ||
sym == defn.Object_clone ||
sym.owner.is(Scala2x)
this.exists && (test(symbol) || allOverriddenSymbols.exists(test))
Expand Down
9 changes: 3 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ class Erasure extends Phase with DenotTransformer {
// After erasure, all former Any members are now Object members
val ClassInfo(pre, _, ps, decls, selfInfo) = ref.info
val extendedScope = decls.cloneScope
def copyDecls(from: ClassSymbol) =
for decl <- from.classInfo.decls do
if !decl.isConstructor then extendedScope.enter(decl)
copyDecls(defn.AnyClass)
copyDecls(defn.MatchableClass)
for decl <- defn.AnyClass.classInfo.decls do
if !decl.isConstructor then extendedScope.enter(decl)
ref.copySymDenotation(
info = transformInfo(ref.symbol,
ClassInfo(pre, defn.ObjectClass, ps, extendedScope, selfInfo))
Expand All @@ -79,7 +76,7 @@ class Erasure extends Phase with DenotTransformer {
defn.ObjectClass.primaryConstructor
else oldSymbol
val oldOwner = ref.owner
val newOwner = if defn.AnyOrMatchable.contains(oldOwner) then defn.ObjectClass else oldOwner
val newOwner = if oldOwner == defn.AnyClass then defn.ObjectClass else oldOwner
val oldName = ref.name
val newName = ref.targetName
val oldInfo = ref.info
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ trait Checking {
val psuper = parent.superClass
val csuper = cls.superClass
val ok = csuper.derivesFrom(psuper) ||
parent.is(JavaDefined) && defn.AnyOrMatchable.contains(csuper) &&
parent.is(JavaDefined) && csuper == defn.AnyClass &&
(parent == defn.JavaSerializableClass || parent == defn.ComparableClass)
if (!ok)
report.error(em"illegal trait inheritance: super$csuper does not derive from $parent's super$psuper", pos)
Expand Down
24 changes: 15 additions & 9 deletions scala3doc/test/dotty/dokka/diagram/HierarchyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
AfterDocumentablesTransformation { m =>
m.visitMembers { x =>
if (x.getName == "C1") {
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "Object"), x.getParentsAsStrings)
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "Matchable", "Object"), x.getParentsAsStrings)
assertEquals(List("B1", "B2", "B3"), x.getDirectParentsAsStrings)
assertEquals(List("E1", "E2"), x.getKnownChildrenAsStrings)
val graph = MemberExtension.getFrom(x).map(_.graph)
val graph = MemberExtension.getFrom(x).map(_.graph)
assertTrue("Graph is empty!", graph.isDefined)
assertEquals(
Set(
"Object" -> "Matchable",
"Matchable" -> "Any",
"Object" -> "Any",
"A1" -> "Object",
"A2[Int]" -> "Object",
Expand All @@ -42,15 +44,15 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
)
}
if (x.getName == "E2") {
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3", "Object"), x.getParentsAsStrings)
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3", "Matchable", "Object"), x.getParentsAsStrings)
assertEquals(List("C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3"), x.getDirectParentsAsStrings)
assertEquals(List.empty, x.getKnownChildrenAsStrings)
val graph = MemberExtension.getFrom(x).map(_.graph)
val graph = MemberExtension.getFrom(x).map(_.graph)
assertTrue("Graph is empty!", graph.isDefined)
assertEquals(
Set(
"Object" -> "Any",
// "A1" -> "Object", // These are not applicable beacuase of bug and its workaround
// "A1" -> "Object", // These are not applicable beacuase of bug and its workaround
// "A2[Int]" -> "Object", // More info at ClassLikeSupport.scala:37
// "A3[Int, String]" -> "Object",
// "B1" -> "Object",
Expand All @@ -65,6 +67,8 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
// "C1[Int, Boolean, Any]" -> "B1",
// "C1[Int, Boolean, Any]" -> "B2",
// "C1[Int, Boolean, Any]" -> "B3",
"Object" -> "Matchable",
"Matchable" -> "Any",
"E2" -> "D2[Int, Boolean]",
"E2" -> "D3",
"D2[Int, Boolean]" -> "Object",
Expand All @@ -75,16 +79,18 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
)
}
if (x.getName == "A2") {
assertEquals(List("Any", "Object"), x.getParentsAsStrings)
assertEquals(List("Any", "Matchable", "Object"), x.getParentsAsStrings)
assertEquals(List.empty, x.getDirectParentsAsStrings)
assertEquals(List("B2", "B3", "C1[A, B, C]", "E1", "E2"), x.getKnownChildrenAsStrings)
val graph = MemberExtension.getFrom(x).map(_.graph)
val graph = MemberExtension.getFrom(x).map(_.graph)
assertTrue("Graph is empty!", graph.isDefined)
assertEquals(
Set(
"Object" -> "Matchable",
"Matchable" -> "Any",
"Object" -> "Any",
"A2[T]" -> "Object",
"B2" -> "A2[T]", // These are not actually true, becuase we lose information about hierarchy in subtypes and their possible mapping to supertypes other that that type itself, e. g. linking to `Object`
"B2" -> "A2[T]", // These are not actually true, becuase we lose information about hierarchy in subtypes and their possible mapping to supertypes other that that type itself, e. g. linking to `Object`
"B3" -> "A2[T]",
"C1[A, B, C]" -> "A2[T]",
"E1" -> "A2[T]",
Expand All @@ -95,4 +101,4 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
}
}
}
)
)

0 comments on commit ac2ad69

Please sign in to comment.