You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
Since it'll be relevant to this discussion, let me answer that last question (copied from dotnet/fsharp#8093 (comment)):
Do note that the F# Spec specifically says that if the default constructors are omitted that default constructors are not created. So technically this seems to me to be a change to the spec.
If I understand the issue at hand correctly, the absence of a default ctor allows C# to create an instance. But adding a default (private) ctor, while fixing the C# issue, will allow creating instances in F#, wouldn't it (though only in private scope)?
It seems perhaps more reasonable that if there's no constructor at all that we mark it AbstractClass? We might even warn and/or disallow creating instance methods, as there's no way to call them, not even through inheritance.
Transferring dotnet/fsharp#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=
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?
The text was updated successfully, but these errors were encountered: