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 nested variant type spreads #7080

Merged
merged 4 commits into from
Oct 7, 2024
Merged

Conversation

zth
Copy link
Collaborator

@zth zth commented Oct 5, 2024

This fixes the issues outlined here: #6721 (review)

Caveat: It does seem to change the parsing recovery behavior in lists: https://github.com/rescript-lang/rescript-compiler/compare/fix-nested-variant-type-srpeads?expand=1#diff-f1835faf75e20ea1a0421cb16ab6be3e9556c0d4651f05789be6b26f1903f998L27-R38

Not sure what to think about that.

cc @tsnobip @glennsl

@zth zth requested a review from tsnobip October 6, 2024 10:18
Copy link
Contributor

@tsnobip tsnobip left a comment

Choose a reason for hiding this comment

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

it makes sense that giving dotdotdot a new meaning in the syntax can lead to some corner cases for its existing use, but so far I find the trade-off acceptable, if we bump into more issues, we could try to refine the behavior of dotdotdot for lists.

Could you rebase the PR?

@@ -171,7 +171,8 @@ let is_structure_item_start = function
let is_pattern_start = function
| Token.Int _ | Float _ | String _ | Codepoint _ | Backtick | True | False
| Minus | Plus | Lparen | Lbracket | Lbrace | List | Dict | Underscore
| Lident _ | Uident _ | Hash | Exception | Percent | Module | At ->
| DotDotDot | Lident _ | Uident _ | Hash | Exception | Percent | Module | At
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah same fix as for dicts! It smelled the same ^^

I'm not sure what to parse here when looking at ",".
Did you forget a `}` here?
Copy link
Contributor

Choose a reason for hiding this comment

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

to be honest, the former error message was not great, the newer one is not better, but I'm not even sure what should be the error message here.

@zth zth force-pushed the fix-nested-variant-type-srpeads branch from e98952d to 8a4bf5b Compare October 7, 2024 09:24
@zth
Copy link
Collaborator Author

zth commented Oct 7, 2024

@tsnobip I did not add DotDotDot to "atomic pattern start". Do you think that's needed?

@tsnobip
Copy link
Contributor

tsnobip commented Oct 7, 2024

@tsnobip I did not add DotDotDot to "atomic pattern start". Do you think that's needed?

@zth Did you try adding it to the atomic pattern start ? Did it change the tests for lists too? Intuitively I'd say it's not atomic because it needs at least some argument, but to be honest I'm not sure what it really means.
FYI, it's used only in one place here:
https://github.com/rescript-lang/rescript-compiler/blob/b0356023e24aa3e831f41857ab31729291fdc8b2/compiler/syntax/src/res_core.ml#L1141-L1148
And the only differences between atomic and not atomic pattern starts are the following tokens that are non-atomic pattern starts:

  | Minus | Plus | True | False | Hash  | Module | At | Float _ | DotDotDot 

True and False definitely look atomic to me for example. Some cleanup would be nice here.

Maybe Maxim knows better about the real semantics and origin of atomic pattern starts? I couldn't find his github handle.

@zth zth merged commit 574d4ac into master Oct 7, 2024
20 checks passed
@zth zth deleted the fix-nested-variant-type-srpeads branch October 7, 2024 13:41
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