diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md index 8d206a1bd1e..9b71a9c31b1 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.100.md @@ -3,6 +3,7 @@ * Compiler hangs when compiling inline recursive invocation ([Issue #17376](https://github.com/dotnet/fsharp/issues/17376), [PR #17394](https://github.com/dotnet/fsharp/pull/17394)) * Fix reporting IsFromComputationExpression only for CE builder type constructors and let bindings. ([PR #17375](https://github.com/dotnet/fsharp/pull/17375)) * Optimize simple mappings in comprehensions when the body of the mapping has `let`-bindings and/or sequential expressions before a single yield. ([PR #17419](https://github.com/dotnet/fsharp/pull/17419)) +* C# protected property can be assigned in F# inherit constructor call. ([Issue #13299](https://github.com/dotnet/fsharp/issues/13299), [PR #17391](https://github.com/dotnet/fsharp/pull/17391)) ### Added diff --git a/src/Compiler/Checking/MethodCalls.fs b/src/Compiler/Checking/MethodCalls.fs index 25f9d420f2e..f75fd2fb6be 100644 --- a/src/Compiler/Checking/MethodCalls.fs +++ b/src/Compiler/Checking/MethodCalls.fs @@ -1237,7 +1237,7 @@ let MethInfoChecks g amap isInstance tyargsOpt objArgs ad m (minfo: MethInfo) = AccessibleFrom(paths, None) | _ -> ad - if not (IsTypeAndMethInfoAccessible amap m adOriginal ad minfo) then + if not (minfo.IsProtectedAccessibility && minfo.LogicalName.StartsWithOrdinal("set_")) && not(IsTypeAndMethInfoAccessible amap m adOriginal ad minfo) then error (Error (FSComp.SR.tcMethodNotAccessible(minfo.LogicalName), m)) if isAnyTupleTy g minfo.ApparentEnclosingType && not minfo.IsExtensionMember && diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index 6f897c7889a..37edb437867 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -90,7 +90,7 @@ type ValBaseOrThisInfo = /// Indicates a normal value | NormalVal - /// Indicates the 'this' value specified in a memberm e.g. 'x' in 'member x.M() = 1' + /// Indicates the 'this' value specified in a member e.g. 'x' in 'member x.M() = 1' | MemberThisVal /// Flags on values diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs index 37add29d802..869e4ba9930 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs @@ -188,3 +188,42 @@ module AccessibilityAnnotations_Basic = compilation |> verifyCompileAndRun |> shouldSucceed + + [] + let ``C# protected property can be assigned in a F# inherit constructor call`` () = + + let csharp = + CSharp + """ +namespace Consumer +{ + public class Foo + { + protected string Value { get; set; } = ""; + } +} +""" + |> withName "CSLib" + + let fsharp = + FSharp + """ +module Hello +open Consumer + +type Bar() = + inherit Foo(Value = "Works") + +type Bar2() as this = + inherit Foo() + do this.Value <- "Works" + +{ new Foo(Value = "OK") with member x.ToString() = "OK" } |> ignore +""" + |> withLangVersion80 + |> withName "FSLib" + |> withReferences [ csharp ] + + fsharp + |> compile + |> shouldSucceed