From f478d7e2c7260997a7ea3df6fbaf01a06e4052a6 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 17 Oct 2024 16:25:29 +0100 Subject: [PATCH] Drop inaccessible subclasses from refineUsingParent --- .../src/dotty/tools/dotc/core/Decorators.scala | 2 +- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 6 +++++- tests/pos/i21790.scala | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i21790.scala 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 = { diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index bfda613d0586..846e4091c617 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -921,7 +921,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 _ =>