dotnet / dotnet/fsharp

Field in a record named the same as a DUs case inside of module of the same name of the record type fails to pattern match

Open
#18,364 0 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-NameResolution Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Hello

**Repro steps**

Provide the steps required to reproduce the problem:

```fs
module Test =

type Configuration =
{
Parameters : string list
}

module Configuration =

type Parameters = Parameters of int list

let echo (value : Test.Configuration.Parameters) =
match value with
| Test.Configuration.Parameters i -> i
```

![Image](https://github.com/user-attachments/assets/1d7cdd64-06a6-476c-b625-663566895d50)

**Expected behavior**

Should not confuse the types

**Actual behavior**

Type confusion is occuring

**Known workarounds**

1. Changing either name of the record property or the DUs case fix the issue.

2. Using an alias, for accessing the DUs:

```fs
module Test =


type Configuration =
{
// Changing this property name fix the issue
Parameters : string list
}

module Configuration =

type Parameters = Parameters of int list

type P = Test.Configuration.Parameters

let echo (value : Test.Configuration.Parameters) =
match value with
| P.Parameters i -> i
```

**Related information**

Provide any related information (optional):

* Operating system: **Windows_NT**
* Runtime: **netcore**
* Dotnet version: **9.0.103**
* VSCode: **1.97.2**

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.