static assert not printing out along the error diagnostic
SealabJaster
sealabjaster at gmail.com
Wed Jul 14 06:10:50 UTC 2021
On Wednesday, 14 July 2021 at 05:59:19 UTC, SealabJaster wrote:
> I've ran into this rarely. At a guess, it seems something
> triggers the compiler to either evaluate something in
> non-lexical order; doesn't realise it needs to error out at the
> static assert instead of doing it later, or maybe it somehow
> ends up gagging the more relevant static assert error.
To put this more coherently, I think it's to do with the fact the
compiler sometimes doesn't immediately stop compilation on error,
usually so it can try to produce even more errors to help aid you.
So it might be storing the `static assert` error, chokes on
`doWork` since `ResultType` isn't defined in this case, and for
some odd reason just completely drops the `static assert`:
```d
// Obviously this isn't valid D, but mostly to show what I think
happens.
struct MyType!
{
// `else` branch does not define a `ResultType`
//
// Compiler sees this static assert, goes into 'error
collection' mode I guess we could call it.
static assert(false, "bad type");
// Error collection mode sees that `ResultType` isn't defined.
// But for some reason, it chokes up, and doesn't produce the
static assert error in the output.
ResultType doWork(){...}
}
```
More information about the Digitalmars-d-learn
mailing list