-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Warn universal extensions on opaque types #22502
base: main
Are you sure you want to change the base?
Conversation
@@ -1190,7 +1191,7 @@ object RefChecks { | |||
} | |||
} | |||
.exists | |||
if !target.typeSymbol.isOpaqueAlias && hidden | |||
if hidden |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That line keeps getting shorter and shorter! 🥲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, it makes sense to say: if the extension method is hidden, then emit a warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so simple when you put it like that.
object Upperbound: | ||
opaque type IArray[+T] <: String = String | ||
extension (arr: IArray[Byte]) def length: Int = 0 // warn | ||
extension [T <: Int](arr: T) def length: Int = 0 // nowarn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't harm to add this extra test
extension [T <: Int](arr: T) def length: Int = 0 // nowarn | |
extension [T <: IArray[Byte]](arr: T) def length: Int = 0 // warn |
extension (d: D) def equals(that: Any): Boolean = false // warn | ||
|
||
object Upperbound: | ||
opaque type IArray[+T] <: String = String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to suggest to change the name of the opaque type, I think we can all agree that IArray[+T] <: String = String
is weird... Maybe:
opaque type IArray[+T] <: String = String | |
opaque type MyString <: String = String |
|
||
object NonUpperbound: | ||
opaque type IArray[+T] = String | ||
extension (arr: IArray[Byte]) def length: Int = 0 // nowarn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extension (arr: IArray[Byte]) def length: Int = 0 // nowarn | |
extension (arr: IArray[Byte]) def length: Int = 0 // nowarn | |
extension [T <: IArray[Byte]](arr: T) def length: Int = 0 // nowarn |
Fixes #22232
Work also done by @hamzaremmal, @julian-a-avar-c and @nmcb