fsharp
fsharp copied to clipboard
Protected property can't be assigned in inherit constructor call
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