From 603973ebb2507ebdb68862c6942c9115d8af7d80 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 [Cherry-picked fb8389390a7db2f06f41fe2f3d7a9c2fcdec6bdd] --- 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 f41faf2358a9..a76317d01c2d 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -284,7 +284,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 185188cbaa4005f8e063fe5739a599b1d1125e4c 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. [Cherry-picked 3d79d407aff7cbcf70d8736459c231e9b73d55dd] --- 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 9c9bf332d1f4..9bd89ae3071a 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -943,7 +943,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 ef83bd29764534d64a2a396284d1afdb226bc189 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 [Cherry-picked 21e5f3c40a156043622f2d400e2cb51cc138bab9] --- 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 9bd89ae3071a..46738dc3a3e1 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -944,7 +944,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