Skip to content

Pattern matching bug: wildcard pattern does not match tuple #5460

@hummy123

Description

@hummy123

A potential bug was mentioned on Discord earlier this week so I went ahead and confirmed the bug actually does occur, and thought it was a good idea to record here so it's not forgotten later.

The following code (provided by Stachu, with some minimal edits applied after) demonstrates the bug:

// <test>
// does _ wildcard pattern match a DU that has a tuple?

// result: matches string "not expected"
// even though "expected" case is meant to match because of wildcard
type DU = | A | B of Bool * Bool

(match DU.B (true, false) with
  | A -> "nope"
  | B _ -> "expected"
  | B (_, _) -> "not expected") = "expected"
// </test>

I have a permalink on my fork which adds an Expecto test to run/confirm the bug, but it's likely easier to copy-paste the buggy code into one's own local copy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions