Skip to content

Private constructor requires attribute #16531

Closed

Description

@nojaf

When generating a signature file the result is somewhat unexpected.

Repro steps

module Telplin

type A private () = 
    member a.Foo () = ()

leads to

module Telplin

type A =
  
  member Foo: unit -> unit

Expected behaviour

This should have [<Class>] attribute.

Actual behaviour

Missing attribute does not compile.

Related information

FCS: FSharpCheckFileResults.GenerateSignature

Activity

  1. added this to the Backlog milestone on Jan 16, 2024
  2. auduchinok commented on Jan 16, 2024

    @auduchinok
    Member

    @nojaf Are you sure it's specifically about private constructors? I can reproduce it without adding the type to implementation file, so neither constructor nor its visibility change anything. I think the compiler wants to say that it can't decide which representation to use, based on the single property member in the signature file.

    Expected behaviour

    This should have [<Class>] attribute.

    I think the rules are a bit more complicated than this. Consider this, for example:

    [<Struct>]
    type A private (i: int) =
        member a.Foo = 1

    The compiler suggests to use Class, Struct, or Sealed, so we need to choose the attribute accordingly.

  3. nojaf commented on Jan 16, 2024

    @nojaf
    ContributorAuthor

    Adding private new: unit -> A to the signature removes the need to add the attribute.
    Whether the attribute should be Class does indeed depend on what the actual type is.
    However, I do believe structs are generated correctly.

  4. auduchinok commented on Jan 16, 2024

    @auduchinok
    Member

    Btw, what is generated for private type representations?

    type U1 =
        private
            | A of int
    
        member this.P = 1
    
    type U2 =
        private
            | A of int

    Something like this?

    [<Sealed>]
    type U1 =
        member P: int
    
    type U2
  5. nojaf commented on Jan 16, 2024

    @nojaf
    ContributorAuthor

    Btw, what is generated for private type representations?

    Run the compiler with --allsigs flag and you will know 😉.

  6. added
    Impact-Low
    Area-Compiler-SigFileGen
    and removed on Jan 22, 2024
  7. added 3 commits that reference this issue on Apr 14, 2026
    acf06a5
    49dfcf8
    d08967d
  8. added a commit that references this issue on Apr 16, 2026
    0abb33d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-SigFileGenBugImpact-Low

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions