dotnet / dotnet/fsharp

Confusing error message when type stated by qualifying a field

Open
#7,396 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

When a record is created with one of the fields having a type qualifier, and an illegal field name that conflicts with a field in another record is used, then the resulting error message is confusing.

**Repro steps**

```
type TypeOne = { NumberOne: int; StringOne: string }
type TypeTwo = { NumberTwo: int; StringTwo: string }

// Type inference must be used.
// Is ok.
let testA () =
{ // ERROR : This record contains fields from inconsistent types
NumberOne = 1
StringTwo = "two"
}

// Forcing type.
// Is ok.
let testB () : TypeOne =
{
NumberOne = 1
StringTwo = "two" // ERROR : The type 'TypeOne' does not contain a field 'StringTwo'
}

// Forcing type by qualifying field, and then using a field from other type.
// Not ok. This results in a confusing error message.
let testC () =
{ // ERROR : This record contains fields from inconsistent types
TypeOne.NumberOne = 1
StringTwo = "two"
}

// Forcing type by qualifying, and then using completely unknown field.
// Is ok.
let testD () =
{
TypeOne.NumberOne = 1
Hello = "hello" // ERROR : The record label 'Hello' is not defined
}
```

**Expected behavior**

Error message for testC should be as for testB or testD.

Also note that error messages for testB and testD differ, as a result of stating the type in different ways.

**Actual behavior**

Error message `This record contains fields from inconsistent types` is given, in spite of the type being stated explicitly.

**Related information**

VS 2019, v 16.1.6

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.