On Wednesday, 22 November 2023 at 19:37:58 UTC, Paul Backus wrote:

This is a bug/limitation in the compiler. I couldn't find an existing report on issues.dlang.org, so I've reported it myself as [issue 24255][1].

Wow: It is a very concise bug example.

I tested with ```ldc``` ant it fails too.


For now, I think the best way to work around it is to specify the type in the lambda, as in `(int i) => i%2 == 0`.

agreed


The reason you see `void` is that when the compiler cannot figure out the type of a function literal, it treats it as a template function:

```d
static assert(__traits(isTemplate, i => i % 2 == 0));
```

And for silly historical reasons, when the compiler tries to determine the type of a template, it returns `void` instead of giving an error:

```d
template example() {}
static assert(is(typeof(example) == void)); // what??
```

Thanks Paul!!!



Reply via email to