dotnet / dotnet/fsharp

Misc. issues with output of interface stub generation

Open
#14,698 0 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Service Bug Impact-Medium Regression
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

While working on updating FSAC to .net 7, some of our tests around interface stub generation started to fail, I think in part due to the new GetSetMember concept.

Specifically, the following scenario:

```fsharp
type IPrinter =
abstract member Indentation: int with get, set

type Printer() =
interface IPrinter with
member _.Indentation with get () = 42
```

When generated with the 'verbose' mode, the output seems to be ok:

```fsharp
type IPrinter =
abstract member Indentation: int with get, set
type Printer() =
interface IPrinter with
member _.Indentation with get () = 42
member _.Indentation
with set (v: int): unit =
failwith "-"
```

But when generated with the 'non verbose' mode, the output has two problems:

a) the setter line contains type annotations, and
b) the method body isn't indented on the following line

```fsharp
type IPrinter =
abstract member Indentation: int with get, set

type Printer() =
interface IPrinter with
member _.Indentation with get () = 42
member _.Indentation
with set (v: int): unit = // note the annotations on this line
failwith "-" // note the need for one more indentation level
```

The type annotations seem to come from [this line](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Service/ServiceInterfaceStubGenerator.fs#L461), which should check the verbosity.
The lack of indentation seems to come from an interaction with [writeImplementation](https://github.com/dotnet/fsharp/blob/main/src/Compiler/Service/ServiceInterfaceStubGenerator.fs#L382) - when verbosity is off there's an assumption that the body is emitted on the same line, but the use of `WriteLine` for the `with set v =` line prior breaks that assumption. Perhaps the setter-writing portion of the stub needs to indent one more level before calling `writeIndentation`?

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.