Skip to content

Improve error reporting: property syntax can't be remembered #2277

@smoothdeveloper

Description

@smoothdeveloper

What

When I try to define a class with getters/setters (and I forget how this is supposed to be defined):

type Foo() =
  member __.Prop : int with get,set

The compiler gives

Error: A type definition requires one or more members or other declarations. If you intend to define an empty class, struct or interface, then use 'type ... = class end', 'interface end' or 'struct end'.

Why

The syntax for some members (not only properties) can be difficult to remember when not used frequently (modules and functions are fine, but some frameworks insist on having properties, instance methods, etc.).

How

In my case, there is "with get,set" which is a clue I want a property, although I should have typed

type Foo() =
  member val Prop = 0 with get, set

I wish the compiler could help me out without resorting to google search.

related #1103

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsFeature ImprovementTheme-Simple-F#A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.

    Type

    No type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions