Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a test and check-support for positional params with a return type #4899

Merged
merged 2 commits into from
Feb 6, 2025

Conversation

danakj
Copy link
Contributor

@danakj danakj commented Feb 5, 2025

Functions with positional parameters omit any implicit or explicit parameter lists. This causes them to not have a pattern block, which crashes if there is a return type that needs to add to the pattern block.

Add a test covering this and handle it by having the ReturnTypeId handler peek at the node stack and conditionally add the missing pattern block. To do so it looks to see if the previous node is a IdentifierNameNotBeforeParams which implies it was not expecting a pattern (since there are no params) and thus the pattern block was not added to the stack.

Note that lambdas also allow functions to omit an identifier, which will need a pattern block on the stack for implicit parameters, explicit parameters or a return type, without seeing any IdentifierName-like parse nodes. To handle this, we will need to look for additional nodes in the future and add the missing pattern block to the stack - possibly for the FunctionInitializer, but the parse support needs to be created for lambdas first.

Functions with positional parameters omit any implicit or explicit
parameter lists. This causes them to not have a pattern block, which
crashes if there is a return type that needs to add to the pattern
block.

Add a test covering this and handle it by having the ReturnTypeId
handler peek at the node stack and conditionally add the missing pattern
block. To do so it looks to see if the previous node is a
`IdentifierNameNotBeforeParams` which implies it was not expecting a
pattern (since there are no params) and thus the pattern block was not
added to the stack.

Note that lambdas also allow functions to omit an identifier, which will
need a pattern block on the stack for implicit parameters, explicit
parameters or a return type, without seeing any IdentifierName-like
parse nodes. To handle this, we will need to look for additional nodes
in the future and add the missing pattern block to the stack - possibly
for the FunctionInitializer, but the parse support needs to be created
for lambdas first.
@danakj danakj force-pushed the positional-return branch from ce6ba4e to b728f4f Compare February 6, 2025 16:44
@danakj
Copy link
Contributor Author

danakj commented Feb 6, 2025

Reworded the commit description for the new approach as well, PTAL

@danakj danakj requested a review from zygoloid February 6, 2025 16:45
@danakj danakj added this pull request to the merge queue Feb 6, 2025
Merged via the queue into carbon-language:trunk with commit 7d6cd3d Feb 6, 2025
8 checks passed
@danakj danakj deleted the positional-return branch February 6, 2025 18:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants