dotnet / dotnet/fsharp

Access modifier `type private X with ...` type extensions is ignored

Open
#4,654 6 comments 0 reactions 1 assignee Claimed by @edgarfgp View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-Accessibility Bug Impact-Medium
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

A private type extension `type private X with` inside a module will be in scope after the module is opened.

#### Repro steps

```fsharp
module Test

module Inner =
type private System.String with
member _this.ExtensionOnString () = ()

"".ExtensionOnString () // Works here.

open Inner
"".ExtensionOnString () // Works too. [A]
```

#### Expected behavior

The line marked [A] should fail to compile, since the type extension is private to the `Inner` module.

#### Actual behavior

The code works.

#### Known workarounds
Placing all extensions in another private module works.

```fsharp
module Test

module Inner =
module private Extensions =
type System.String with
member _this.ExtensionOnString () = ()

open Extensions
"".ExtensionOnString () // Works here.

open Inner
// "".ExtensionOnString () but no longer here.
```

#### Related information

The same on .NET and Mono.

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.