January 03, 2022 [Issue 22648] New: [std.variant.Variant] Incorrectly written unittests | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=22648 Issue ID: 22648 Summary: [std.variant.Variant] Incorrectly written unittests Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: trivial Priority: P1 Component: phobos Assignee: nobody@puremagic.com Reporter: jlourenco5691@gmail.com 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 `() =>`; -- |
Copyright © 1999-2021 by the D Language Foundation