Fix issue 22298 - Nested function's scope parameters can be assigned to variables in enclosing function#13530
Conversation
|
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#13530" |
|
This is a memory safety issue, it should probably go to stable |
| if (va && | ||
| (va.enclosesLifetimeOf(v) && !(v.storage_class & (STC.parameter | STC.temp)) || | ||
| if (va && !va.isDataseg() && | ||
| (va.enclosesLifetimeOf(v) && !(v.storage_class & STC.temp) || |
There was a problem hiding this comment.
Is the check for STC.temp still necessary?
There was a problem hiding this comment.
Maybe not, let's see what the test suite says.
There was a problem hiding this comment.
std/datetime/systime.d(9085): Error: scope variable `__tup794` assigned to `foundTZ` with longer lifetime
Looks like it's still needed for tuple lowering.
8352b22 to
dbfecff
Compare
…to variables in enclosing function
dbfecff to
8722687
Compare
In the initial implementation of lifetimes (#5972), a
__gsharedcounter was added that was incremented whenever aVarDeclarationwas created. This is supposed to give a lexical order to local variables, but it fails because there are multiple stages whereVarDeclarationsare created:FuncDeclarationmixinare created during function body semanticSpecial cases were added to
VarDeclaration.enclosesLifetimeOf(VarDeclaration v), where temporaries were compared using line and column number, and parameters assumed thatlifetime(parameter) > lifetime(local)always holds. Of course, this can fail when the parameter is from a nested function, and the local is in the enclosing function. It also doesn't account formixin:I made the sequence counter increment during symbol semantic of the
VarDeclarationinstead of in the constructor, and moved the counter to theglobalstruct so it can be reset easier. This is still hacky and not how I want to see lifetimes implemented, but it'll do for now.