Comment #0 by dlang-bugzilla — 2011-12-06T05:22:08Z
This code works in D1:
class C
{
final:
string s;
}
In D2 it results in:
Error: variable test_final.C.s final cannot be applied to variable
Since it works in D1, I assume it's an unintentional regression?
Comment #1 by dlang-bugzilla — 2011-12-06T05:30:56Z
I was told that "final" has meaning for variables in D1, so I'm changing this to an enhancement request.
Comment #2 by andrej.mitrovich — 2013-02-04T14:06:55Z
*** Issue 7724 has been marked as a duplicate of this issue. ***
Comment #3 by razvan.nitu1305 — 2018-07-06T12:21:16Z
The example compiles successfully on master git head. Closing as fixed.
Comment #4 by dlang-bugzilla — 2018-07-06T12:23:51Z
Razvan: I think a while ago we decided to use WORKSFORME for closing bugs that are no longer reproducible. FIXED is for things fixed as a result of a PR intended to fix that particular bug. I think at some point we used the resolution to find which bugs were fixed in one release cycle.
Comment #5 by dlang-bugzilla — 2018-07-06T12:25:34Z
BTW, is this bug even valid? What does "final" mean for a variable? Maybe refusing to compile "final" with variables is the correct behavior? If so, does that mean there's a regression?
Comment #6 by razvan.nitu1305 — 2018-07-06T12:30:35Z
If final is applied directly to the declaration, the compiler will issue an error:
class C
{
final string s; // error: cannot apply final to variable declarations;
}
However, if final is used as in the original bug report, it is simply ignored. The dmd philosophy for attributes that apply to block declarations is to apply the attribute where possible and to ignore it where it cannot be applied. Precedent: https://github.com/dlang/dmd/pull/7229