Skip to content

New codefix provider to remove superflous binding for a Union case that has 0 fields.#14267

Merged
T-Gro merged 1 commit into
dotnet:mainfrom
T-Gro:14066-remove-quick-fix-for-adding-_-when-using-a-union-case-with-not-data
Nov 8, 2022
Merged

New codefix provider to remove superflous binding for a Union case that has 0 fields.#14267
T-Gro merged 1 commit into
dotnet:mainfrom
T-Gro:14066-remove-quick-fix-for-adding-_-when-using-a-union-case-with-not-data

Conversation

@T-Gro

@T-Gro T-Gro commented Nov 8, 2022

Copy link
Copy Markdown
Member

This kicks in when:

  • DU case has 0 fields and _ is used to pattern match
  • DU case has 0 fields and a named binding is used to pattern match

This builds on top of the new diagnostics added via #14055

CodeFixRemoveSuperflousBinding.mp4

@T-Gro T-Gro requested a review from a team as a code owner November 8, 2022 13:15
@T-Gro

T-Gro commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

/run fantomas

@github-actions

github-actions Bot commented Nov 8, 2022

Copy link
Copy Markdown
Contributor

@vzarytovskii

Copy link
Copy Markdown
Member

Huh, interesting that it failed to run fantomas. Need to check what's up with it

@edgarfgp

edgarfgp commented Nov 8, 2022

Copy link
Copy Markdown
Contributor

@T-Gro This looks awesome .

@kerams

kerams commented Nov 8, 2022

Copy link
Copy Markdown
Contributor

fsharp/fslang-suggestions#1094 would be a godsend in cases like this.

@T-Gro

T-Gro commented Nov 8, 2022

Copy link
Copy Markdown
Member Author

fsharp/fslang-suggestions#1094 would be a godsend in cases like this.

Oh yes, the relevant part of the tree when spotting a diagnostic (since it is available "at hand") could directly flow with it.
Right now, doing code fixes feels like scratching your left ear with your right leg :((

@edgarfgp

Copy link
Copy Markdown
Contributor

@T-Gro While I was adding the same quick fix for Rider. I notice that we can also use the same quick fix for FS3191: This literal pattern does not take arguments

type E =
     | A = 1
     | B = 2

 let (E.A x) = E.A

match E.A with
 | E.A x -> ()

let [<Literal>] A = 1

 match 1 with
 | (A x) -> ()

See JetBrains/resharper-fsharp#444 for more info

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.

5 participants