Skip to content

Commit 8fbd460

Browse files
Backport "Survive inaccessible types when computing implicit scope" to LTS (#22128)
Backports #21589 to the 3.3.5. PR submitted by the release tooling. [skip ci]
2 parents 2d50b3b + 0484e65 commit 8fbd460

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

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

+2
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

+4
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.check

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i21543.scala:10:15 ------------------------------------------------------------
2+
10 | Cmd(List("1", "2")) // error // error
3+
| ^^^
4+
| Found: ("1" : String)
5+
| Required: Event
6+
|
7+
| Note that I could not resolve reference Event.
8+
| Event is a private member in a base class
9+
|
10+
|
11+
| longer explanation available when compiling with `-explain`
12+
-- [E007] Type Mismatch Error: tests/neg/i21543.scala:10:20 ------------------------------------------------------------
13+
10 | Cmd(List("1", "2")) // error // error
14+
| ^^^
15+
| Found: ("2" : String)
16+
| Required: Event
17+
|
18+
| Note that I could not resolve reference Event.
19+
| Event is a private member in a base class
20+
|
21+
|
22+
| longer explanation available when compiling with `-explain`

tests/neg/i21543.scala

+13
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")) // error // error
11+
)
12+
}
13+
}

0 commit comments

Comments
 (0)