Skip to content

Multiple accessibilities given for property getter or setter is not raised for property #15423

Closed

Description

@nojaf

Get and set properties cannot have different visibility for the getter and setter

Repro steps

Example:

type Foo() =
    member f.X with internal get (key1, key2) = true and private set (key1, key2) value = ()
    member internal f.Y with get (key1, key2) = true and private set (key1, key2) value = ()

Expected behavior

Both X and Y show the same diagnostic (FS0558)

Actual behavior

f.X won't produce any diagnostics and will create an internal getter and setter.

image

While f.Y will produce

image

Known workarounds

/

Related information

Local compiler

Activity

  1. added
    Area-Compiler-Syntax
    on Jun 16, 2023
  2. added this to the Backlog milestone on Jun 16, 2023
  3. T-Gro commented on Jun 16, 2023

    @T-Gro
    Member

    The error works a little diffently.

    You can have visiblity:

    • "outer" for the entire member
    • "inner" just for set
    • "inner" just for get

    When you mix outer and inner, you get the error you screenshoted
    If you omit outer and use two inner ones, they can be as they wish.

    This also gets reflected in the IL (just follows the standard the privates in F# become internals in IL, but that's it)

    https://sharplab.io/#v2:DYLgZgzgNALiCWwA+BtAPAOQPYFECOArgIbDwwCeAfALoCwAUOtgMJYC2ADkQE7wRYA7GgwocApgAIAYliwAKAJQSAvAwnqJbMWwBGY7hLAA6ABoS1GywHcyAC3P1LTjRwI7SAYwkBzMTAly/FoAaiRKyhIw3ASSFs5EAgAmEhy8AG5EMJIQfgFBYqHAShnAMSoBCkA=

  4. auduchinok commented on Jun 16, 2023

    @auduchinok
    Member

    A property declaration may also be split into two, so the getter and the setter would be analysed separately.
    And then comes the fact that F# allows overloading properties, so we won't even know if two accessor declarations will belong to the same property until after type checking is done.

  5. 0101 commented on Jun 19, 2023

    @0101
    Contributor

    Get and set properties can have different visibility for the getter and setter. But the error message is confusing and should be fixed.

  6. added
    Area-Diagnostics
    and removed
    Area-Compiler-Syntax
    on Jun 19, 2023
  7. T-Gro commented on Jun 19, 2023

    @T-Gro
    Member

    Will be resolved by updating the error message in #15424

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-DiagnosticsFeature Improvement

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions