[Issue 1053] New: Make 'static else if' or 'static if (...) {...} else if' work

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Mar 11 15:42:51 PDT 2007


<d-bugmail at puremagic.com> wrote in message 
news:bug-1053-3 at http.d.puremagic.com/issues/...
> http://d.puremagic.com/issues/show_bug.cgi?id=1053
>
>           Summary: Make 'static else if' or 'static if (...) {...} else 
> if'
>                    work
>           Product: D
>           Version: 1.008
>          Platform: All
>        OS/Version: All
>            Status: NEW
>          Severity: enhancement
>          Priority: P2
>         Component: DMD
>        AssignedTo: bugzilla at digitalmars.com
>        ReportedBy: wbaxter at gmail.com
>
>
> It would be nice if "else static if" could be written "static else if". 
> Or
> even better just "else if".
>
> "else static if" struck me as odd the first time I saw it, and since then 
> I
> continue to mistype it as "static else if" pretty much every time I use 
> it.

Then stop typing it that way ;)

>
> So it would be great if "static else if" just worked.
>
> On the other hand, I'm pretty sure
>  static if (foo) { }
>  else if (bar) { }
> is an error currently, so it would be nice if that were just taken to be a
> "static else if".  There isn't a "static else {}" so why should we have to
> repeat the "static" on an "else if"?  One "static" should be enough.

It's not.  "static if" is a statement of its own, and "if" is a statement of 
its own.  This:

static if(foo) {}
else if(bar) {}

is legal.  It means if foo evaluates to true, compile in the static if's 
body.  Otherwise, compile in the "if(bar) {}" statement.

There's no "static else" because the grammar for static if is "static 
if(cond) statment 'else' statement'.  So you chain static ifs with "static 
if(){} else static if(){}" because "static if" is a statement, and it comes 
after that "else".

> Oh, and besides that it's
> already ambiguous with plain ifs...
>  if (foo)
>     if (biff)
>         single_statement();
>  else if (bar) { }
>
> Exactly the same deal -- who does the else belong to?

It belongs to the if(biff) statement.

> As an added bonus either of these changes would make the Emacs D-mode 
> capable
> of indenting static ifs with else ifs properly.  That's not a sufficient 
> reason
> to make the change (emacs D-mode could be made to work somehow) But the 
> fact
> that cc-mode basically sees "else static if" as an aberration was the 
> thing
> that finally drove me to file an enhancement request on this.

Unfortunately I think this would make the grammar needlessly complicated.

And don't use emacs; use vim ;) 




More information about the Digitalmars-d-bugs mailing list