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

fix #20645 - implement C++ style init-statement for if #20653

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

thewilsonator
Copy link
Contributor

@thewilsonator thewilsonator commented Jan 8, 2025

Sill to do

  • same thing but for switch

@thewilsonator thewilsonator added Review:Needs Changelog A changelog entry needs to be added to /changelog Review:WIP Work In Progress - not ready for review or pulling Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org Severity:New Language Feature labels Jan 8, 2025
@thewilsonator thewilsonator requested a review from ibuclaw as a code owner January 8, 2025 02:36
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @thewilsonator! 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

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

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#20653"

@thewilsonator thewilsonator changed the title fix #20645 - implement C++ style init-statement for `if fix #20645 - implement C++ style init-statement for if Jan 8, 2025
auto param = parseAssignCondition();
auto condition = parseExpression();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly question: why does the old code do parseAssignCondition followed by parseExpression? Does parseAssignCondition not eat tokens?

Unlike with for which (assuming its there) unconditionally parses a statement before the first semicolon, I think here we would need to determine if there is a semicolon present before deciding wether or not to sparse a statement or an expression here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseAssignCondition only eats tokens if it sits on a storage class. If it does not, it just returns null. It also does not parse an initializer.

AFAIU, in if(auto x = e), parseAssignCondition parses the auto x = part, and parseExpression parses the e part.

@Lars-Kristiansen
Copy link

Hello I'm baz from styx-lang. What you're doing is bad. What you need is "variable declaration" as a primary expression, but you guys keep on making special cases every each time Manu is upset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review:Needs Approval Review:Needs Changelog A changelog entry needs to be added to /changelog Review:Needs Spec PR A PR updating the language specification needs to be submitted to dlang.org Review:WIP Work In Progress - not ready for review or pulling Severity:New Language Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow comparison clause in if statements which contain statement-local declarations?
5 participants