www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8312] New: Too many error messages with a writeln of fixed size array

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312

           Summary: Too many error messages with a writeln of fixed size
                    array
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is wrong D2 code (because currently D doesn't have variable length arrays,
and n is a run-time value):


import std.stdio;
void main() {
    uint n = 1;
    uint[n + 1] foo;
    writeln(foo);
}


I think it prints too many error messages (DMD 2.060alpha):

test.d(4): Error: variable n cannot be read at compile time
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: variable n cannot be read at compile time
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: variable n cannot be read at compile time
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: variable n cannot be read at compile time
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: variable n cannot be read at compile time
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u
test.d(4): Error: Integer constant expression expected instead of n + 1u

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 27 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312




A related case shown in D.learn (reduced):


import std.stdio: writeln;
void main() {
    immutable int[] A = [1];
    int[A.length] B;
    writeln(A);
    writeln(B);
}


DMD 2.060alpha:

temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length
temp.d(3): Error: Integer constant expression expected instead of (A =
[1]).length

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Platform|x86                         |All
         OS/Version|Windows                     |All



https://github.com/D-Programming-Language/dmd/pull/1057

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a3b4375047da593c3cd9c7d84751ee8733116303
fix Issue 8312 - Too many error messages with a writeln of fixed size array

https://github.com/D-Programming-Language/dmd/commit/c7f2cd0fad0d56219e4ff2a6b72f43f677b48452


Issue 8312 - Too many error messages with a writeln of fixed size array

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312




With this program:

import std.stdio;
void main() {
    uint n = 1;
    uint[n + 1] foo;
    writeln(foo);
}


DMD 2.060beta prints:

temp.d(4): Error: variable n cannot be read at compile time
temp.d(4): Error: Integer constant expression expected instead of n + 1u
temp.d(5): Error: template std.stdio.writeln does not match any function
template declaration
...\dmd2\src\phobos\std\stdio.d(1578): Error: template std.stdio.writeln(T...)
cannot deduce template function from argument types !()(_error_)

That I think is now acceptable.


Probably the errors of the second program too are improved:

import std.stdio: writeln;
void main() {
    immutable int[] A = [1];
    int[A.length] B;
    writeln(A);
    writeln(B);
}


but I can't verify the error messages because now it compiles and runs with
output:

[1]
[0]

So I have added a dependency to Issue 8400. Until Issue 8400 is undone I can't
verify this Issue 8312 is truly fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312





 Probably the errors of the second program too are improved:
 
 import std.stdio: writeln;
 void main() {
     immutable int[] A = [1];
     int[A.length] B;
     writeln(A);
     writeln(B);
 }
 
 but I can't verify the error messages because now it compiles and runs with
 output:
 
 [1]
 [0]
 
 So I have added a dependency to Issue 8400. Until Issue 8400 is undone I can't
 verify this Issue 8312 is truly fixed.
No, this is expected behavior. With the declaration `int[A.lehgth] B;`, A.length is interpreted to integer constant expression 1, then the type of B is compiled to int[1], it is _static_ array has 1 length, and the B's elements are initialized with int.init. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 25 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312






 No, this is expected behavior. With the declaration `int[A.lehgth] B;`,
 A.length is interpreted to integer constant expression 1, then the type of B is
 compiled to int[1], it is _static_ array has 1 length, and the B's elements are
 initialized with int.init.
If you think so then close down this bug (and maybe Issue 8400 too). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 25 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8312


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





 
 No, this is expected behavior. With the declaration `int[A.lehgth] B;`,
 A.length is interpreted to integer constant expression 1, then the type of B is
 compiled to int[1], it is _static_ array has 1 length, and the B's elements are
 initialized with int.init.
If you think so then close down this bug (and maybe Issue 8400 too).
OK, closed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 25 2012