-
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
Enable LeakingImplicitClassVal lint rule #2650
Enable LeakingImplicitClassVal lint rule #2650
Conversation
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.
For the classes I wrote, this is clearly an improvement.
I suspect this is addressing much less than 1% of the problem of too many public vals in Chisel modules. Is this the first of many steps in a broader effort?
Not exactly, haha. My current effort is mostly about enabling as many of the builtin rules to Scalafix as possible. I think most of those rules are uncontroversially good rules to enable. Public |
Yeah, it’s hard to see how to employ lint rules to address that problem. (I’ve long wished Scala’s default visibility wasn’t public.) |
For anyone who isn't aware why this is a good lint rule, not doing this effectively adds the implicit class PartyString(val x: String) extends AnyVal {
def celebrate(): Unit = println(s"Woohoo from '$x'")
}
val myString = "Hello World!"
myString.celebrate() // Woohoo from 'Hello World!'
myString.x // <------- huh? Historical note: it used to be required for the |
Side note but I also have no idea why we are extending |
Related issue:
Type of change: other enhancement
Impact: no functional change
Development Phase: implementation
Release Notes
Followup to #2648.
This PR enables the
LeakingImplicitClassVal
lint rule in Scalafix. In Scala,val
constructor parameters are part of the public interface of a class. However, in most cases,implicit
classes do not intend to publicly expose theval
parameter, as the parameter is generally only there to assign an internal name to the object being implicitly converted to another type. This lint rule will require that allval
parameters toimplicit class
es be explicitly marked asprivate
.To the Scala experts: please take a look at the changes to the code required by this new lint rule and let me know if this is a reasonable rule to enable in rocket-chip.