Skip to content

Improve Error Reporting: Make FS0072 less intimidating. #13013

@isaacabraham

Description

@isaacabraham

What

The following code leads to the following error:

let bar foo =
    let age = foo.Bar + 99
    age * 2

Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

Why

The message is overly verbose and complicated, using words like "indeterminate" and so on. In reality, all we're trying to say is: "I couldn't infer what this type is! Please add an annotation to tell me directly.". We could also provide some guidance to explain that the compiler cannot generally infer types from C#.

How

How about:

Unable to infer the type of foo. Please add a type annotation where foo is declared e.g. (foo:string).

or

It is unclear what type foo is. Please add a type annotation where foo is declared e.g. (foo:string).

We could also add some "background" information as well:

Unable to infer the type of foo. Please add a type annotation where foo is declared e.g. (foo:string). F# can only directly infer from member usage types that are defined in F#; if the type of foo is defined in a C# library (including anything from the Base Class Library e.g. string), F# will not be able to infer it based on a member access.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsFeature RequestTheme-Simple-F#A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions