Skip to content

Don't warn FS3559 when obj is inferred if the obj is expected there #16454

Description

@cmeeren

The new FS3559 triggers where I think it should not. Consider this:

let foo (x: obj) = ()
foo null

It triggers on null:

A type has been implicitly inferred as 'obj', which may be unintended. Consider adding explicit type annotations. You can disable this warning by using '#nowarn "3559"' or '--nowarn:3559'.

But the type of the argument is explicitly obj, so it doesn't make sense that it should trigger here.

Another slightly more realistic example:

let invokeStatic (mi: System.Reflection.MethodInfo) =
    mi.Invoke(null, [||])

MethodInfo.Invoke expects obj as its first argument, so F# inferring obj here should not cause a warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.help wanted

    Type

    No fields configured for Bug.

    Projects

    Status
    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions