std.range.package - add asserts/static asserts for unused variables in unittests#5635
Conversation
|
Thanks for your pull request, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
Yes, that's why tooling wins. |
|
@wilzbach many of those are used in traits compiles statements and static asserts. Looks like dscanner misses the case were variables are used at compile time tests. |
|
I welcome the added |
|
@JackStouffer they get rid of useless assignments. |
andralex
left a comment
There was a problem hiding this comment.
static assert ain't bad but a better test also make sure the result of the compiled code is as expected.
std/range/package.d
Outdated
| int[4] testArr = [1,2,3,4]; | ||
| //just checking it compiles | ||
| auto s = testArr[].stride(2); | ||
| static assert(__traits(compiles,testArr[].stride(2))); |
There was a problem hiding this comment.
better yet also assert it equals [1, 3].
There was a problem hiding this comment.
doing so may cause a GC allocation which makes the unittest drop the @nogc. Since the test is not public, maybe it would be better to leave it like this
There was a problem hiding this comment.
@nogc unittest
{
static immutable result = [1, 3];
auto s = testArr[].stride(2);
assert(s.equal(result));
}There was a problem hiding this comment.
yah there's a solution to everything - just ask around and mess with things!
std/range/package.d
Outdated
| // Make sure bug 3311 is fixed. ChainImpl should compile even if not all | ||
| // elements are mutable. | ||
| auto c = chain( iota(0, 10), iota(0, 10) ); | ||
| static assert(__traits(compiles, chain( iota(0, 10), iota(0, 10)))); |
There was a problem hiding this comment.
same here, assert not only it compiles but it yields a range as expected.
std/range/package.d
Outdated
| immutable(Foo)[] a; | ||
| immutable(Foo)[] b; | ||
| auto c = chain(a, b); | ||
| static assert(__traits(compiles, chain(a, b))); |
Yeah quite likely - there's no semantic phase at DScanner. |
20bbe87 to
07bb328
Compare
07bb328 to
1e44763
Compare
|
@andralex I think this is good to go now |
Most likely I missed some.