fsharp / fsharp/fslang-suggestions

Give a constructorless type a private/internal constructor

Open
#906 1 comment 3 reactions 0 assignees View on GitHub
approved-in-principle area: interop
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Transferring https://github.com/dotnet/fsharp/issues/8093

Shouldn't a constructorless type have a private/internal constructor in IL?

Looking at these two types in sharplab https://sharplab.io/#v2:DYLgZgzgNAJiDUAfALgTwA4FMAEAxA9vgIzYC8AsAFDY3YTICGyAlgMbYC2mHARpgE7ZmMbAA8yYqlTRY8hAEzZ0/ZgDcmOABQBKMlVp1GLdl14ChI8aTFA=

```
type Foo1 =
static member id x = x

type Foo2 private () =
static member id x = x
```

Foo1 can't be constructed in F# similar to Foo2 but only Foo2 has an internal constructor in IL, leaving Foo1 to be constructed from C# without issue, is this by design?

Contributor guide

No contributing guide indexed for this repository

Research direction

Compare the Foo1 and Foo2 examples in the linked SharpLab reproduction and inspect the generated IL, focusing on constructor accessibility from F# and C#. Determine whether constructorless types should receive a private or internal constructor, then document the intended behavior and its compatibility implications before identifying the compiler tests or implementation area to change.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.