Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Instance field should be allowed in initializer expression when it is initialized via "this.foo" sugar. #3263
This issue was originally filed by schwa...@gmail.com
/// Immutable 2D cartesian point.
/// Immutable planar arc.
PRODUCT / OS VERSION
I can easily work around this by not using the "this.foo" sugar, but the sugar is sweet :-)
This comment was originally written by schwaj...@gmail.com
I understand the reason for disallowing "this" in the initializer list, or maybe I don't :-) It seems like in this particular case, "this.foo" can be considered not an access to a field in "this", but rather as a name for an otherwise unnamed parameter.
For my education, could you briefly elaborate on why this is a bad idea?
Uniform rules are hugely important. Special cases are, as a rule, a bad idea. While they look tempting based on a single example, unforeseen effects compound. So as a language designer, one develops a distinct antipathy for them on principle. Every such "featurette" also has an opportunity cost - time spent on it comes at the direct expense of something else.
This particular case is not worth spending cycles on. The sugar is there for a very simple, common case. If things are more complex, use the full length form. It won't actually be much longer.