Skip to content

Conversation

@T-Gro
Copy link
Member

@T-Gro T-Gro commented Nov 23, 2023

This fixes #16297
Before, it was failing with 'member val' definitions are only permitted in types with a primary constructor. Consider adding arguments to your type definition, e.g. 'type X(args) = ...'.

Curiously, things started to work if the auto property was declared only after a 'static let' or a 'static do', even an empty 'static do ()' worked.

This bugfix eliminated the need to put in dummy static let/do and makes static autoproperty work

type T =
    //static let x = 42   <--- if a 'static let' or 'static do' were here first, everything worked
    static member val P = 1 with get,set   // <-- if this was the first member, it failed 

The error message remains in place for instance auto properties ('member val' without static).
Types without constructors are codegen'd as static, therefore instance auto property does not make sense.

@T-Gro T-Gro self-assigned this Nov 23, 2023
@T-Gro T-Gro marked this pull request as ready for review November 23, 2023 14:30
@T-Gro T-Gro requested a review from a team as a code owner November 23, 2023 14:30
@T-Gro T-Gro merged commit 912a0c5 into dotnet:main Nov 23, 2023
@T-Gro T-Gro deleted the 16297-cant-use-static-auto-property-in-a-object-type-without-a-primary-constructor branch November 23, 2023 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't use static auto property in a object type without a primary constructor

4 participants