dotnet / dotnet/fsharp

Ambiguous error message when type checking cannot determine type of a member

Open
#17,962 4 comments 0 reactions 0 assignees View on GitHub
Area-Diagnostics Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

**Repro steps**

Compile the snippet below:

```
type MyType =
{ MyField : string }
member this.Length = this.MyProperty.Length
member this.MyProperty = this.MyField
```

**Expected behavior**

Either:
* Program compiles successfully, because order of members is irrelevant.
* Program fails to compile with a correct error message, because order of members is relevant.

The expected error message in the second case would be:

```
The type 'MyType' does not define the field, constructor or member 'MyProperty'
```

**Actual behavior**

Compiler error message on `Length` property:

```
Program.fs(3,26): error FS0072: Lookup on object of indeterminate type...
```

This is an incorrect error message, because specifying the type of `this` does not fix the problem:

```
member this.Length = (this : MyType).MyProperty.Length // "Lookup on object of indeterminate type"
```

Note that Visual Studio suggests the following fix instead, which also does not work:

```
member (this: MyType).Length = this.MyProperty.Length // "Unexpected symbol '.' in member definition"
```

**Known workarounds**

Swap the order of the two members.

**Related information**

`Microsoft (R) F# Compiler version 12.8.401.0 for F# 8.0`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.