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

Fix #5531 #5778

Merged
merged 10 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions src/fsharp/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,14 @@ and GetRelevantMethodsForTrait (csenv:ConstraintSolverEnv) permitWeakResolution
/// to a generic instantiation for an operator based on the right hand type.

let minfos = List.reduce (ListSet.unionFavourLeft MethInfo.MethInfosUseIdenticalDefinitions) minfos

/// Check that the available members aren't hiding a member from the parent (depth 1 only)
let relevantMinfos = minfos |> List.filter(fun minfo -> not minfo.IsDispatchSlot && not minfo.IsVirtual && minfo.IsInstance)
minfos
|> List.filter(fun minfo1 ->
not(minfo1.IsDispatchSlot &&
relevantMinfos
|> List.exists (fun minfo2 -> MethInfosEquivByNameAndSig EraseAll true csenv.g csenv.amap m minfo2 minfo1)))
else
[]
// The trait name "op_Explicit" also covers "op_Implicit", so look for that one too.
Expand Down
2 changes: 2 additions & 0 deletions tests/fsharp/regression/5531/compilation.output.test.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

test.fs(7,17): warning FS0864: This new member hides the abstract member 'abstract member Base.Foo : unit -> unit'. Rename the member or use 'override' instead.
2 changes: 2 additions & 0 deletions tests/fsharp/regression/5531/compilation.output.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

test.fs(7,17): warning FS0864: This new member hides the abstract member 'abstract member Base.Foo : unit -> unit'. Rename the member or use 'override' instead.
7 changes: 7 additions & 0 deletions tests/fsharp/regression/5531/output.test.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Base
Base
Derived
Base
Base
Base
Derived
7 changes: 7 additions & 0 deletions tests/fsharp/regression/5531/output.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Base
Base
Derived
Base
Base
Base
Derived
23 changes: 23 additions & 0 deletions tests/fsharp/regression/5531/test.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type Base() =
abstract member Foo : unit -> unit
default this.Foo() = printfn "Base"

type Derived() =
inherit Base()
member this.Foo() = printfn "Derived"

let inline callFoo< ^T when ^T : (member Foo: unit -> unit) > (t: ^T) =
(^T : (member Foo: unit -> unit) (t))

let b = Base()
let d = Derived()
let bd = d :> Base

b.Foo()
bd.Foo()
d.Foo()

callFoo<Base> b
callFoo<Base> bd
callFoo<Base> d
callFoo<Derived> d
30 changes: 30 additions & 0 deletions tests/fsharp/tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,36 @@ module RegressionTests =
[<Test >]
let ``struct-tuple-bug-1-FSI_BASIC`` () = singleTestBuildAndRun "regression/struct-tuple-bug-1" FSI_BASIC

#if !FSHARP_SUITE_DRIVES_CORECLR_TESTS
[<Test>]
let ``SRTP doesn't handle calling member hiding hinherited members`` () =
let cfg = testConfig "regression/5531"

let outFile = "compilation.output.test.txt"
let expectedFile = "compilation.output.test.bsl"

fscBothToOut cfg outFile "%s --nologo -O" cfg.fsc_flags ["test.fs"]

let diff = fsdiff cfg outFile expectedFile

match diff with
| "" -> ()
| _ ->
Assert.Fail (sprintf "'%s' and '%s' differ; %A" (getfullpath cfg outFile) (getfullpath cfg expectedFile) diff)

let outFile2 = "output.test.txt"
let expectedFile2 = "output.test.bsl"

execBothToOut cfg (cfg.Directory) outFile2 (cfg.Directory ++ "test.exe") ""

let diff2 = fsdiff cfg outFile2 expectedFile2

match diff2 with
| "" -> ()
| _ ->
Assert.Fail (sprintf "'%s' and '%s' differ; %A" (getfullpath cfg outFile2) (getfullpath cfg expectedFile2) diff2)
#endif

#if !FSHARP_SUITE_DRIVES_CORECLR_TESTS
// This test is disabled in coreclr builds dependent on fixing : https://github.com/Microsoft/visualfsharp/issues/2600
[<Test>]
Expand Down