D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20353 - -checkaction=context does not work well with const numbers
Summary: -checkaction=context does not work well with const numbers
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2019-11-04 21:24 UTC by Dennis
Modified: 2020-11-11 18:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dennis 2019-11-04 21:24:07 UTC
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 moonlightsentinel 2019-11-04 23:24:05 UTC
The second error was fixed as a side effect of https://github.com/dlang/druntime/pull/2846/
Comment 2 Dlang Bot 2019-11-05 01:58:45 UTC
@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 basile-z 2020-11-11 18:10:34 UTC
fixed by https://github.com/dlang/dmd/pull/11005