Skip to content

Commit

Permalink
Backport "Survive inaccessible types when computing implicit scope" t…
Browse files Browse the repository at this point in the history
…o LTS (#22128)

Backports #21589 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Dec 4, 2024
2 parents 2d50b3b + 0484e65 commit 8fbd460
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class MissingType(val pre: Type, val name: Name)(using Context) extends TypeErro
case _ if givenSelf.exists && givenSelf.member(name).exists =>
i"""$name exists as a member of the self type $givenSelf of $cls
|but it cannot be called on a receiver whose type does not extend $cls"""
case _ if pre.baseClasses.exists(_.findMember(name, pre, Private, EmptyFlags).exists) =>
i"$name is a private member in a base class"
case _ =>
missingClassFile

Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,10 @@ trait ImplicitRunInfo:
override def stopAt = StopAt.Static
private val seen = util.HashSet[Type]()

override def derivedTypeBounds(tp: TypeBounds, lo: Type, hi: Type): Type =
if lo.exists && hi.exists then super.derivedTypeBounds(tp, lo, hi)
else NoType // Survive inaccessible types, for instance in i21543.scala.

def applyToUnderlying(t: TypeProxy) =
if seen.contains(t) then
WildcardType
Expand Down
22 changes: 22 additions & 0 deletions tests/neg/i21543.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- [E007] Type Mismatch Error: tests/neg/i21543.scala:10:15 ------------------------------------------------------------
10 | Cmd(List("1", "2")) // error // error
| ^^^
| Found: ("1" : String)
| Required: Event
|
| Note that I could not resolve reference Event.
| Event is a private member in a base class
|
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg/i21543.scala:10:20 ------------------------------------------------------------
10 | Cmd(List("1", "2")) // error // error
| ^^^
| Found: ("2" : String)
| Required: Event
|
| Note that I could not resolve reference Event.
| Event is a private member in a base class
|
|
| longer explanation available when compiling with `-explain`
13 changes: 13 additions & 0 deletions tests/neg/i21543.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
object CompilerCrash {
trait Scope {
private type Event = String

case class Cmd(events: List[Event])
}

new Scope {
val commands = List(
Cmd(List("1", "2")) // error // error
)
}
}

0 comments on commit 8fbd460

Please sign in to comment.