D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10910 - Duplicate error messages for array bounds errors
Summary: Duplicate error messages for array bounds errors
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: diagnostic, pull
: 12943 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-08-27 00:05 UTC by Don
Modified: 2024-12-13 18:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2013-08-27 00:05:32 UTC
The problem is in implicitConvTo() and implicitCastTo(). They call optimize(), but don't save the result.

optimize() can generate an error message, and return an ErrorExp when an array bounds error occurs.
It should be called BEFORE implicitConvTo, instead of inside it.
There are many cases of this, here are some examples:


void example()
{
   char c = "abcdef"[17];
   char[7] x = "abc"[12];
   int ww = "abc"["afds"[9]];
}

diag.d(4): Error: string index 17 is out of bounds [0 .. 6]
diag.d(4): Error: string index 17 is out of bounds [0 .. 6]
diag.d(5): Error: string index 12 is out of bounds [0 .. 3]
diag.d(5): Error: string index 12 is out of bounds [0 .. 3]
diag.d(5): Error: string index 12 is out of bounds [0 .. 3]
diag.d(5): Error: string index 12 is out of bounds [0 .. 3]
diag.d(6): Error: string index 9 is out of bounds [0 .. 4]
diag.d(6): Error: string index 9 is out of bounds [0 .. 4]
Comment 1 Don 2013-08-27 11:52:20 UTC
A couple more examples:

void bug10910(string y) {}

char example()
{
    char c = "abcdef"[17];
    char [7] x = "abc"[12];
    int ww = "abc"["dsdffg"[9]];
    int m = new int["as"[218]];
    auto aa = [0:0];
    aa.remove("dgffs"[356]);
    bug10910("sdgdf"[14..16]);
    return c;
}

The last line gives a particularly silly error message:

junk.d(80): Error: string slice [14 .. 16] is out of bounds
junk.d(80): Error: function junk.bug10910 (string y) is not callable using argument types (string)

Converting string to string is not exactly rocket science.
Comment 2 Kenji Hara 2015-01-16 07:44:23 UTC
*** Issue 12943 has been marked as a duplicate of this issue. ***
Comment 3 Dlang Bot 2023-06-13 18:45:31 UTC
@WalterBright updated dlang/dmd pull request #15314 "fix https://issues.dlang.org/show_bug.cgi?id=10910" fixing this issue:

- fix Issue 10910 - Duplicate error messages for array bounds errors

https://github.com/dlang/dmd/pull/15314
Comment 4 dlangBugzillaToGithub 2024-12-13 18:10:56 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

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

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