-
-
Notifications
You must be signed in to change notification settings - Fork 739
[Issue 15320] eliminate 'static assert(__traits(compiles,..' #3807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks! Many of these could and should also be followed by an obvious |
@@ -765,14 +765,14 @@ unittest | |||
|
|||
// Issue #10130 - map of iota with const step. | |||
const step = 2; | |||
static assert(__traits(compiles, map!(i => i)(iota(0, 10, step)))); | |||
map!(i => i)(iota(0, 10, step)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(map!(i => i)(iota(0, 10, step)).walkLength == 10);
Some massive change (+- almost 1000 lines) to std.datetime appears to have snuck into the first commit. |
The changes are only snuck in in the sense that they're easy to miss. But there are a bunch of tests in std.datetime that use |
I don't see anything obviously wrong with the changes to std.datetime, but it is a lot of changes, so I could have missed something. |
Does anybody have an idea how to translate those in |
Technically, they're parentheses (or parens), not brackets ([] would be brackets), but regardless, the reason that the parens are there because the result of |
The ones in std.conv seem to either be verifying that something doesn't compiler (in which case, it wouldn't make any sense to change them) or checking something that's deprecated. The ones checking deprecated behavior should probably be moved into a deprecated unittest block. Similarly, most of those in std.traits test that something doesn't compile, and the ones that do can be changed to check the result like you've done with the rest. |
@jmdavis: It is not clear for me what the unittest bellow (from //With constructor
{
static struct S2
{
int i = 0;
static S2 opCall(int*){assert(0);}
static S2 opCall(int){assert(0);}
this(int i){this.i = i;}
}
S2 s = void;
static assert( __traits(compiles, emplace(&s, 1))); //(works, but deprecated)
static assert( __traits(compiles, emplace(&s, &i))); //(works, but deprecated)
emplace(&s, 1);
assert(s.i == 1);
} In |
Well, if you take the code inside the static assertions which is being tested to see whether it compiles and put it outside of the static assertion, you'll see the deprecation messages. For instance, if you change line# 4783 so that it's
then you get this:
A separate unittest block will have to be created for the tests that test deprecated functionality so that that unittest block can be marked as deprecated (otherwise, the deprecation message will always print out with the build). Unfortunately, that does mean some code duplication, but it'll go away once the deprecated functionality has been removed (along with the associated tests). My guess is that static assertions were used to avoid having to create deprecated unittest blocks, but deprecated unittest blocks would be much clearer.
I would say that line 4782 is redundant and that it should be removed. It's a compile time test for something that's then tested at runtime. And it's clearly not deprecated functionality, whereas line 4783 clearly is. My guess is that it's a copy-past error.
std.traits is all about compile time. None of its functionality is intended for runtime. Maybe Andrei would disagree, but I don't see any reason why changing those static assertions to runtime assertions would help anything. I'd just leave them as-is. |
That's the problem, I don't see the deprecation message, but the runtime assertion:
Line 4709: |
Hmmm. I'm definitely seeing the deprecation message, but the assertion is caused, because the struct in question specifically asserts that opCall isn't used with emplace, making this a very weird test. Certainly, you can't make that a runtime test as-is. That particular static assertion would need to done on a different struct with the same API but without the assertion. I'll make life simple here. Just don't worry about std.conv. The deprecation in question is almost two years old, so I'll just remove it and the offending tests in another PR which has to do with deprecations. This PR doesn't need to worry about it. |
This means that if there are no other comments, this PR is ready to be merged. |
Auto-merge toggled on |
The autotester seems to be stuck on building Win_32_64 |
[Issue 15320] eliminate 'static assert(__traits(compiles,..'
https://issues.dlang.org/show_bug.cgi?id=15320
There are still some occurrences remaining:
std/concurency.d
:spawn
s create threadsstd/conv.d
: couldn't figure it outstd/exception.d
: must stay,__traits(compiles
is called in a loop with different checked resultsstd/file.d
: file operationsstd/numeric.d
: don't know if it can/should be replacedstd/traits.d
: don't know howThe regex used for searching:
static\s+assert\s*\(\s*__traits\s*\(\s*compiles