Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# protected property can be assigned in a F# inherit constructor call #17391

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Checking/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,8 @@ let MethInfoChecks g amap isInstance tyargsOpt objArgs ad m (minfo: MethInfo) =
AccessibleFrom(paths, None)
| _ -> ad

if not (IsTypeAndMethInfoAccessible amap m adOriginal ad minfo) then
let isProtectedSetter = minfo.IsProtectedAccessibility && minfo.LogicalName.StartsWithOrdinal("set_")
if not (IsTypeAndMethInfoAccessible amap m adOriginal ad minfo) && not isProtectedSetter then
edgarfgp marked this conversation as resolved.
Show resolved Hide resolved
error (Error (FSComp.SR.tcMethodNotAccessible(minfo.LogicalName), m))

if isAnyTupleTy g minfo.ApparentEnclosingType && not minfo.IsExtensionMember &&
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/TypedTree/TypedTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,42 @@ module AccessibilityAnnotations_Basic =
compilation
|> verifyCompileAndRun
|> shouldSucceed

[<Fact>]
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
Loading