dotnet / dotnet/fsharp

Fields and methods on internal types are impossible to make public

Open
#2,820 20 comments 3 reactions 0 assignees View on GitHub
Area-Compiler-Checking Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

This is causing #2184 - I don't think the Roslyn EE is doing anything wrong here.

```f#
module internal InternalModule =

type DebugProxy() =

member __.PublicMethod() = 15
member __.CustomGetter with public get() = 15
member val Items = 15

typeof.GetMembers(System.Reflection.BindingFlags.Public ||| System.Reflection.BindingFlags.Instance) |> printfn "%A"
// [|System.String ToString(); Boolean Equals(System.Object); Int32 GetHashCode(); System.Type GetType(); Void .ctor()|]
```

Note how the only public instance methods are ones inherited from System.Object. `PublicMethod`, `CustomGetter`, `Items` nor `get_Items` are available on the public interface. This is in contrast to C#, where public members on internal types stay public.

Compare the same GetMembers call on a type in a public module:

```f#
module PublicModule =

type DebugProxy() =

member __.PublicMethod() = 15
member __.CustomGetter with public get() = 15
member val Items = 15

typeof.GetMembers(System.Reflection.BindingFlags.Public ||| System.Reflection.BindingFlags.Instance) |> printfn "%A"
// [|Int32 PublicMethod(); Int32 get_CustomGetter(); Int32 get_Items(); System.String ToString(); Boolean Equals(System.Object); Int32 GetHashCode(); System.Type GetType(); Void .ctor(); Int32 CustomGetter; Int32 Items|]
```

#### Expected behavior

I would expect that public members are always public, irrespective of whether they're contained in non-public modules/types.

#### Actual behavior

Members in non-public modules/types always have their public methods set to non-public.

#### Known workarounds

None :(

/cc @dsyme

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.