dotnet / dotnet/fsharp

"Implement Interface" defines multiple methods for nested interfaces

Open
#5,813 0 comments 0 reactions 0 assignees View on GitHub
AI-thinks-windows-only Area-LangService-CodeFixes Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

This one is a bit weird, and I don't know if this is the right place for it.

If you define two interfaces that implement a common, third interface, the "quick action" (CTRL + .) will re-implement the common interface when it should not, even if the third interface is explicitly implemented. (If the third interface is not explicitly implemented, the quick-action does nothing.)

#### Repro steps

Consider the following code:

```
type IFoo =
abstract member Foo : unit -> unit

type IBar =
inherit IFoo
abstract member Bar : unit -> unit

type IBaz =
inherit IFoo
abstract member Baz : unit -> unit
abstract member Baz2 : unit -> unit
```

If you define a type, `Foo` as the following:

```
type Foo () =
interface IFoo with
member this.Foo () = ()
interface IBar with
member this.Bar() = raise (System.NotImplementedException())
interface IBaz with
member this.Baz() = raise (System.NotImplementedException())
```

The attempting to use the quick-action to implement `IBaz` completely will result in:

```
type Foo () =
interface IFoo with
member this.Foo () = ()
interface IBar with
member this.Bar() = raise (System.NotImplementedException())
interface IBaz with
member this.Baz2() = raise (System.NotImplementedException())
member this.Foo() = raise (System.NotImplementedException())
member this.Baz() = raise (System.NotImplementedException())
```

This is obviously not the correct action for a nested interface.

#### Expected behavior

The interface function that has already been implemented for a higher-level interface should not be reimplemented.

#### Actual behavior

The member is reimplemented, and `FS0855: No abstract or interface member was found that corresponds to this override` is thrown. (Thus, the resulting code cannot compile without modification.)

#### Known workarounds

Delete the extraneous member(s).

#### Related information

Provide any related information

* Operating system: Microsoft Windows 10 Pro for Workstations
* Branch: VS 15.7.5 Public Release
* .NET Runtime, CoreCLR or Mono Version: .NET 4.7.2
* Editing Tools (e.g. Visual Studio Version): Visual Studio 15.7.5
* Links to F# RFCs or entries on https://github.com/fsharp/fslang-suggestions: Not Applicable
* Links to performance testing scripts: Not Applicable
* Indications of severity: Minor / Convenience

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.