Skip to content

Commit 4e07efc

Browse files
authored
Drop inaccessible subclasses from refineUsingParent (#21799)
2 parents c63cfde + f478d7e commit 4e07efc

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Decorators.scala

+1-1
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 = {

Diff for: compiler/src/dotty/tools/dotc/core/TypeOps.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,11 @@ object TypeOps:
930930
for tp <- mixins.reverseIterator do
931931
protoTp1 <:< tp
932932
maximizeType(protoTp1, NoSpan)
933-
wildApprox(protoTp1)
933+
val inst = wildApprox(protoTp1)
934+
if !inst.classSymbol.exists then
935+
// E.g. i21790, can't instantiate S#CA as a subtype of O.A, because O.CA isn't accessible
936+
NoType
937+
else inst
934938
}
935939

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

Diff for: tests/pos/i21790.scala

+14
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)