From fb8389390a7db2f06f41fe2f3d7a9c2fcdec6bdd Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 12 Nov 2024 11:24:29 +0000 Subject: [PATCH 1/3] Fix Any#className decorator on null --- compiler/src/dotty/tools/dotc/core/Decorators.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 29d4b3fa4052..96a2d45db80d 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -292,7 +292,7 @@ object Decorators { case _ => String.valueOf(x).nn /** Returns the simple class name of `x`. */ - def className: String = x.getClass.getSimpleName.nn + def className: String = if x == null then "" else x.getClass.getSimpleName.nn extension [T](x: T) def assertingErrorsReported(using Context): T = { From 3d79d407aff7cbcf70d8736459c231e9b73d55dd Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 12 Nov 2024 11:58:38 +0000 Subject: [PATCH 2/3] (Re-)Drop inaccessible subclasses from refineUsingParent This reverts commit cecd05356beecd232053d4c593af54bcc12cad0e. --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 6 +++++- tests/pos/i21790.scala | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i21790.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 2403a6e22bc6..79eac7bde38d 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -930,7 +930,11 @@ object TypeOps: for tp <- mixins.reverseIterator do protoTp1 <:< tp maximizeType(protoTp1, NoSpan) - wildApprox(protoTp1) + val inst = wildApprox(protoTp1) + if !inst.classSymbol.exists then + // E.g. i21790, can't instantiate S#CA as a subtype of O.A, because O.CA isn't accessible + NoType + else inst } if (protoTp1 <:< tp2) instantiate() diff --git a/tests/pos/i21790.scala b/tests/pos/i21790.scala new file mode 100644 index 000000000000..0cc7db935ac7 --- /dev/null +++ b/tests/pos/i21790.scala @@ -0,0 +1,14 @@ +package p + +trait S: + sealed trait A + private class CA() extends A + +object O extends S + +trait T + +class Test: + def f(e: T) = e match + case _: O.A => + case _ => From 21e5f3c40a156043622f2d400e2cb51cc138bab9 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 12 Nov 2024 12:01:35 +0000 Subject: [PATCH 3/3] Tweak refineUsingParent drop conditions In tests/pos/i21790.scala, O.A has no class symbol, because it's an inaccessible private class of S. But in tests/warn/i21860.scala, Shape.Triangle doesn't have a "classSymbol" because it has multiple - Shape and Corners. So use .classSymbols.isEmpty instead of !.classSymbol.exists --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 79eac7bde38d..697e50c6a2a8 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -931,7 +931,7 @@ object TypeOps: protoTp1 <:< tp maximizeType(protoTp1, NoSpan) val inst = wildApprox(protoTp1) - if !inst.classSymbol.exists then + if inst.classSymbols.isEmpty then // E.g. i21790, can't instantiate S#CA as a subtype of O.A, because O.CA isn't accessible NoType else inst