digitalmars.D.bugs - [Issue 10755] New: 'has no effect in expression' error for return too with comma operator
- d-bugmail puremagic.com (81/81) Aug 04 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10755
http://d.puremagic.com/issues/show_bug.cgi?id=10755 Summary: 'has no effect in expression' error for return too with comma operator Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: accepts-invalid Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc With dmd 2.064alpha this code gives: void main() { 1; } test.d(2): Error: long has no effect in expression (1) - - - - - - - - - - - - This gives an error, commas are disallowed here: void main() { int[10] a; auto x = a[1, 2]; } test.d(3): Error: only one index allowed to index int[10u] - - - - - - - - - - - - This too gives errors: void main() { int[10, 20] a; } test.d(2): Error: found ',' when expecting ']' test.d(2): Error: no identifier for declarator int[10] test.d(2): Error: semicolon expected, not '20' test.d(2): Error: found ']' when expecting ';' following statement - - - - - - - - - - - - This is disallowed: void main() { int x = 1, 2; } test.d(2): Error: no identifier for declarator int test.d(2): Error: semicolon expected, not '2' - - - - - - - - - - - - This gives an error: void main() { int x; x = 1, 2; } test.d(3): Error: long has no effect in expression (2) - - - - - - - - - - - - While this code compiles with no errors nor warnings: int foo() { return 1, 2; // line 2 } int bar() { return foo(), 3; // line 5 } void main() { assert(bar() == 3); } Inside bar() there is a call to foo(). foo() is not pure, but inside foo() "1" is a pure expression (a literal), so for this program I suggest to generate an error at line 2, and disallow comma syntax at return points, but probably no warning at line 5: test.d(2): Error: int has no effect in expression (1) - - - - - - - - - - - - This generates an error: int foo() { return 1; } void main() { int x; x = foo(), 2; } test.d(6): Error: long has no effect in expression (2) So maybe it's right to generate an error at line 5 too. - - - - - - - - - - - - -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 04 2013