Bug 9252 – Wrong error message in a case of alias-this-array indexing with double value
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-01-01T08:53:01Z
Last change time
2018-10-23T12:22:59Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-01-01T08:53:01Z
This program shows a correct error message:
void main() {
int[5] a;
double i = 0;
a[i] = 0;
}
test.d(4): Error: cannot implicitly convert expression (i) of type double to uint
While this code in a similar case shows a not good error message:
struct Foo {
int[] data = [0];
alias this = data;
}
void main() {
Foo a;
int i1 = 0;
a[i1] = 10; // OK.
assert(a.data[0] == 10);
double i2 = 0;
a[i2] = 20; // Error.
}
DMD 2.061alpha gives:
test.d(11): Error: no [] operator overload for type Foo
Comment #1 by razvan.nitu1305 — 2018-10-23T12:22:59Z
dmd 2.081 shows:
Error: cannot implicitly convert expression i2 of type double to ulong
Which is the correct error. Closing as WORKSFORME