Skip to content

Misc. issues with output of interface stub generation #14698

Open
@baronfel

Description

@baronfel

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:

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:

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

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, which should check the verbosity.
The lack of indentation seems to come from an interaction with writeImplementation - 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-ServiceVarious compiler service issues which do not belong to other labels/areas.BugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.Regression

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions