digitalmars.D - CaseStatement specification issue
- Sergey Kozyr (10/10) Aug 14 2014 I was reading D language reference and found some issue with
- Sergey Kozyr (21/21) Aug 14 2014 Sorry for previous message. Once again:
- Daniel Murphy (3/11) Aug 14 2014 "case 2:" is a CaseStatement and it's after "case 1:"
- Baz (3/24) Aug 14 2014 It's a "fall trough":
- AsmMan (25/59) Aug 14 2014 It's a fall trough but it is not the reason why it does works. It
- Baz (2/65) Aug 14 2014 I totally agree. I just wanted to mention the technical name.
- Sergey Kozyr (10/21) Aug 15 2014 I agree that this is a valid D language construction. But
- ketmar via Digitalmars-d (17/18) Aug 15 2014 and we'll find some more bugs there:
- Timon Gehr (2/4) Aug 15 2014 What is the problem? This passes DMD's parser.
- ketmar via Digitalmars-d (4/5) Aug 15 2014 that is the problem: it shouldn't. this has no sense, and it's easy to
- Timon Gehr (5/15) Aug 15 2014 That's not what you said.
- ketmar via Digitalmars-d (8/13) Aug 15 2014 that's what i mean. ok, i should write it clear.
- Sergey Kozyr (16/16) Aug 18 2014 Also two more errors in documentation:
- Brian Schott (8/10) Aug 18 2014 Check the list of bugs that I've already filed here:
- Sergey Kozyr (5/15) Aug 18 2014 I've created three issues in bug tracker: 13326, 13327, 13328.
- Sergey Kozyr (12/40) Aug 20 2014 I want to pay attention at line 9:
- Sergey Kozyr (7/11) Aug 20 2014 In second line equal sign is between "Identifier" and
I was reading D language reference and found some issue with "case ... :" statement specifications. Documentation http://dlang.org/statement#CaseStatement says that after case 1: must be non-empty statement "ScopeStatementList". For example case 1: } case 2: ; case 3
Aug 14 2014
Sorry for previous message. Once again: I was reading D language reference and found some issue with "case ... :" statement specifications. Documentation http://dlang.org/statement#CaseStatement says that after case 1: must be non-empty statement "ScopeStatementList". For example case 1: return true; case 2: { } case 3: ; But next example concerns me: case 1: case 2: return true; case 3: return false; After "case 1:" we see no statement at all. This conflicts with "CaseStatement" rule of documentation. But this is right D code. I think language reference must be updated.
Aug 14 2014
"Sergey Kozyr" wrote in message news:khaugqemvygmsaaeyild forum.dlang.org...case 1: case 2: return true; case 3: return false; After "case 1:" we see no statement at all. This conflicts with "CaseStatement" rule of documentation. But this is right D code. I think language reference must be updated."case 2:" is a CaseStatement and it's after "case 1:"
Aug 14 2014
On Thursday, 14 August 2014 at 13:19:36 UTC, Sergey Kozyr wrote:Sorry for previous message. Once again: I was reading D language reference and found some issue with "case ... :" statement specifications. Documentation http://dlang.org/statement#CaseStatement says that after case 1: must be non-empty statement "ScopeStatementList". For example case 1: return true; case 2: { } case 3: ; But next example concerns me: case 1: case 2: return true; case 3: return false; After "case 1:" we see no statement at all. This conflicts with "CaseStatement" rule of documentation. But this is right D code. I think language reference must be updated.It's a "fall trough": https://en.wikipedia.org/wiki/Switch_statement#Fallthrough
Aug 14 2014
On Thursday, 14 August 2014 at 16:01:05 UTC, Baz wrote:On Thursday, 14 August 2014 at 13:19:36 UTC, Sergey Kozyr wrote:It's a fall trough but it is not the reason why it does works. It does because (as Daniel already mentioned) a case is a valid statement, therefore a case following other case is a totally valid statement. for example: case 1: case 2: return true; There are three statements. One which must be followed by another (case keyword) and another by an expression (return keyword). It is not even a special-case in the switch in C language. The switch keyword accept a expression constant as argument and must be followed by a statement, so: switch(1) return 0; is valid C code and no standard-compliant compiler must give an error about that. The fact we can do: switch(E) { case 1: ... break; case 2: .... break; default: ... break; } That's why compound-statement is a statement too (which switch does accept same reason why break keyword is needed)Sorry for previous message. Once again: I was reading D language reference and found some issue with "case ... :" statement specifications. Documentation http://dlang.org/statement#CaseStatement says that after case 1: must be non-empty statement "ScopeStatementList". For example case 1: return true; case 2: { } case 3: ; But next example concerns me: case 1: case 2: return true; case 3: return false; After "case 1:" we see no statement at all. This conflicts with "CaseStatement" rule of documentation. But this is right D code. I think language reference must be updated.It's a "fall trough": https://en.wikipedia.org/wiki/Switch_statement#Fallthrough
Aug 14 2014
On Thursday, 14 August 2014 at 17:10:50 UTC, AsmMan wrote:On Thursday, 14 August 2014 at 16:01:05 UTC, Baz wrote:I totally agree. I just wanted to mention the technical name.On Thursday, 14 August 2014 at 13:19:36 UTC, Sergey Kozyr wrote:It's a fall trough but it is not the reason why it does works. It does because (as Daniel already mentioned) a case is a valid statement, therefore a case following other case is a totally valid statement. for example: case 1: case 2: return true; There are three statements. One which must be followed by another (case keyword) and another by an expression (return keyword). It is not even a special-case in the switch in C language. The switch keyword accept a expression constant as argument and must be followed by a statement, so: switch(1) return 0; is valid C code and no standard-compliant compiler must give an error about that. The fact we can do: switch(E) { case 1: ... break; case 2: .... break; default: ... break; } That's why compound-statement is a statement too (which switch does accept same reason why break keyword is needed)Sorry for previous message. Once again: I was reading D language reference and found some issue with "case ... :" statement specifications. Documentation http://dlang.org/statement#CaseStatement says that after case 1: must be non-empty statement "ScopeStatementList". For example case 1: return true; case 2: { } case 3: ; But next example concerns me: case 1: case 2: return true; case 3: return false; After "case 1:" we see no statement at all. This conflicts with "CaseStatement" rule of documentation. But this is right D code. I think language reference must be updated.It's a "fall trough": https://en.wikipedia.org/wiki/Switch_statement#Fallthrough
Aug 14 2014
It's a fall trough but it is not the reason why it does works. It does because (as Daniel already mentioned) a case is a valid statement, therefore a case following other case is a totally valid statement. for example: case 1: case 2: return true; There are three statements. One which must be followed by another (case keyword) and another by an expression (return keyword).I agree that this is a valid D language construction. But documentation says that statement "case 1:" must be followed by any statement except other "case" or "default". Let's open doc http://dlang.org/statement#CaseStatement You see that "case ArgumentList :" is followed by "ScopeStatementList" (http://dlang.org/statement#ScopeStatementList) which is a list of any statements except CaseStatement or CaseRangeStatement or DefaultStatement. This rule conflicts with actual D language compiler.
Aug 15 2014
On Fri, 15 Aug 2014 19:46:07 +0000 Sergey Kozyr via Digitalmars-d <digitalmars-d puremagic.com> wrote:Let's open doc http://dlang.org/statement#CaseStatementand we'll find some more bugs there: CaseStatement: case ArgumentList : ScopeStatementList ArgumentList: AssignExpression AssignExpression , AssignExpression , ArgumentList AssignExpression: ConditionalExpression ConditionalExpression =3D AssignExpression ConditionalExpression +=3D AssignExpression ... and so on. so we can see that things like 'case n+=3D5:' should be allowed, while they are not.
Aug 15 2014
On 08/16/2014 12:21 AM, ketmar via Digitalmars-d wrote:so we can see that things like 'case n+=5:' should be allowed, while they are not.What is the problem? This passes DMD's parser.
Aug 15 2014
On Sat, 16 Aug 2014 01:31:42 +0200 Timon Gehr via Digitalmars-d <digitalmars-d puremagic.com> wrote:What is the problem? This passes DMD's parser.that is the problem: it shouldn't. this has no sense, and it's easy to fix this in grammar itself.
Aug 15 2014
On 08/16/2014 01:41 AM, ketmar via Digitalmars-d wrote:On Sat, 16 Aug 2014 01:31:42 +0200 Timon Gehr via Digitalmars-d <digitalmars-d puremagic.com> wrote:That's not what you said. On 08/16/2014 12:21 AM, ketmar via Digitalmars-d wrote:What is the problem? This passes DMD's parser.that is the problem: it shouldn't.and we'll find some more bugs there: ... so we can see that things like 'case n+=5:' should be allowed, while they are not.this has no sense, and it's easy to fix this in grammar itself.There is nothing to be 'fixed'. The code is still rejected when it is analysed.
Aug 15 2014
On Sat, 16 Aug 2014 02:20:27 +0200 Timon Gehr via Digitalmars-d <digitalmars-d puremagic.com> wrote:that's what i mean. ok, i should write it clear.That's not what you said.What is the problem? This passes DMD's parser.that is the problem: it shouldn't.There is nothing to be 'fixed'. The code is still rejected when it is=20 analysed.there is no sense to accept such code in parser anyway, and it can be easily fixed in grammar. ok, there is some sense with overloaded opAssign() and friends, but such code is awful and i believe that there is no sane reasons to allow such abomination.
Aug 15 2014
Also two more errors in documentation: 1. One member of an anonymous enum On page http://dlang.org/enum.html in "Manifest Constants" section there is an example of anonymous enum with a single member. But top rules on the same page don't have description of this case. Rules says that members are always enclosed with braces '{' and '}'. I think documentation must be updated. 2. Functions with "in" and "out" contracts On function declaration page http://dlang.org/function.html there is mention of "in" keyword with some code block and "out" block with some arguments and code block. This documentation page doesn't describe what this "in" and "out" sections mean. It's impossible to understand that these blocks are called "contracts". I downloaded DMD sources to find test where this contracts are described. I this this page need a link to "Contracts" documentation (http://dlang.org/contracts.html).
Aug 18 2014
On Monday, 18 August 2014 at 09:36:39 UTC, Sergey Kozyr wrote:Also two more errors in documentation: ...Check the list of bugs that I've already filed here: https://issues.dlang.org/show_bug.cgi?id=10233. If you find one that hasn't been filed, file it and add "spec" to the "Keywords" field and "10233" to the "Blocks" field. I plan on updating or rewriting a lot of the language specification based on these issues, so any that you identify will help me make the specification more accurate.
Aug 18 2014
On Monday, 18 August 2014 at 17:54:07 UTC, Brian Schott wrote:On Monday, 18 August 2014 at 09:36:39 UTC, Sergey Kozyr wrote:I've created three issues in bug tracker: 13326, 13327, 13328. As far as I can see these issues could be fixed with pull requests to github repository https://github.com/D-Programming-Language/dlang.org . Am I right?Also two more errors in documentation: ...Check the list of bugs that I've already filed here: https://issues.dlang.org/show_bug.cgi?id=10233. If you find one that hasn't been filed, file it and add "spec" to the "Keywords" field and "10233" to the "Blocks" field. I plan on updating or rewriting a lot of the language specification based on these issues, so any that you identify will help me make the specification more accurate.
Aug 18 2014
One more documentation issue. I've took sample from http://dlang.org/template.htmlinterface Addable(T) { final R add(this R)(T t) { return cast(R)this; // cast is necessary, but safe } } class List(T) : Addable!T { List remove(T t) { return this; } } void main() { auto list = new List!int; list.add(1).remove(1); // ok }I want to pay attention at line 9:class List(T) : Addable!TAs ClassDeclaration rule (http://dlang.org/class.html#ClassDeclaration) says after ':' you can see list of base classes. But "BaseClassList" rule allows only Identifier separated with comma. But here we have TemplateInstance instead of Identifier. This sample code is compiled by DMD2 compiler (but interface must be replaced with class previously). So I think specification must be updated in "SuperClass" and "Interface" rules.SuperClass: Identifier TemplateInstance Interface: Identifier TemplateInstanceDo you want me to create a bug under issue 10233?
Aug 20 2014
One more thing in specification. "AutoDeclarationX" rule (http://dlang.org/declaration.html#AutoDeclarationX) seems broken.AutoDeclarationX: Identifier = TemplateParameters Initializer AutoDeclarationX , Identifier TemplateParameters = InitializerIn second line equal sign is between "Identifier" and "TemplateParameters". While in third line equal sign is between "TemplateParameters" and "Initializer". I think second line contains error. Do you want me to create a bug at issues.dlang.org?
Aug 20 2014