D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4939 - Some compile-time length tests of array concats
Summary: Some compile-time length tests of array concats
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: accepts-invalid, diagnostic, pull
Depends on:
Blocks:
 
Reported: 2010-09-25 08:50 UTC by bearophile_hugs
Modified: 2024-12-13 17:53 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-09-25 08:50:01 UTC
This is a wrong D2 program, because the lengths of the arrays don't match:


// Program #1
void main() {
    int[2] a1;
    int[3] a2;
    int[6] result;
    result[] = a1 ~ a2;
}


It compiles with no errors, because a1~a2 produces a dynamic array, despite its length is determined at compile-time. I'd like the compile to catch this bug at compile-time.

The situation in Program #1 is not so common, but a little more refined implementation of the same kind of tests may catch at compile-time more common cases, like:


// Program #2
void main() {
    int[] a1 = new int[2];
    int[] a2 = new int[3];
    int[6] result;
    result[] = a1 ~ a2; // Error
    a1 ~= 0;
    result[] = a1 ~ a2;
}


// Program #3
void main() {
    int[] a1 = new int[2];
    int[] a2 = new int[3];
    int[] result = new int[6];
    result[] = a1 ~ a2; // Error
}
Comment 1 Kenji Hara 2015-06-12 12:11:13 UTC
https://github.com/D-Programming-Language/dmd/pull/4741

It will make the Program #1 case error. Program #2 and #3 case are not in range, because they needs data flow analysis.
Comment 2 dlangBugzillaToGithub 2024-12-13 17:53:30 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18302

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB