dotnet / dotnet/fsharp

Compile error from field vs submodule name ambiguity when outside unopened module

Open
#10,444 4 comments 1 reaction 1 assignee Claimed by @edgarfgp 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

Over the years, F# has allowed more things to have the same name without getting confused. This issue is about one such situation where F# still gets confused.

Consider the following code.

```fsharp
module Top

module A =
type B = { C: bool }

module B =
module C =
let x = 0

let y = B.C.x

let z = A.B.C.x
// ^^^^^
// Error FS0728 Field 'C' is not static
```

**Expected behavior**

I expected the expressions assigned to `y` and `z` to evaluate to the same thing.

**Actual behavior**

As shown in the code as a comment, the actual behavior is a compile error in the expression assigned to `z` because the `B` resolves to the type `B` instead of the nested submodule `B`.

At the same time, IntelliSense gives the correct tooltip when hovering over `x`.
![2020-11-12_11-34-29_370](https://user-images.githubusercontent.com/34664007/98974969-1f824180-24db-11eb-80ee-b09d193c395e.png)

But IntelliSense also gives a tooltip that agrees with the compiler when hovering over `C`.
![2020-11-12_11-35-19_371](https://user-images.githubusercontent.com/34664007/98975055-404a9700-24db-11eb-954e-3f5d02356e14.png)

**Known workarounds**

Open module `A` just before `z` like this.
```fsharp
open A
let z = B.C.x
```

**Related information**

* Operating system
- Edition: Windows 10 Enterprise
- Version: 1909
- OS build: 18363.1198
* .NET SDK: .NET Core 3.1.403
* Visual Studio
- Edition: Enterprise 2019
- Version: 16.7.7

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.