Skip to content

Commit e889472

Browse files
committed
Survive inaccessible types when computing implicit scope
Also: Give a better error message later when encountering a missing type that refers to a private member of a base class. The previous one was misleading since it referred to a potentially missing class file, which is certainly not the case here. Fixes #21543 [Cherry-picked 472555d][modified]
1 parent 91e973c commit e889472

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class MissingType(val pre: Type, val name: Name)(using Context) extends TypeErro
7373
case _ if givenSelf.exists && givenSelf.member(name).exists =>
7474
i"""$name exists as a member of the self type $givenSelf of $cls
7575
|but it cannot be called on a receiver whose type does not extend $cls"""
76+
case _ if pre.baseClasses.exists(_.findMember(name, pre, Private, EmptyFlags).exists) =>
77+
i"$name is a private member in a base class"
7678
case _ =>
7779
missingClassFile
7880

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ trait ImplicitRunInfo:
781781
override def stopAt = StopAt.Static
782782
private val seen = util.HashSet[Type]()
783783

784+
override def derivedTypeBounds(tp: TypeBounds, lo: Type, hi: Type): Type =
785+
if lo.exists && hi.exists then super.derivedTypeBounds(tp, lo, hi)
786+
else NoType // Survive inaccessible types, for instance in i21543.scala.
787+
784788
def applyToUnderlying(t: TypeProxy) =
785789
if seen.contains(t) then
786790
WildcardType

tests/neg/i21543.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object CompilerCrash {
2+
trait Scope {
3+
private type Event = String
4+
5+
case class Cmd(events: List[Event])
6+
}
7+
8+
new Scope {
9+
val commands = List(
10+
Cmd(List("1", "2"))
11+
)
12+
}
13+
}

0 commit comments

Comments
 (0)