Bug 8312 – Too many error messages with a writeln of fixed size array

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-27T09:39:00Z
Last change time
2012-07-25T08:32:46Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
bearophile_hugs
Depends on
8400

Comments

Comment #0 by bearophile_hugs — 2012-06-27T09:39:16Z
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
Comment #1 by bearophile_hugs — 2012-07-08T15:04:14Z
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
Comment #2 by k.hara.pg — 2012-07-19T08:03:32Z
Comment #3 by github-bugzilla — 2012-07-23T05:14:12Z
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
Comment #4 by bearophile_hugs — 2012-07-25T07:24:39Z
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.
Comment #5 by k.hara.pg — 2012-07-25T08:02:42Z
(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.
Comment #6 by bearophile_hugs — 2012-07-25T08:27:31Z
(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).
Comment #7 by k.hara.pg — 2012-07-25T08:32:46Z
(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.