-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Infer private[this] #7411
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
Infer private[this] #7411
Conversation
The reason is that some of these fields might be converted later to private[this] fields which do not get setter. Instead, generate setters for private vars that are not private[this] in phase Getters.
The plan is that by then we know when a members is private[this].
Make private term members Local if they are accessed only from their owner's this-type.
Don't emit signatures for private fields of primitive type
Add docs to state that they will be dropped.
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/7411/ to see the changes. Benchmarks is based on merging with master (0f7a85b) |
While I welcome removal of this syntax, I don't thin that the semantic is unneccessary. It's very convenient to be able to enforce stricter rules. Also I wouldn't call To be quiet honest I think we need lot more flexible access restriction system, so we may specifiy complex predicates on who may and may not access an entity. Could you consider keeping the functionality under different syntax please?.. Maybe not a modifer but an annotation?.. |
That's just a cop out. Seriously, I have not seen a convincing argument why distinctions between private/protected and private/protected[this] are necessary. And unnecessary distinctions just lead to bikeshedding and complexity. One could argue that the default is wrong and it should always be [this]. We already had this discussion, and I believe that the reasons for keeping plain private and protected were convincing, for algorithmic reasons as well as backwards compatibility. |
@odersky trait ProtectedThisVarianceOk[-A, +B] {
protected[this] type AliasA = A
protected[this] type AliasB = B
}
trait ProtectedVarianceIsNotOk[-A, +B] {
// Error:(16, 18) contravariant type A occurs in invariant position in type A of type AliasA
// protected type AliasA = A
protected type AliasA = A
protected type AliasB = B
} Scala 2 allows declaration of IMHO removing |
Treating |
Sorry, I was not aware. It still feels like a bad blow for cake & PDT; possibly less dramatic if variant aliases are out of the picture anyway... Removal of private[this] is of course strictly an improvement (if someone needs a not-this |
Here is a proposal to retain |
Infer private[this] if all accesses are via this, even if it is not explicitly specified.
Deprecate usage of
private[this]
andprotected[this]
under -strict (i.e. for 3.1.).The main reasons for dropping
private[this]
are:this
is a value.private
is purely local and can be easily inferredprivate
orprivate[this]
? One is shorter but the other might be more efficient.protected[this]
by now influences compiler decisions in no way at all. Its delta overprotected
is small.protected
by itself is niche (e.g. Don Syme has argued eloquently why it is too niche for F#), so having two variants of it looks like overkill.