[Issue 23835] Accessing variable outside nested function creates delegate even if it is static

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 12 13:27:31 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23835

--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
Looking at the compiler code, it seems that when `builder.perform()` is
encountered you have a CallExp that points to a DotIdExp (builder.perform).

To analyze it, the compiler first needs to semantically analyze `builder`. Once
it does that it also checks whether it is accessed from a nested function and
issues the error you are seeing. Between the analysis site of the call exp and
the analysis site of `builder` there are multiple calls so at the point where
`builder` is analyzed you have no idea whether it comes from a CallExp or a
DotIdExp or something else. As such, I think that supporting this case will
make the compiler code much uglier (passing a parameter down the call stack or
duplicating the code path that analyzes `builder` at at the point of the
analysis of the call expression) for a small gain in expressiveness.

Since the workaround is very easy, I think that this will most likely be a
WONTFIX.

--


More information about the Digitalmars-d-bugs mailing list