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

Declare and update return.value #366

Merged
merged 6 commits into from
Feb 13, 2023
Merged

Declare and update return.value #366

merged 6 commits into from
Feb 13, 2023

Conversation

edemaine
Copy link
Collaborator

Sequel to #364. I started writing documentation and then added a few intended features:

  • let return: T
  • return .= init
  • return++

Also cleans up the code in a single ReturnValue rule.

@edemaine edemaine temporarily deployed to build February 12, 2023 21:19 — with GitHub Actions Inactive
AfterReturnShorthand
WAssignmentOp
UpdateExpressionSymbol
__ Colon
Copy link
Contributor

Choose a reason for hiding this comment

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

This could pick up a Label on the following line, we may want to disallow __ and enforce same line or use a more specific rule.

@STRd6
Copy link
Contributor

STRd6 commented Feb 12, 2023

We may also be able to use the return type annotation of a function, if present, to set the default type annotation for the return value.

@edemaine edemaine temporarily deployed to build February 13, 2023 00:51 — with GitHub Actions Inactive
@edemaine edemaine temporarily deployed to build February 13, 2023 04:02 — with GitHub Actions Inactive
@edemaine
Copy link
Collaborator Author

We may also be able to use the return type annotation of a function, if present, to set the default type annotation for the return value.

Great idea! I implemented this, which involved improving the AST for types a bit. Not sure I got the best names for things (t is particularly annoying, because type is already taken). Feel free to suggest (or make) improvements.

source/parser.hera Outdated Show resolved Hide resolved
@edemaine edemaine temporarily deployed to build February 13, 2023 14:34 — with GitHub Actions Inactive
@edemaine
Copy link
Collaborator Author

4469fab prevents newlines before colons in a lot of cases. (I searched for all __ Colon and changed most of them — the only remaining case is ternary ?:.) This actually fixed a bunch of bugs with label parsing (see new tests in test/label.civet), and didn't seem to break any tests, so it's hopefully OK in practice. If needed, in the future, we could allow newlines before the colon if we then check for a space after the colon to ensure it's not a label.

@edemaine edemaine merged commit 42ff8b7 into main Feb 13, 2023
@edemaine edemaine deleted the return-declare branch February 13, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants