Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new syntax] Support function ref Type Parameters for function pointer types #15243

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented May 17, 2023

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/qngjoxgihmcsvoprnanb@forum.dlang.org 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.

@dlang-bot
Copy link
Contributor

dlang-bot commented May 17, 2023

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: and Returns:)

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"

@ntrel ntrel changed the title [new syntax] Support function ref *Type Parameters* for function pointer types [new syntax] Support function ref Type Parameters for function pointer types May 17, 2023
@ntrel
Copy link
Contributor Author

ntrel commented May 29, 2023

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/upxvnjqqygosnluisjaw@forum.dlang.org

That problem is not solved by this pull alone.

Edit: Turns out we don't need scope there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants