Thread overview
[Issue 8312] New: Too many error messages with a writeln of fixed size array
Jul 19, 2012
Kenji Hara
Jul 25, 2012
Kenji Hara
Jul 25, 2012
Kenji Hara
June 27, 2012
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


--- Comment #0 from bearophile_hugs@eml.cc 2012-06-27 09:39:16 PDT ---
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: -------
July 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8312



--- Comment #1 from bearophile_hugs@eml.cc 2012-07-08 15:04:14 PDT ---
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: -------
July 19, 2012
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


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-07-19 08:03:32 PDT ---
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: -------
July 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8312



--- Comment #3 from github-bugzilla@puremagic.com 2012-07-23 05:14:12 PDT ---
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 Merge pull request #1057 from 9rnsr/fix8312

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: -------
July 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8312



--- Comment #4 from bearophile_hugs@eml.cc 2012-07-25 07:24:39 PDT ---
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: -------
July 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8312



--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2012-07-25 08:02:42 PDT ---
(In reply to comment #4)
> 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: -------
July 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8312



--- Comment #6 from bearophile_hugs@eml.cc 2012-07-25 08:27:31 PDT ---
(In reply to comment #5)

> 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: -------
July 25, 2012
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


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2012-07-25 08:32:46 PDT ---
(In reply to comment #6)
> (In reply to comment #5)
> 
> > 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: -------