Skip to content

False positive Open declaration can be removed when using extension for builder #16227

@BoundedChenn31

Description

@BoundedChenn31

Here is the half-done maybe CE
Repro steps

Here is the half-done maybe CE, extension for it that adds Bind-overload and usage attempt:

namespace Case1

module MaybeBuilder =
    
    type MaybeBuilder() =
        member inline _.Bind(optionValue: 'T option, f) =
            match optionValue with
            | None -> None
            | Some value -> f value

        member inline _.Return maybeNull =
           if isNull maybeNull then None else Some maybeNull

        member inline _.Delay f = f

        member inline _.Run f = f()

    let maybe = MaybeBuilder()


module MaybeBuilderExtension =
    
    open MaybeBuilder
    
    type MaybeBuilder with
        member inline _.Bind(maybeNull: 'T, f) =
            if isNull maybeNull then None else f maybeNull


module Usage =
    open MaybeBuilder
    open MaybeBuilderExtension // TODO: false positive

    let foo (s: string) =
        maybe {
            let! a = s
            return a
        }

Visual Studio marks open MaybeBuilderExtension as safe to remove.
2023-11-03_233943

However it would break compilation of code because we actually use Bind from extension.

Expected behavior

open for builder extension isn't marked as unnecessary.

Actual behavior

It's marked as unnecessary.

Known workarounds
.

Related information

.NET SDK: 7.0.403
Visual Studio 17.7.6

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions