-
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
private[this] inference does not work for constructor parameters #22620
Comments
Apparently, that is an intentional feature: It would be nice if the reference clarified that. The idea is that deciding if a field is required, etc, is already done "by construction" in constructors for class params, so adding Inferring it "back" to private local means the field can be eliminated, which is not desirable. A possible nuance would be "don't eliminate inferred private local, only use that for variance checking", but maybe that is too much nuance. This corner case is served just by introducing a private member "manually". |
Actually, I feel like that nuance you mentioned would make more sense. I would say that all the old uses of Also, while the |
And there's another related issue: if you use the -rewrite option in scalac on a working example with a |
@yaniskas thanks, I'll also check out the rewrite bug. I submitted a PR only to document status quo. You could open a "Discussion" topic if you feel strongly about the feature. Or I could "convert to discussion" this ticket; my PR doesn't have to "fix" it. I don't have an opinion. I observe the sometimes-gnarly syntax is "just a convenient shorthand" that is optimized for the common case. Actually, I do have an opinion: I'd prefer the simplicity of Edit: I misunderstood what you meant about the rewrite: not that it produces bad syntax, just that it requires refactoring in this case. That's interesting, whether it should refuse the rewrite. |
With the rewrite I meant that it just removes the To me it just seems like a regression/unnecessary removal of a feature. And I don't see why the syntax for |
I'll leave it here with the triage label so it's not overlooked. |
I wouldn't treat this a regression, although I agree that this bug is causing |
Document the status quo. Documents #22620
Compiler version
3.6.3
Minimized code
Output
Expectation
This code compiles correctly if you use the deprecated
private[this]
syntax, so according to the Scala 3 reference, it looks like the compiler should treat v as if it had been declaredprivate[this]
, and the code should compile without errors. It also happens to compile correctly if you do not include theprivate val
declaration at all and let the compiler infer it.The text was updated successfully, but these errors were encountered: