Skip to content

Commit ed7905d

Browse files
edgarfgppsfinaki
andauthored
C# protected property can be assigned in a F# inherit constructor call (#17391)
* C# protected property can be assigned in a F# inherit constructor call * Failing test * Keep the access rights even if this is no a base call * Keep the access rights even if this is no a base call * Update check * more tests * release notes * inline the check, so it's only performed if LHS is true --------- Co-authored-by: Petr <[email protected]>
1 parent b475ab7 commit ed7905d

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* 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))
44
* Fix reporting IsFromComputationExpression only for CE builder type constructors and let bindings. ([PR #17375](https://github.com/dotnet/fsharp/pull/17375))
55
* 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))
6+
* 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))
67

78
### Added
89

src/Compiler/Checking/MethodCalls.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ let MethInfoChecks g amap isInstance tyargsOpt objArgs ad m (minfo: MethInfo) =
12371237
AccessibleFrom(paths, None)
12381238
| _ -> ad
12391239

1240-
if not (IsTypeAndMethInfoAccessible amap m adOriginal ad minfo) then
1240+
if not (minfo.IsProtectedAccessibility && minfo.LogicalName.StartsWithOrdinal("set_")) && not(IsTypeAndMethInfoAccessible amap m adOriginal ad minfo) then
12411241
error (Error (FSComp.SR.tcMethodNotAccessible(minfo.LogicalName), m))
12421242

12431243
if isAnyTupleTy g minfo.ApparentEnclosingType && not minfo.IsExtensionMember &&

src/Compiler/TypedTree/TypedTree.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type ValBaseOrThisInfo =
9090
/// Indicates a normal value
9191
| NormalVal
9292

93-
/// Indicates the 'this' value specified in a memberm e.g. 'x' in 'member x.M() = 1'
93+
/// Indicates the 'this' value specified in a member e.g. 'x' in 'member x.M() = 1'
9494
| MemberThisVal
9595

9696
/// Flags on values

tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/AccessibilityAnnotations/Basic/Basic.fs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,42 @@ module AccessibilityAnnotations_Basic =
188188
compilation
189189
|> verifyCompileAndRun
190190
|> shouldSucceed
191+
192+
[<Fact>]
193+
let ``C# protected property can be assigned in a F# inherit constructor call`` () =
194+
195+
let csharp =
196+
CSharp
197+
"""
198+
namespace Consumer
199+
{
200+
public class Foo
201+
{
202+
protected string Value { get; set; } = "";
203+
}
204+
}
205+
"""
206+
|> withName "CSLib"
207+
208+
let fsharp =
209+
FSharp
210+
"""
211+
module Hello
212+
open Consumer
213+
214+
type Bar() =
215+
inherit Foo(Value = "Works")
216+
217+
type Bar2() as this =
218+
inherit Foo()
219+
do this.Value <- "Works"
220+
221+
{ new Foo(Value = "OK") with member x.ToString() = "OK" } |> ignore
222+
"""
223+
|> withLangVersion80
224+
|> withName "FSLib"
225+
|> withReferences [ csharp ]
226+
227+
fsharp
228+
|> compile
229+
|> shouldSucceed

0 commit comments

Comments
 (0)