Skip to content

Better representation of cons pattern #14007

@nojaf

Description

@nojaf

Is your feature request related to a problem? Please describe.

Given the following F# code:

    match list with
    | head :: tail -> Some head
    | [] -> None

and relevant AST:

SynMatchClause
    (LongIdent
       (SynLongIdent
          ([op_ColonColon], [], [Some (OriginalNotation "::")]),
        None, None,
        Pats
          [Tuple
             (false,
              [Named
                 (SynIdent (head, None), false, None,
                  tmp.fsx (2,6--2,10));
               Named
                 (SynIdent (tail, None), false, None,
                  tmp.fsx (2,14--2,18))], tmp.fsx (2,6--2,18))],
        None, tmp.fsx (2,6--2,18)), None, ...

The code doesn't really contain any tuple in this case.

Describe the solution you'd like

I'd be in favour of having a better representation, something similar to SynPat.Or or SynPat.And.
Proposal:

type SynPat =
...
   | Cons of lhsPat: SynPat * rhsPat: SynPat * range: range * trivia: SynPatConsTrivia

Describe alternatives you've considered

We currently process the AST and match against "::".

Additional context

related: #11481

//cc @dsyme, @auduchinok

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