dotnet / dotnet/fsharp

Misleading extra error message when field declaration order differs between signature & implementation

Open
#20,410 0 comments 0 reactions 0 assignees View on GitHub
Bug Needs-Triage
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

**Repro steps**

#### Signature

```fsi
type ResolvedConfig =
{
Config: FormatConfig
Settings: ResolvedSetting list
EditorConfigFiles: string list
Problems: EditorConfigProblem list
}
```

#### Implementation

```fs
type ResolvedConfig = // FS0313: The type definitions for type 'ResolvedConfig' in the signature and implementation are not compatible because the order of the fields is different in the signature and implementation
{
Config: FormatConfig
EditorConfigFiles: string list // FS0193: The module contains the field EditorConfigFiles: string list but its signature specifies Settings: ResolvedSetting list The names differ
Problems: EditorConfigProblem list
Settings: ResolvedSetting list
}
```

**Expected behavior**

FS0313 should be emitted on the type. (Record field declaration order matters, since it affects the order of ctor parameters.)

**Actual behavior**

FS0193 is _also_ emitted for the first out-of-order field in the implementation. There _is_ however a field `Settings: ResolvedSetting list`; it's just not at the same ordinal.

The message is not strictly wrong, but it is arguably misleading. Maybe we should include wording like "the names at this position differ" or something?

**Known workarounds**

N/A

**Related information**

Current `main`.

I happened to notice this when testing out record type spreads in Fantomas, but the extra error message happens for explicit field declarations as well.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied signature and implementation with differing record-field order on current main, then trace the compiler's signature/implementation diagnostic handling. Done means the order mismatch still reports FS0313, without an additional misleading FS0193 for a field that exists at another position.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.