Skip to content

Pattern discard not allowed for union case that takes no data#14055

Merged
vzarytovskii merged 13 commits into
dotnet:mainfrom
edgarfgp:pattern-discard-not-allowed-for-union-case-that-takes-no-data
Oct 10, 2022
Merged

Pattern discard not allowed for union case that takes no data#14055
vzarytovskii merged 13 commits into
dotnet:mainfrom
edgarfgp:pattern-discard-not-allowed-for-union-case-that-takes-no-data

Conversation

@edgarfgp

@edgarfgp edgarfgp commented Oct 8, 2022

Copy link
Copy Markdown
Contributor

Fixes #13851

  • Put this behind a Lang preview

@edgarfgp edgarfgp closed this Oct 8, 2022
@edgarfgp edgarfgp reopened this Oct 8, 2022
@abelbraaksma

Copy link
Copy Markdown
Contributor

Great work! This also fixes the (closed with ‘resolution by design’) issues: #10204 and #1592.

@edgarfgp edgarfgp marked this pull request as ready for review October 9, 2022 10:48
@T-Gro

T-Gro commented Oct 10, 2022

Copy link
Copy Markdown
Member

/azp run

T-Gro
T-Gro previously approved these changes Oct 10, 2022
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@T-Gro T-Gro requested review from 0101, abonie and psfinaki October 10, 2022 08:43
@abonie

abonie commented Oct 10, 2022

Copy link
Copy Markdown
Member

Does this also cover function keyword? If so, it would make sense to add a unit test for that too

@edgarfgp

edgarfgp commented Oct 10, 2022

Copy link
Copy Markdown
Contributor Author

Does this also cover function keyword? If so, it would make sense to add a unit test for that too

Yes, it does, I have added more tests. Thanks for the review :)

@T-Gro T-Gro self-requested a review October 10, 2022 12:12
T-Gro
T-Gro previously approved these changes Oct 10, 2022
@vzarytovskii

vzarytovskii commented Oct 10, 2022

Copy link
Copy Markdown
Member

Does this also cover function keyword? If so, it would make sense to add a unit test for that too

Yes, it does, I have added more tests. Thanks for the review :)

Does it affect single-case unions when using them as a deconstruct syntax in functions? I.e. was it allowed before and is it now? My guess it shouldn't be affecting it, since they'll just be aliases?

@T-Gro

T-Gro commented Oct 10, 2022

Copy link
Copy Markdown
Member

It was working before (with _ discard), and was not working before when using named arg.
@edgarfgp : Can you please test what the new behavior is?

IMO it would be more consistent with other features it function arguments also show a warning if empty discard is used, but the opinion is not very strongly held.
image

@edgarfgp

edgarfgp commented Oct 10, 2022

Copy link
Copy Markdown
Contributor Author

Does it affect single-case unions when using them as a deconstruct syntax in functions? I.e. was it allowed before and is it now? My guess it shouldn't be affecting it, since they'll just be aliases?

Can you give an example in code to better illustrate your question :) ?

@T-Gro

T-Gro commented Oct 10, 2022

Copy link
Copy Markdown
Member

It was working before (with _ discard), and was not working before when using named arg. @edgarfgp : Can you please test what the new behavior is?

IMO it would be more consistent with other features it function arguments also show a warning if empty discard is used, but the opinion is not very strongly held. image

FYI the middle ones gives a FS0725 error (good), and it gives a fixing suggestion of replacing this with an underscore.
=> with this PR, would be good to NOT suggest putting in an underscore in case of empty field list.
(or the suggestion would rather remove the field alltogether, instead of replacing it with an underscore)

image

@edgarfgp

Copy link
Copy Markdown
Contributor Author

It was working before (with _ discard), and was not working before when using named arg. @edgarfgp : Can you please test what the new behavior is?

@T-Gro Ok let me add a test with your code sample :)

IMO it would be more consistent with other features it function arguments also show a warning if empty discard is used, but the opinion is not very strongly held. image

Agreed would be good to show the new warning error to make it consistent

FYI the middle ones gives a FS0725 error (good), and it gives a fixing suggestion of replacing this with an underscore. => with this PR, would be good to NOT suggest putting in an underscore in case of empty field list. (or the suggestion would rather remove the field alltogether, instead of replacing it with an underscore)

image

I guess this quick fix is not longer needed and a new/ or existing one suggesting remove the _ will be more useful
I would not be helpful with any VS tooling(quick fixes) as part of this PR

Any help is appreciated ;)

@vzarytovskii

Copy link
Copy Markdown
Member

I guess this quick fix is not longer needed and a new/ or existing one suggesting remove the _ will be more useful\nI would not be helpful with any VS tooling(quick fixes) as part of this PR

If you could just create a follow-up issue for removing exciting quick fix for this case and adding new one (remove discard) - we'll take care of it.

psfinaki
psfinaki previously approved these changes Oct 10, 2022

@psfinaki psfinaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hah I was scared to review this due to the number of files in the PR but then realized it's actually the analyzer fixing code in our repo :D

Thanks, great work - and especially great testing :)

Comment thread src/Compiler/FSComp.txt Outdated
@edgarfgp edgarfgp dismissed stale reviews from psfinaki and T-Gro via 286098a October 10, 2022 16:48
@edgarfgp

Copy link
Copy Markdown
Contributor Author

Hah I was scared to review this due to the number of files in the PR but then realized it's actually the analyzer fixing code in our repo :D

Thanks, great work - and especially great testing :)

Thanks, Happy to help

@vzarytovskii vzarytovskii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sweet, thanks a ton for it, Edgar, great job as usual!

@vzarytovskii vzarytovskii enabled auto-merge (squash) October 10, 2022 17:38
@vzarytovskii vzarytovskii merged commit 26bc85e into dotnet:main Oct 10, 2022
@edgarfgp

Copy link
Copy Markdown
Contributor Author

Sweet, thanks a ton for it, Edgar, great job as usual!

Thanks for the kind words :) . It always a pleasure to help F# to get better.

I’m already looking for the next issue to contribute

@psfinaki

Copy link
Copy Markdown
Contributor

@edgarfgp here are some ideas for you ;)

@abelbraaksma

Copy link
Copy Markdown
Contributor

Awesome that you tackled this long standing issue! 🥳

@edgarfgp

Copy link
Copy Markdown
Contributor Author

My pleasure @abelbraaksma , @NinoFloris might also like this one as he raised this issue as well 😀

@edgarfgp

Copy link
Copy Markdown
Contributor Author

@edgarfgp here are some ideas for you ;)

Thanks @psfinaki . I have most of those issues on my radar . I might ask for some technical guidance in some of them

@psfinaki

Copy link
Copy Markdown
Contributor

@edgarfgp sure - absolutely :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Pattern discard allowed for union case that takes no data

6 participants