dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.89k stars 783 forks source link

Update signature generation to include Sealed/Class/Interface attribute for OO-style type constructs #14308

Open T-Gro opened 1 year ago

T-Gro commented 1 year ago

Fsc.exe offers a way to generate signature files out of current implementation. For most of the F# constructs, a tooling-powered roundtrip just works: You can generally take an existing imp file, generate .fsi for it, and then compile them together.

One particular are where this does not work are OO-style (so not DUs, not records) constructions like this one:

module Core_access    
type MyClassPropertiyGetters =     
    member      x.AnyKindOfProperty= 12   

This results in the following .fsi file:

module Core_access

type MyClassPropertiyGetters =

  member AnyKindOfProperty: int

And a compiler error for the type saying: FS0938
The representation of this type is hidden by the signature. It must be given an attribute such as [<Sealed>], [<Class>] or [<Interface>] to indicate the characteristics of the type.

Proposal: Enrich signature generation to include one of the three attributes (most likely choosing between and ?)

T-Gro commented 1 year ago

Testcase will be prepared at ~\tests\FSharp.Compiler.ComponentTests\Signatures\TestCasesForGenerationRoundTrip\access-minimal-repro.fsx

Without manually specifying the Sealed attribute at impl file, the roundtrip (impfile -> generate -> compile .fs and .fsi together) fails.