-
Notifications
You must be signed in to change notification settings - Fork 185
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
DisableSyntax.NoFinalVal
needs to take into account the context
#1935
Comments
Hi @BalmungSan!
Did you see the (badly escaped) comment about the configuration toggle in the docs?
My understanding after digging into this is that Since it's in opt-in and documented, I don't see any problem keeping it. What do you suggest? We could issue a warning if that rule is used with recent scala (ignoring the sbt/zinc version since it's not available to rules) - happy to take PRs on this. |
@bjaglin Yeah I read the thread. To my understanding, the problem is related to constant-inlining. Thus, my rationale is that in the example I shared we were not doing something wrong. And we would like not to disable the rule in general. So, not sure if the rule could be extended to check if the |
Thanks for clarifying. I am no expert either, but I agree it makes sense to relax the rule when an explicit type is present 👍 I don't think I will personally prioritize this as the amount of users for which enabling |
I totally understand that the old constant-inlining in Scala 2 has some problems, and that Scala 3
inline
is better. I also, agree that afinal val
inside anobject
orfinal class
is redundant.However, unless I am missing something like a compiler bug or bad practice (and if that is the case I would highly appreciate the feedback), I think there are valid use cases for making a
final val
.I will share the situation in particular that we faced today, but I think the root use case is common enough.
This, of course, triggers the
noFinalVal
warning / error.For now, we work around the problem using
override protected final def
which is fine (and Arman will actually recommend doing that because of performance). But, we wonder if the rule is just too strict (since this feels like a normal use case in OOP) or if usingfinal val
in this context is still problematic and thus should be avoided.The text was updated successfully, but these errors were encountered: