3 days ago

On Monday, 30 June 2025 at 04:51:58 UTC, Rajesh wrote:

>

On Sunday, 29 June 2025 at 21:56:19 UTC, 0xEAB wrote:

>

On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote:

>

Is there a restriction that I cannot call return from foreach (opApply delegate) if it is executed at compile time?

To me this looks like a compiler bug where it runs into a wrong assumption once it finds the return statement in the foreach body and has to give up earlier.

Thanks for your reply. It looks like a bug to me as well, but I wanted to confirm with experts if it's a known issue or a limitation before I file a bug report.

I've now filed this:
https://github.com/dlang/dmd/issues/21502

3 days ago

On Monday, 30 June 2025 at 14:30:49 UTC, Manfred Nowak wrote:

>

On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote:

[...]

> struct Problem {
>     this(int val) {
>         foreach (int number; myType)
>             return;

[...]

>

Is there a restriction [...]

Yes.

'this' is not allowed to have a 'return' (15.13.0.2) ...
and to exit a 'foreach'-loop needs a 'break' (12.11.0.6).

So the compiler should not compile that program even for runtime.

return can be used to exit foreach (as can goto or throw), and return; can be used in a constructor. The latter I'll look at clarifying in the spec. The issue from this thread is just a limitation of CTFE.

10 hours ago

On Thursday, 3 July 2025 at 15:29:53 UTC, Nick Treleaven wrote:

>

On Monday, 30 June 2025 at 04:51:58 UTC, Rajesh wrote:

>

On Sunday, 29 June 2025 at 21:56:19 UTC, 0xEAB wrote:

>

On Sunday, 29 June 2025 at 13:06:38 UTC, Rajesh wrote:

>

Is there a restriction that I cannot call return from foreach (opApply delegate) if it is executed at compile time?

To me this looks like a compiler bug where it runs into a wrong assumption once it finds the return statement in the foreach body and has to give up earlier.

Thanks for your reply. It looks like a bug to me as well, but I wanted to confirm with experts if it's a known issue or a limitation before I file a bug report.

I've now filed this:
https://github.com/dlang/dmd/issues/21502

Thanks Nick

1 2
Next ›   Last »