www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - version'd else-if

reply derick_eddington nospam.yashmoo.com writes:
DMD 0.125 on Linux.

: import std.stdio;
:
: void main (char[][] args)
: {
:       if (args.length = 2) {
:               writefln("2");
:       }
:       version (BUG) {
:               else if (args.length == 3) {
:                       writefln("3");
:               }
:       }
: }

$ dmd verelif.d
verelif.d(9): found 'else' instead of statement
verelif.d(13): unrecognized declaration

$ dmd -version=BUG verelif.d
verelif.d(9): found 'else' instead of statement
verelif.d(13): unrecognized declaration
Jun 01 2005
next sibling parent reply Derek Parnell <derek psych.ward> writes:
On Wed, 1 Jun 2005 07:56:16 +0000 (UTC),
derick_eddington nospam.yashmoo.com wrote:

 DMD 0.125 on Linux.
 
: import std.stdio;
:
: void main (char[][] args)
: {
:       if (args.length = 2) {
:               writefln("2");
:       }
:       version (BUG) {
:               else if (args.length == 3) {
:                       writefln("3");
:               }
:       }
: }
 
 $ dmd verelif.d
 verelif.d(9): found 'else' instead of statement
 verelif.d(13): unrecognized declaration
 
 $ dmd -version=BUG verelif.d
 verelif.d(9): found 'else' instead of statement
 verelif.d(13): unrecognized declaration
The docs say that the body of a version block must be valid D statements, and 'else' never starts a valid D statement. So its not a bug. Try rearranging it thus ... void main (char[][] args) { if (args.length == 2) { writefln("2"); } else version (BUG) { if (args.length == 3) { writefln("3"); } } } -- Derek Melbourne, Australia 1/06/2005 6:39:25 PM
Jun 01 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Derek Parnell" <derek psych.ward> wrote in message 
news:g6j77wymnkft.9f9aw0m8symi$.dlg 40tude.net...
 Try rearranging it thus ...

 void main (char[][] args)
 {
       if (args.length == 2) {
               writefln("2");
       }
       else
       version (BUG) {
               if (args.length == 3) {
                       writefln("3");
               }
       }
 }
Might have to have an extra set of {} after the version statement - or else anything after the version statement, if BUG is not defined, will be the "else" statement!
Jun 02 2005
parent derick_eddington nospam.yashmoo.com writes:
In article <d7npko$27fp$1 digitaldaemon.com>, Jarrett Billingsley says...
"Derek Parnell" <derek psych.ward> wrote in message 
news:g6j77wymnkft.9f9aw0m8symi$.dlg 40tude.net...
 Try rearranging it thus ...

 void main (char[][] args)
 {
       if (args.length == 2) {
               writefln("2");
       }
       else
       version (BUG) {
               if (args.length == 3) {
                       writefln("3");
               }
       }
 }
Might have to have an extra set of {} after the version statement - or else anything after the version statement, if BUG is not defined, will be the "else" statement!
I wondered about that too at first but it's not at all just textually including like I was assuming before. version() is ConditionalStatement which is a Statement, and in this case it is always seen as the Statement of the 'else'. For example:
 void main (char[][] args)
 {
       if (args.length == 2) {
               writefln("2");
       }
       else
       version (BUG) {
               if (args.length == 3) {
                       writefln("3");
               }
       }
       writefln("hmm");
 }
$ ./verelif hmm $ ./verelif abc 2 hmm
Jun 02 2005
prev sibling parent zwang <nehzgnaw gmail.com> writes:
derick_eddington nospam.yashmoo.com wrote:
 DMD 0.125 on Linux.
 
 : import std.stdio;
 :
 : void main (char[][] args)
 : {
 :       if (args.length = 2) {
 :               writefln("2");
 :       }
 :       version (BUG) {
 :               else if (args.length == 3) {
 :                       writefln("3");
 :               }
 :       }
 : }
 
 $ dmd verelif.d
 verelif.d(9): found 'else' instead of statement
 verelif.d(13): unrecognized declaration
 
 $ dmd -version=BUG verelif.d
 verelif.d(9): found 'else' instead of statement
 verelif.d(13): unrecognized declaration
 
 
This is not a bug. Your sample code violates the syntax defined in http://www.digitalmars.com/d/version.html ConditionalDeclaration: Condition DeclarationBlock Condition DeclarationBlock else DeclarationBlock DeclarationBlock: Declaration { Declarations } Declarations: Declaration Declaration Declarations ConditionalStatement: Condition Statement Condition Statement else Statement Condition: VersionCondition DebugCondition StaticIfCondition IfTypeCondition
Jun 01 2005