[Issue 10594] New: Shaping the value range for immutable variables
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 10 04:41:34 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10594
Summary: Shaping the value range for immutable variables
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2013-07-10 04:41:33 PDT ---
(This is an improvement for Issue 10018 , but it's sufficiently different, so I
have opened a new issue.)
Currently this fails:
void main(in string[] args) {
immutable ushort x = args.length % 5;
immutable ubyte y = x;
}
dmd 2.064alpha gives:
temp.d(3): Error: cannot implicitly convert expression (x) of type
immutable(ushort) to immutable(ubyte)
Issue 10018 asks to propagate the range of immutable values, allowing that code
to compile with no errors.
- - - - - - - - - - -
This is an improvement of that idea:
void main(in string[] args) {
immutable size_t x = args.length;
assert(x < 256);
immutable ubyte y = x;
}
x is an immutable full-range size_t. But the assert should change the range of
x, allowing the successive assignment of y to be accepted.
- - - - - - - - - - -
Another possible idea is to allow code like:
void main(in string[] args) {
immutable size_t x = args.length;
if (x < 256) {
immutable ubyte y = x;
}
}
--
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