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
merged 15 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 10 additions & 10 deletions src/Compiler/Checking/TypeRelations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ let rec TypeFeasiblySubsumesType ndeep g amap m ty1 canCoerce ty2 =

| _ ->
// F# reference types are subtypes of type 'obj'
(isObjTy g ty1 && (canCoerce = CanCoerce || isRefTy g ty2))
||
(isAppTy g ty2 &&
(canCoerce = CanCoerce || isRefTy g ty2) &&
begin match GetSuperTypeOfType g amap m ty2 with
| None -> false
| Some ty -> TypeFeasiblySubsumesType (ndeep+1) g amap m ty1 NoCoerce ty
end ||
ty2 |> GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes g amap m
|> List.exists (TypeFeasiblySubsumesType (ndeep+1) g amap m ty1 NoCoerce))
let isObjAndRefType = (isObjTy g ty1 && (canCoerce = CanCoerce || isRefTy g ty2))
let isAppTy = isAppTy g ty2
let isAppAndRefType = isAppTy && (canCoerce = CanCoerce || isRefTy g ty2)
let superType =
match GetSuperTypeOfType g amap m ty2 with
| None -> false
| Some ty -> TypeFeasiblySubsumesType (ndeep+1) g amap m ty1 NoCoerce ty
let immediateInterfacesOfType = ty2 |> GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes g amap m
let immediateInterfaces = immediateInterfacesOfType |> List.exists (TypeFeasiblySubsumesType (ndeep+1) g amap m ty1 NoCoerce)
isObjAndRefType || (isAppAndRefType && superType || immediateInterfaces)

/// Choose solutions for Expr.TyChoose type "hidden" variables introduced
/// by letrec nodes. Also used by the pattern match compiler to choose type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,36 @@ 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 = "Fails")
"""
|> withLangVersion80
|> withName "FSLib"
|> withReferences [ csharp ]

fsharp
|> compile
|> shouldSucceed
Loading