5

Improve Error Reporting: Make FS0072 less intimidating. · Issue #13013 · dotnet/...

 2 years ago
source link: https://github.com/dotnet/fsharp/issues/13013
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

isaacabraham commented 8 days ago

edited

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.

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 about:

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

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.

jasiozet, enricosada, and reijerh reacted with thumbs up emoji

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK