[Issue 9430] New: short and byte implicitly cast to integer with binary arithmetic ops
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 30 19:52:48 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9430
Summary: short and byte implicitly cast to integer with binary
arithmetic ops
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: estewh at gmail.com
--- Comment #0 from stewart <estewh at gmail.com> 2013-01-31 14:52:44 EST ---
This fails to compile with the (equivalent) errors shown below:
void main() {
byte[3] val = [1, 2, 3];
byte[3] res2;
res[0] = val[1]+val[2]; // Error A
res[0] = val[1]-val[2]; // Error A
res[0] = val[1]/val[2]; // Error A
byte a1 = 1, a2 = 2;
byte result = a1+a2; // Error B
assert(result == 4);
result = a1;
result += a2; // OK
res[0] = val[1];
res[0] += val[2]; // OK
res[0] = val[1];
res[0] -= val[2]; // OK
res[0] = val[1];
res[0] *= val[2]; // OK
res[0] = val[1];
res[0] /= val[2]; // OK
}
Error A: cannot implicitly convert expression (cast(int)val[1UL] +
cast(int)val[2UL] ) of type int to byte.
Error B: cannot implicitly convert expression (cast(int)a1 + cast(int)a2 ) of
type int to byte.
Same is true for short[] arrays. It is true for +, -, *, /
NOTE: It is not the case for +=, -=, *= and /=. These work with byte and short
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list