Bug 9107 – Value Range Analysis with uint and byte

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-02T12:24:00Z
Last change time
2013-11-24T22:03:39Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-12-02T12:24:19Z
Maybe this shows a problem of the Value Range Analysis, DMD 2.061alpha; void main(string[] args) { int a1 = 198 + args.length; // A run-time value. byte b1 = a1 % 200; // error, OK. uint a2 = 198 + args.length; ubyte b2 = a2 % 200; // no error, good. byte b3 = a2 % 200; // no error, bad. } test.d(3): Error: cannot implicitly convert expression (a1 % 200) of type int to byte
Comment #1 by yebblies — 2013-01-16T07:31:56Z
Range of a2 % 200: ( 0 to 200 ) Range of byte: ( -128 to 127 )
Comment #2 by yebblies — 2013-11-23T08:09:08Z
(In reply to comment #0) bearophile, you actually asked for this in issue 6000. void modulus_bug6000b() { long n = 10520; ubyte b = n % 10; } And it would've been rejected before VRP was implemented, so it's an ancient regression. https://github.com/D-Programming-Language/dmd/pull/2865
Comment #3 by github-bugzilla — 2013-11-24T22:03:09Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3d574175d021befdc991794f6b9361afcebd1bb8 Fix Issue 9107 - Value Range Analysis with uint and byte https://github.com/D-Programming-Language/dmd/commit/60441ae1d3b5197769514ff6632e46fee8d6cc87 Merge pull request #2865 from yebblies/issue9107 Issue 9107 - Value Range Analysis with uint and byte