Skip to content

Commit 58f88a6

Browse files
authored
(Re-)Drop inaccessible subclasses from refineUsingParent (#21930)
Re-fixes #21790 Closes #21896
2 parents 5d5a9e6 + 21e5f3c commit 58f88a6

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ object Decorators {
292292
case _ => String.valueOf(x).nn
293293

294294
/** Returns the simple class name of `x`. */
295-
def className: String = x.getClass.getSimpleName.nn
295+
def className: String = if x == null then "<null>" else x.getClass.getSimpleName.nn
296296

297297
extension [T](x: T)
298298
def assertingErrorsReported(using Context): T = {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,11 @@ object TypeOps:
900900
for tp <- mixins.reverseIterator do
901901
protoTp1 <:< tp
902902
maximizeType(protoTp1, NoSpan)
903-
wildApprox(protoTp1)
903+
val inst = wildApprox(protoTp1)
904+
if inst.classSymbols.isEmpty then
905+
// E.g. i21790, can't instantiate S#CA as a subtype of O.A, because O.CA isn't accessible
906+
NoType
907+
else inst
904908
}
905909

906910
if (protoTp1 <:< tp2) instantiate()

tests/pos/i21790.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package p
2+
3+
trait S:
4+
sealed trait A
5+
private class CA() extends A
6+
7+
object O extends S
8+
9+
trait T
10+
11+
class Test:
12+
def f(e: T) = e match
13+
case _: O.A =>
14+
case _ =>

0 commit comments

Comments
 (0)