Skip to content

Only expand positional records if the DataCon application is fully saturated #4586

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

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

Conversation

ozkutuk
Copy link
Collaborator

@ozkutuk ozkutuk commented May 10, 2025

Fixes #4564.

"Positional record expansion" only makes sense if the constructor application has all the required arguments provided, otherwise invalid code is generated as demonstrated in the linked issue. This PR augments the collected records with "saturation" information, so that unsatured applications can be filtered out during the code action generation.

(cc: @jetjinser, do you mind taking a look into this, as you were the author of #4447)

@ozkutuk ozkutuk changed the title Only expand record wildcards if the DataCon application is fully saturated Only expand positional records if the DataCon application is fully saturated May 10, 2025
Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for taking care of this!

Comment on lines +181 to +182
RecordInfoApp _ (RecordAppExpr Unsaturated _ _) -> False
_ -> True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it is only two cases, maybe we should be exhaustive?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe I misunderstood you, but I can't see how it is only two cases. This is what I come up with if I try to make this fully exhaustive:

    isConvertible :: RecordInfo -> Bool
    isConvertible = \case
      RecordInfoApp _ (RecordAppExpr Unsaturated _ _) -> False
      RecordInfoApp _ (RecordAppExpr Saturated _ _) -> True
      RecordInfoPat {} -> True
      RecordInfoCon {} -> True

I personally find this a bit too verbose, but if that's the style the codebase favors, I would be happy to change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is just my preference, but since you are maintaining the plugin right now, your opinion matters more than mine in style preferences.

Also, thought it would be two, not 4, so yeah, that's more verbose than anticipated.

@fendor fendor requested a review from michaelpj May 10, 2025 15:13
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.

Code action "expand positional record" produces invalid code.
2 participants