Skip to content

Protected property can't be assigned in inherit constructor call #13299

@amongonz

Description

@amongonz

Trying to assign a protected property at the constructor call of an inherit clause fails with an accessibility error.

Repro steps

public class Foo
{
    protected string Value { get; set; } = "";
}
type Bar() =
    // FS0629
    inherit Foo(Value = "Fails")

Expected behavior

The F# snippet compiles and Value is assigned.

Actual behavior

The F# snippet fails with FS0629 "Method 'set_Value' is not accessible from this code location."

Known workarounds

Either assign the property on a do clause or at the constructor call of an object expression.

type Bar() as this =
    inherit Foo()
    // OK
    do this.Value <- "OK"

// OK as well
{ new Foo(Value = "OK") with (* ... *) }

Related information

  • .NET 6.0.203

Metadata

Metadata

Assignees

Labels

Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions