http://d.puremagic.com/issues/show_bug.cgi?id=7724



--- Comment #6 from Manu <turkey...@gmail.com> 2012-04-21 09:39:11 PDT ---
(In reply to comment #4)
> This is not a bug - you can't use final with variables.
> 
> Examine following D2 code:
> 
> import std.stdio;
> 
> class Issue7724 {
> /+--------------------------+
>  | Uncomment to get "...someValue final cannot be applied to variable" error.
>   final:
>     int someValue;
>     int setValue(int argValue) { someValue = argValue; }
>     int getValue() { return someValue; }
>  +--------------------------+/ 
> 
>   // Correct:
>   int someValue;
>   final:
>     void setValue(int argValue) { someValue = argValue; }
>     int getValue() { return someValue; }
> }
> 
> int main() {
>   return 0;
> }

It's inconsistent to allow superfluous instance of some attributes, but not
others.

static int x; at global scope is silently ignored.
final applied to data members should be equally ignored, but rather, attributes
with colon probably just shouldn't be applied to things that they're not
applicable to. Otherwise you'll end up with all sorts of class organisation
mess when you consider a few attributes together.

I'm not into the idea that the language should insist I break my class up
according to arbitrary attributes, rather than keeping related things together,
which I find far preferable.

Also, declaring 'final:' at some arbitrary point in a class is hard to spot,
and error prone (it might be missing). If it's the first thing in a class (like
'public:' often is in C++), then it's very easy to spot and validate.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to