dotnet / dotnet/fsharp

False positive `Open declaration can be removed` when having records with the same name

Open
#16,226 1 comment 2 reactions 0 assignees View on GitHub
Area-LangService-CodeFixes Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

**Repro steps**

Consider this code
```fsharp
namespace Case2

module RecordA =
type Record = { Foo: string }

module RecordB =
type Record = { Bar: string }

module Use =
open RecordB // actually not required
open RecordA
open RecordB // TODO: false positive

let convertBToA (recordB: Record) =
{ Foo = recordB.Bar }
```
VS marks second `open RecordB` as unnecessary. Removal of it breaks compilation because we actually need `RecordB.Record` and `open RecordA` shadows it.

![2023-11-03_224641](https://github.com/dotnet/fsharp/assets/44954031/72de829d-7ce6-4988-abec-141f58560366)

**Expected behavior**

Suggested refactorings do not break compilation and highlight correct targets for change

**Actual behavior**

Suggested refactoring breaks compilation.

**Known workarounds**
.

Provide any related information (optional):

.NET SDK: 7.0.403
Visual Studio 17.7.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.