-
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 on bad extensions of aliases #22362
Conversation
Hi @som-snytt! Would you like to have a look at this since you opened the issue and the change is in code that you authored? |
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.
Looks great! Thanks for the contribution.
I added a small nitpick comment, but you can ignore it if you don't like it, since it's purely a personal preference/opinion.
Sorry, I got used to doing reviews for people that can merge by themselves, so the call for action is very unclear 😅 , so either:
|
I'm suspicious about aliases that are not effectively final. I'm taking a look now. |
This is the use case I was thinking of, but it is covered by the previous change, not to warn on overrides. It's already covered in tests/warn/i16743.scala although I've made it look slightly different.
|
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.
Otherwise LGTM!
tests/warn/i22233.check
Outdated
@@ -0,0 +1,7 @@ | |||
-- [E194] Potential Issue Warning: tests/warn/i22233.scala:1:26 -------------------------------------------------------- |
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.
probably a check file is not needed, as the text is vetted by the original test.
what I would do is move tests/pos/ext-override.scala to warns.
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 removed the check file 👍
Also I moved tests/pos/ext-override.scala
to the warn but actually I don't understand the reasoning. The tests in warn all give a warning right? In this test case there are no warnings. Could you elaborate?
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.
@RoccoMathijn they allow warn tests to have zero warnings, which is useful. I think (IMHO) tests about lack of warning should go in warn, while testing "does this compile" remain in pos. A warn test can still have -Werror
to announce that no warns are expected (so you don't have to scan the test code).
@som-snytt I was thinking about a similar example: //> using scala 3.nightly
class Animal {
def show: String = "Animal"
def show1: String = "Animal"
}
class Dog extends Animal
abstract class A:
type X
extension (a: X) def show: String
class B extends A:
override type X = Animal
extension (d: X) override def show: String = "Dog"
class C:
type X = Animal
extension (d: X) def show1: String = "Dog" // no warn on nightly, warn now
@main
def main =
given B {}
val dog = new Dog
println(dog.show)
given C {}
println(dog.show1) This change is closer to being correct IMO. Though, I'm not sure if we should also warn on |
@KacperFKorban yes. The justification for not warning at the override in B is "don't warn for something the user can do nothing about". Some Another example for overriding is that |
I forgot https://github.com/scala/scala3/pull/21191/files in case it is relevant. |
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.
Looks Good! Thanks!
Fixes #22233