Bug 20353 – -checkaction=context does not work well with const numbers

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-04T21:24:07Z
Last change time
2020-11-11T18:10:34Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2019-11-04T21:24:07Z
When compiling with -checkaction=context: ```D void main() { const x = -1L; const y = -2L; assert(x == y); } ``` expected: -1 != -2 actual: assert(x == y) failed Also applies to floating points. I don't know why it fails to give context here. Making either x or y mutable makes it work. Also: ```D void main() { const long[1] x = [uint.max]; const long[1] y = [-1]; assert(x == y); } ``` expected: [4294967296] != [-1] actual: [-1] != [-1] This is because in core.internal.dassert: getPrintfFormat there is a check: static if (is(T == long)) This doesn't Unqual T so it doesn't hold when T == const(long), so it chooses the wrong format.
Comment #1 by moonlightsentinel — 2019-11-04T23:24:05Z
The second error was fixed as a side effect of https://github.com/dlang/druntime/pull/2846/
Comment #2 by dlang-bot — 2019-11-05T01:58:45Z
@MoonlightSentinel created dlang/dmd pull request #10535 "Fix Issue 20353 - -checkaction=context does not work well with const …" fixing this issue: - Fix Issue 20353 - -checkaction=context does not work well with const numbers https://github.com/dlang/dmd/pull/10535
Comment #3 by b2.temp — 2020-11-11T18:10:34Z