dmd
dmd copied to clipboard
[new syntax] Support `function` `ref` Type Parameters for function pointer types
Fixes Issue 2753 - Cannot declare pointer to function returning ref.
This token ordering is consistent with function literals:
function RefOrAutoRefopt Typeopt ParameterWithAttributesopt FunctionLiteralBody2
https://dlang.org/spec/expression.html#function_literals
See https://forum.dlang.org/post/[email protected] for more on the grammar.
Alternatively, allowing Type function Parameters ref would also fix the issue, though that is less easy to see that the return value is actually a reference when looking at the return type. Also there is no precedent for that AIUI in the grammar, though the compiler does use this ordering in error messages despite it being invalid syntax.
Another option would be Type ref function Parameters, but again, no precedent for that.
This pull implements support for 'leading function' pointer types in most places, ~~but not for a declaration at module scope yet~~.
Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:
- My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
- My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
- I have provided a detailed rationale explaining my changes
- New or modified functions have Ddoc comments (with
Params:andReturns:)
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
| Auto-close | Bugzilla | Severity | Description |
|---|---|---|---|
| ✓ | 2753 | enhancement | Cannot declare pointer to function returning ref |
Testing this PR locally
If you don't have a local development environment setup, you can use Digger to test this PR:
dub run digger -- build "master + dmd#15243"
Although this solves the ref problem, there is another syntax ambiguity with scope if we want to extend dip1000. See:
https://forum.dlang.org/post/[email protected]
That problem is not solved by this pull alone.
Edit: Turns out we don't need scope there.