Skip to content

[Bug] Struct constructor parameter renamed when name matches field (causes FS0039) #3349

Description

@itsdanieldk

Issue created from fantomas-online

Code

 module Bug
 
 type Cont = SuccessCont
 
 [<Struct>]
 type ContStackFrame =
     val Cont: Cont
     new cont = { Cont = cont }

Result

module Bug

type Cont = SuccessCont

[<Struct>]
type ContStackFrame =
    val Cont: Cont
    new newcont = { Cont = cont }

Problem description

Fantomas renames the struct constructor parameter cont to newcont by prepending new to the identifier. The record initialization { Cont = cont } still references the original parameter name, so the formatted code fails to compile with:

error FS0039: The value or constructor 'cont' is not defined.

This is also an idempotency issue. Each subsequent format pass prepends another new:

Pass 1: new cont → new newcont
Pass 2: new newcont → new newnewcont
Pass 3: new newnewcont → new newnewnewcont

This appears to happen when the constructor parameter name matches the field name (differing only in case): val Cont: Cont + new cont = .... Fantomas seems to confuse the parameter with the new keyword and merges them.

Extra information

  • The formatted result breaks my code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.
  • I would like a release if this problem is solved.

Options

Default Fantomas configuration

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions