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

Warn universal extensions on opaque types #22502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rochala
Copy link
Contributor

@rochala rochala commented Feb 3, 2025

Fixes #22232

Work also done by @hamzaremmal, @julian-a-avar-c and @nmcb

@@ -1190,7 +1191,7 @@ object RefChecks {
}
}
.exists
if !target.typeSymbol.isOpaqueAlias && hidden
if hidden
Copy link
Contributor

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! 🥲

Copy link
Member

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

Copy link
Contributor

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
Copy link
Member

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

Suggested change
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
Copy link
Member

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:

Suggested change
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
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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn universal extensions on opaque type
3 participants