Skip to content

Cannot return with foreach opApply from constructor at compile-time #21502

Open
@ntrel

Description

@ntrel
struct NumberType
{
    int num;

    int opApply(scope int delegate(int) dg)
    {
        int result = dg(num);
        return result;
    }
}

struct Problem {
    int value;

    this(int val) {
        auto nt = NumberType(18);

        foreach (int number; nt)
        {
            return;
        }
    }
}

auto compile_time_var = Problem(1); // error

void f() {
    auto runtime_var = Problem(1); // ok
}
Error: variable `__capture` cannot be read at compile time

From https://forum.dlang.org/post/[email protected].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions