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

Desugar patterns #6099

Merged
merged 4 commits into from
Nov 27, 2023
Merged

Desugar patterns #6099

merged 4 commits into from
Nov 27, 2023

Conversation

mulias
Copy link
Contributor

@mulias mulias commented Nov 26, 2023

Traverse pattern ASTs and desugar two cases

  • Desugar optional record field default value expr. This expr might contain nodes that need to be desugared, such as binary operations. Failing to desugar this expr can cause an internal panic later in canonicalization.

  • Discard SpaceBefore and SpaceAfter nodes so that patterns can be destructured over multiple lines. Keeping these nodes can cause an internal panic later in canonicalization. Fixes Problem compiling Tutorial example: Optional Record Fields #5653.

@mulias mulias force-pushed the desugar-patterns branch 2 times, most recently from 05c07e3 to 5854420 Compare November 26, 2023 14:52
ayazhafiz
ayazhafiz previously approved these changes Nov 26, 2023
Comment on lines 575 to 576
// Find `OptionalField`s and desugar the default value exprs. Also discard `SpaceBefore` and
// `SpaceAfter` nodes so that patterns can be destructured over multiple lines.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Slight preference for removing this comment. I think it's pretty clear what the function does from the body, and it's pretty likely it will grow out of date if the logic is ever updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, removed

@@ -1231,6 +1231,54 @@ mod test_can {
assert_eq!(problems, Vec::new());
}

#[test]
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

You might consider asserting on the can AST (you could print it back using

//! Pretty-prints the canonical AST back to check our work - do things look reasonable?
) or adding tests in test_mono to assert the code generation is as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the tests to test_mono because that seemed simpler.

Traverse pattern ASTs and desugar two cases

- Desugar optional record field default value expr. This expr might
  contain nodes that need to be desugared, such as binary operations.
  Failing to desugar this expr can cause an internal panic later in
  canonicalization.

- Discard SpaceBefore and SpaceAfter nodes so that patterns can be
  destructured over multiple lines. Keeping these nodes can cause an
  internal panic later in canonicalization. Fixes [1].

[1]: roc-lang#5653.
@ayazhafiz ayazhafiz merged commit 7fdb593 into roc-lang:main Nov 27, 2023
14 checks passed
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.

Problem compiling Tutorial example: Optional Record Fields
2 participants