Skip to content

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

@bjornbaverfjord

Description

@bjornbaverfjord

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-LangService-CodeFixesCode fixes associated with diagnosticsBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No fields configured for Bug.

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions