Skip to content

Commit ea6d866

Browse files
authored
Merge pull request #112 from scala/backport-lts-3.3-21930
Backport "(Re-)Drop inaccessible subclasses from refineUsingParent" to 3.3 LTS
2 parents 267b9ce + ef83bd2 commit ea6d866

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ object Decorators {
284284
case _ => String.valueOf(x).nn
285285

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

289289
extension [T](x: T)
290290
def assertingErrorsReported(using Context): T = {

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,11 @@ object TypeOps:
943943
for tp <- mixins.reverseIterator do
944944
protoTp1 <:< tp
945945
maximizeType(protoTp1, NoSpan)
946-
wildApprox(protoTp1)
946+
val inst = wildApprox(protoTp1)
947+
if inst.classSymbols.isEmpty then
948+
// E.g. i21790, can't instantiate S#CA as a subtype of O.A, because O.CA isn't accessible
949+
NoType
950+
else inst
947951
}
948952

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

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)