-
-
Notifications
You must be signed in to change notification settings - Fork 661
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
Final #6596
Final #6596
Conversation
Allow using it as field modifier for functions and in place of `var` for fields
When discussing it, we also suggested to allow |
Done Note that there's a decision to be made there: Anonymous structures allow both class an structure notation, so when seeing the |
Is there a good reason for allowing this then? It seems like this is just adds one more thing to worry about in code-style debates / one additional check in haxe-checkstyle. :) |
What about simply always inlining |
Honestly i feel this We already have |
Technically, you'll have to worry about it anyway because if anything, it would be a typing error. That means that it's still valid syntax either way. |
You would have the exact same situation with |
So let's think a bit more about reducing such duplications, not introducing them :) |
We could remove |
Can we mark some syntax as deprecated and remove it in 4.1? |
Will this eventually be expressed in target output? For example would "final s = new Something();" be marked as final in the Java target? This is important for generating thread safe code in cases where locks (constructors) are difficult. |
Can this can be overridden using |
It can be easily overridden using "search and replace." ;-) |
Since I feel like if you have to use |
This adds
final
as a keyword and allows using it in two places:var
when declaring fields.The semantics of the latter are as follows:
static final
vars have to be initialized immediatelyfinal
vars which are not initialized immediately, it requires a constructor which has to assign to all such fieldsstatic inline final
works, but has the same semantics asstatic inline var
Implementation details
I added a new
var_access
variantAccCtor
which is used as thev_write
value for non-static final vars. For static vars, we simply useAccNo
. We internally add the@:final
metadata tofinal
fields (both vars and methods) in order to recognize final fields for the XML export. This also makes it automatically work with the already implemented@:final
parts of the compiler.Parsing is a bit funky: We can't parse
final
as a field modifier because it is also used forfinal x
fields. We also have to consider that field modifiers may appear both before and after thefinal
, which requires a call toparse_cf_rights
twice.