Skip to content

Commit ac2ad69

Browse files
committed
Fix scala3doc Hierarchy test
Also, drop code that's no longer needed since we made Matchable an empty trait
1 parent 2009dc3 commit ac2ad69

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CommunityBuildTestA extends CommunityBuildTest:
101101
@Test def ujson = projects.ujson.run()
102102
@Test def upickle = projects.upickle.run()
103103
@Test def utest = projects.utest.run()
104-
@Test def zio = projects.zio.run()
104+
@Test def zio = projects.zio.run()
105105
end CommunityBuildTestA
106106

107107
@Category(Array(classOf[TestCategory]))

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
956956
else
957957
singleton(tp).equal(tree)
958958
case _ =>
959-
tree.ensureConforms(defn.MatchableType)
960-
.select(defn.Any_isInstanceOf)
961-
.appliedToType(tp)
959+
tree.select(defn.Any_isInstanceOf).appliedToType(tp)
962960
}
963961

964962
/** tree.asInstanceOf[`tp`] */

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ class Definitions {
301301
Final,
302302
bounds = TypeBounds.lower(AnyClass.thisType))
303303

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

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

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

@@ -1174,7 +1174,6 @@ class Definitions {
11741174

11751175
// ----- Symbol sets ---------------------------------------------------
11761176

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

11801179
@tu lazy val AbstractFunctionType: Array[TypeRef] = mkArityArray("scala.runtime.AbstractFunction", MaxImplementedFunctionArity, 0)

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ object SymDenotations {
961961
def matchNullaryLoosely(using Context): Boolean = {
962962
def test(sym: Symbol) =
963963
sym.is(JavaDefined) ||
964-
defn.AnyOrMatchable.contains(sym.owner) ||
964+
sym.owner == defn.AnyClass ||
965965
sym == defn.Object_clone ||
966966
sym.owner.is(Scala2x)
967967
this.exists && (test(symbol) || allOverriddenSymbols.exists(test))

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@ class Erasure extends Phase with DenotTransformer {
6161
// After erasure, all former Any members are now Object members
6262
val ClassInfo(pre, _, ps, decls, selfInfo) = ref.info
6363
val extendedScope = decls.cloneScope
64-
def copyDecls(from: ClassSymbol) =
65-
for decl <- from.classInfo.decls do
66-
if !decl.isConstructor then extendedScope.enter(decl)
67-
copyDecls(defn.AnyClass)
68-
copyDecls(defn.MatchableClass)
64+
for decl <- defn.AnyClass.classInfo.decls do
65+
if !decl.isConstructor then extendedScope.enter(decl)
6966
ref.copySymDenotation(
7067
info = transformInfo(ref.symbol,
7168
ClassInfo(pre, defn.ObjectClass, ps, extendedScope, selfInfo))
@@ -79,7 +76,7 @@ class Erasure extends Phase with DenotTransformer {
7976
defn.ObjectClass.primaryConstructor
8077
else oldSymbol
8178
val oldOwner = ref.owner
82-
val newOwner = if defn.AnyOrMatchable.contains(oldOwner) then defn.ObjectClass else oldOwner
79+
val newOwner = if oldOwner == defn.AnyClass then defn.ObjectClass else oldOwner
8380
val oldName = ref.name
8481
val newName = ref.targetName
8582
val oldInfo = ref.info

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ trait Checking {
988988
val psuper = parent.superClass
989989
val csuper = cls.superClass
990990
val ok = csuper.derivesFrom(psuper) ||
991-
parent.is(JavaDefined) && defn.AnyOrMatchable.contains(csuper) &&
991+
parent.is(JavaDefined) && csuper == defn.AnyClass &&
992992
(parent == defn.JavaSerializableClass || parent == defn.ComparableClass)
993993
if (!ok)
994994
report.error(em"illegal trait inheritance: super$csuper does not derive from $parent's super$psuper", pos)

scala3doc/test/dotty/dokka/diagram/HierarchyTest.scala

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
1212
AfterDocumentablesTransformation { m =>
1313
m.visitMembers { x =>
1414
if (x.getName == "C1") {
15-
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "Object"), x.getParentsAsStrings)
15+
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "Matchable", "Object"), x.getParentsAsStrings)
1616
assertEquals(List("B1", "B2", "B3"), x.getDirectParentsAsStrings)
1717
assertEquals(List("E1", "E2"), x.getKnownChildrenAsStrings)
18-
val graph = MemberExtension.getFrom(x).map(_.graph)
18+
val graph = MemberExtension.getFrom(x).map(_.graph)
1919
assertTrue("Graph is empty!", graph.isDefined)
2020
assertEquals(
2121
Set(
22+
"Object" -> "Matchable",
23+
"Matchable" -> "Any",
2224
"Object" -> "Any",
2325
"A1" -> "Object",
2426
"A2[Int]" -> "Object",
@@ -42,15 +44,15 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
4244
)
4345
}
4446
if (x.getName == "E2") {
45-
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3", "Object"), x.getParentsAsStrings)
47+
assertEquals(List("A1", "A2[Int]", "A3[Int, String]", "Any", "B1", "B2", "B3", "C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3", "Matchable", "Object"), x.getParentsAsStrings)
4648
assertEquals(List("C1[Int, Boolean, Any]", "D2[Int, Boolean]", "D3"), x.getDirectParentsAsStrings)
4749
assertEquals(List.empty, x.getKnownChildrenAsStrings)
48-
val graph = MemberExtension.getFrom(x).map(_.graph)
50+
val graph = MemberExtension.getFrom(x).map(_.graph)
4951
assertTrue("Graph is empty!", graph.isDefined)
5052
assertEquals(
5153
Set(
5254
"Object" -> "Any",
53-
// "A1" -> "Object", // These are not applicable beacuase of bug and its workaround
55+
// "A1" -> "Object", // These are not applicable beacuase of bug and its workaround
5456
// "A2[Int]" -> "Object", // More info at ClassLikeSupport.scala:37
5557
// "A3[Int, String]" -> "Object",
5658
// "B1" -> "Object",
@@ -65,6 +67,8 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
6567
// "C1[Int, Boolean, Any]" -> "B1",
6668
// "C1[Int, Boolean, Any]" -> "B2",
6769
// "C1[Int, Boolean, Any]" -> "B3",
70+
"Object" -> "Matchable",
71+
"Matchable" -> "Any",
6872
"E2" -> "D2[Int, Boolean]",
6973
"E2" -> "D3",
7074
"D2[Int, Boolean]" -> "Object",
@@ -75,16 +79,18 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
7579
)
7680
}
7781
if (x.getName == "A2") {
78-
assertEquals(List("Any", "Object"), x.getParentsAsStrings)
82+
assertEquals(List("Any", "Matchable", "Object"), x.getParentsAsStrings)
7983
assertEquals(List.empty, x.getDirectParentsAsStrings)
8084
assertEquals(List("B2", "B3", "C1[A, B, C]", "E1", "E2"), x.getKnownChildrenAsStrings)
81-
val graph = MemberExtension.getFrom(x).map(_.graph)
85+
val graph = MemberExtension.getFrom(x).map(_.graph)
8286
assertTrue("Graph is empty!", graph.isDefined)
8387
assertEquals(
8488
Set(
89+
"Object" -> "Matchable",
90+
"Matchable" -> "Any",
8591
"Object" -> "Any",
8692
"A2[T]" -> "Object",
87-
"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`
93+
"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`
8894
"B3" -> "A2[T]",
8995
"C1[A, B, C]" -> "A2[T]",
9096
"E1" -> "A2[T]",
@@ -95,4 +101,4 @@ class HierarchyTest extends ScaladocTest("hierarchy"):
95101
}
96102
}
97103
}
98-
)
104+
)

0 commit comments

Comments
 (0)