-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Missing warning for invalid recursive val. #14429
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
Comments
It seems to me this came up again but I can't find a ticket or discussion. That was an early retronym contribution. Someone always says why would anyone do that, so it's worth noticing why retronym used to do that in 2012:
I guess that is the same use case. Note the similarity to the last tweak to name binding, illustrated at this ticket and changed in the PR linked there (which I will try not to pollute with a reference). The problem there was that the shadowing member was inherited.
Perhaps the tweak could be tweaked: the shadowing member matches an inherited member, which is grounds for making the name on the RHS ambiguous. However, you're supposed to be able to introduce an override specifically to disambiguate in this case, so maybe this only justifies a warning when the shadowing member is the enclosing definition.
There was another recent request for help with shadowing. Maybe this is the ticket I was thinking of, to warn on certain recursions. This is your ticket for givens: #10947 Here is tpolecat's almost a duplicate but lazy vals. #12943 which is what I was remembering. |
I will keep running into this issue 😄 |
I remember adding something for recursive defs |
Indeed dotty-staging@ddf73dd introduced the check for recursive definitions:
It is done during the The check for |
This should already be covered by Edit: As the option |
Excellent, indeed:
Is it? Shouldn't we encourage users interested in these checks to use @Swoorup could you use this flag for your use-cases? |
Asking the obvious, why isn't Regardless I do expect this particular case to at least give me a warning. Its not immediately obvious to figure what the issue is and let alone where the issue lies, in a simple 50-100 line code, when you use the default vanilla setting. |
There is still something we want to improve, in particular, better error messages for handling inner classes, and improve the modularity of the check (warn for subtle initialization behavior of open class/traits). And we also want to get more community feedback before turning it on by default. |
The warning is available under
I only just realized that the difference is that one warns about uninitialized fields and the other warns about non-initialized values.
for
The previous recursive def fix was superseded by I'm intrigued by my earlier comment that this is a shadowing problem, i.e., it should tell me what I'm shadowing accidentally and how to fix the reference. I just deleted my comment with an example of solving the OP in Scala 2 with the usual caveat that "nobody codes like that". A modern help message could tell me how people do code. Linking a related comment that formalisms and language discipline win over ad-hoc warnings. #16830 (comment) |
Compiler version
3.1.1
Minimized code
https://scastie.scala-lang.org/9Naw4C8JRuKQtPd0VXBXLw
No warnings or compilation errors
Expectation
Compiler error or warning.
Scala 2 gives
value a in object Playground does nothing other than call itself recursively
Without warning, this is easy to create bugs like this. For eg:
The text was updated successfully, but these errors were encountered: