On Sat, 31 May 2014 19:27:08 -0400, Walter Bright
<newshou...@digitalmars.com> wrote:
On 5/30/2014 5:37 AM, Steven Schveighoffer wrote:
On Thu, 29 May 2014 21:15:21 -0400, deadalnix <deadal...@gmail.com>
wrote:
On Thursday, 29 May 2014 at 19:06:15 UTC, Steven Schveighoffer
wrote:
Static if is certainly NOT an attribute, it doesn't make any sense.
Well... it sorta does. static if does not introduce a new scope, even
with
{}, and this only happens with attributes.
-Steve
in which case
static if(cond) {
immutable:
}
int x;
should not create x as immutable if cond is true. The current
behavior is not consistent with attribute either.
Ugh, that is really bad. It shouldn't do that. Is that intentional?
Yes. Semantic scope and lexical scope are different things. The ':'
thing applies to the remaining statements in the lexical scope. 'static
if' does not create a new semantic scope, even though the { } suggests
it does.
deadalnix's suggestion, at least to me, was that currently the compiler
would attribute immutable to int x. Testing, I see it does not. Maybe I
misinterpreted the implication. The statement "current behavior is not
consistent with attribute" seems wrong then.
There have been several suggestions to make 'static if' apply
independently of the rest of the grammar, i.e. allow things like:
int static if (cond) * else [ ] foo; // conditionally make foo a
pointer or an array
I think we can agree that looks awful, but it is the same thing as
suggesting that the 'immutable:' above extend outside of its lexical
scope.
I agree, I think we are arguing the same thing.
static if seems like an attribute in how it scopes things.
-Steve