fix #21409 - Closure not created for default arguments of a static function if called from a nested one#21453
Conversation
|
Thanks for your pull request and interest in making D better, @baz-bg! 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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
There was a problem hiding this comment.
See review.
- The current proposed fix will run semantic on the variable declaration from a scope different from where it is declared, which isn't sound from a semantic POV.
- There already exists a function for checking each variable reference in
arg, that islambdaCheckForNestedRef(arg, sc). I suggest to call this function after inlineCopy and resolveLoc. Propagate the return value if an error occurs (return true). - Split up tests into one per function, add a couple more different variations of the expression, such as
uint c0 = p0 + 1oruint c0 = fun(p0). I would also suggest an= thisexample, but it would appear dmd is unable to inline a field if its object has a member function (https://compiler-explorer.com/z/PrxjnzcE3) - Please target stable branch.
|
@ibuclaw ok, expected for the |
GDC doesn't use the front-end inliner, so it "just works" for that compiler. The use of If inlineCopy really is unavoidable for DMD, then it should ignore cost when it comes to copying default arguments. A separate issue can be used to track this though, not here. |
|
@baz-bg thanks for tackling this by the way. Default arguments is a bit of a "left behind" feature that has not been kept up to date with other development in the language - no safety, purity, nogc checks, etc. |
…nction if called from a nested one
Default args sema appears to be already run but sometimes it needs to be recontextualized