Bug 22648 – [std.variant.Variant] Incorrectly written unittests
Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-01-03T23:39:23Z
Last change time
2022-01-04T00:42:19Z
Keywords
pull
Assigned to
No Owner
Creator
João Lourenço
Comments
Comment #0 by jlourenco5691 — 2022-01-03T23:39:23Z
The unittests written from the line 2055 to 2058 inclusive are wrong. Their logic is correct but they're passing by the wrong reasons. Currently, they fail because of the compile-time error "Error: has no effect". The result of the comparison is discarded and that results in an error, failing the '__traits(compiles, ...)' tests. This is unittest in question:
```
@system unittest
{
// check comparisons incompatible with AllowedTypes
Algebraic!int v = 2;
assert(v == 2);
assert(v < 3);
static assert(!__traits(compiles, {v == long.max;}));
static assert(!__traits(compiles, {v == null;}));
static assert(!__traits(compiles, {v < long.max;}));
static assert(!__traits(compiles, {v > null;}));
}
```
To correctly write the test, the value should be explicitly discarded by using a `cast(void)` in the whole expression, or by returning the result either by adding a `return` or transforming the lambda in an inline lambda `() =>`;
Comment #1 by dlang-bot — 2022-01-03T23:42:18Z
@iK4tsu created dlang/phobos pull request #8351 "Fix Issue 22648 - [std.variant.Variant] Incorrectly written unittests" fixing this issue:
- std.variant: Fix incorrectly written unittets
Fix Issue 22648 - [std.variant.Variant] Incorrectly written unittests
Signed-off-by: João Lourenço <[email protected]>
https://github.com/dlang/phobos/pull/8351
Comment #2 by dlang-bot — 2022-01-04T00:42:19Z
dlang/phobos pull request #8351 "Fix Issue 22648 - [std.variant.Variant] Incorrectly written unittests" was merged into master:
- 597d8e7b921833cdf041e0eaefc2806a0ff7f960 by João Lourenço:
std.variant: Fix incorrectly written unittets
Fix Issue 22648 - [std.variant.Variant] Incorrectly written unittests
Signed-off-by: João Lourenço <[email protected]>
https://github.com/dlang/phobos/pull/8351