Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Survive inaccessible types when computing implicit scope #21589

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3292,14 +3292,14 @@ object UnusedSymbol {

class NonNamedArgumentInJavaAnnotation(using Context) extends SyntaxMsg(NonNamedArgumentInJavaAnnotationID):

override protected def msg(using Context): String =
override protected def msg(using Context): String =
"Named arguments are required for Java defined annotations"
+ Message.rewriteNotice("This", version = SourceVersion.`3.6-migration`)

override protected def explain(using Context): String =
override protected def explain(using Context): String =
i"""Starting from Scala 3.6.0, named arguments are required for Java defined annotations.
|Java defined annotations don't have an exact constructor representation
|and we previously relied on the order of the fields to create one.
|Java defined annotations don't have an exact constructor representation
|and we previously relied on the order of the fields to create one.
Comment on lines -3301 to +3302
Copy link
Member

@hamzaremmal hamzaremmal Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR will fail because of the changes here, some of the checkfiles will not match anymore, they need to be updated.

|One possible issue with this representation is the reordering of the fields.
|Lets take the following example:
|
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 @@ -821,6 +821,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
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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Cmd(List("1", "2"))
Cmd(List("1", "2")) // error // error

)
}
}
Loading