https://issues.dlang.org/show_bug.cgi?id=20674
--- Comment #4 from Paul Backus <[email protected]> --- (In reply to Dennis from comment #3) > (In reply to Walter Bright from comment #1) > > To do what this example asks for, data flow analysis would be required. This > > can be done, but is a large increase in implementation complexity and time > > to compile. > > This puzzles me. The examples don't contain a single branch or loop. Surely > you can infer scope here without creating a control-flow graph, right? Currently, in order to infer scope for `p`, you only need to check each usage of `p` for compliance with scope. To make the example (and others like it) work, you would need to recursively check each usage of any variable that `p` might be assigned to (like `p2`), and each usage of any variable that any of *those* variables might be assigned to, and so on, until you cannot find any new variables to check. What I've just described is a graph search problem. Whether the compiler actually builds an explicit control-flow graph or not, it amounts to the same thing. --
