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

FS0760 suggests change that breaks code (Quick Action) #6381

Open
Tracked by #15408
bjornbaverfjord opened this issue Mar 27, 2019 · 2 comments
Open
Tracked by #15408

FS0760 suggests change that breaks code (Quick Action) #6381

bjornbaverfjord opened this issue Mar 27, 2019 · 2 comments
Labels
Area-LangService-CodeFixes Code fixes associated with diagnostics Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@bjornbaverfjord
Copy link

This working code triggers:

FS0760: It is recommended that objects supporting the IDisposable interface are created using the syntax 'new Type(args)', rather than 'Type(args)' or 'Type' as a function value representing the constructor, to indicate that resources may be owned by the generated value

open System.Media
open System.IO
let s = [|1uy; 2uy|]
let sp = new SoundPlayer(MemoryStream s) 
sp.PlaySync()

After applying suggested change in Visual Studio the result is:

open System.Media
open System.IO
let s = [|1uy; 2uy|]
let sp = new SoundPlayer(new MemoryStream s) 
sp.PlaySync()

This code is broken and gives compile error:

error FS0010: Unexpected symbol ')' in expression

The relevant source is here:
CodeFix/AddNewKeywordToDisposableConstructorInvocation.fs

Microsoft Visual Studio Community 2017
Version 15.9.10
VisualStudio.15.Release/15.9.10+28307.557
Microsoft .NET Framework
Version 4.7.03190
redsquiggle

@cartermp
Copy link
Contributor

The correct approach here is the code fix needs to understand that curried parameters will cause an ambiguity and add parentheses:

MemoryStream s ->new MemoryStream(s)

@cartermp cartermp modified the milestones: 16.1, 16.2 Apr 23, 2019
@cartermp cartermp modified the milestones: 16.2, Backlog Apr 30, 2019
@dsyme dsyme added the Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. label Aug 26, 2020
@dsyme dsyme added Area-LangService-CodeFixes Code fixes associated with diagnostics and removed Area-LangService-API labels Apr 5, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
@psfinaki psfinaki mentioned this issue Jun 15, 2023
85 tasks
@brianrourkeboll
Copy link
Contributor

I believe that this was fixed by #18179.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-LangService-CodeFixes Code fixes associated with diagnostics Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Status: New
Development

No branches or pull requests

5 participants