Skip to content

Pattern matching regression on numbers (at least) #3877

@painedpineapple

Description

@painedpineapple

When switching on numbers (like HTTP status codes), the compiled output is incorrect.

Example:

let httpResponseCode = 201
let _ =
  match httpResponseCode with
  | 201|200 ->
      Js.log (("good response")[@reason.raw_literal "good response"])
  | 500|503|506|509|598|501|504|507|510|599|502|505|508|511 ->
      Js.log (("bad response")[@reason.raw_literal "bad response"])
  | _ -> Js.log (("the catch all")[@reason.raw_literal "the catch all"])

Reason playground: https://reasonml.github.io/en/try?rrjsx=true&reason=DYUwLgBAFmYA4CUQGc4HsB2yQGE0BMQIBeCAJgAYBGAbgCg7kB3ASzAGMoIAKGeJVJmx5CASggBvOgB9y1GXIokAfHQgQAUsgB0wNAHNuAIn1oCEAE4p0WEEdH1ZAVgoUFLgMzuKANm8BOd38ADm8qbwAWbwB2dyo3Z39A5woybydvUOcqKhU1TR09QyMAIwBDfEtrITtRBQB9PPUtXQNjMCgidjKOLjLgYHt6AF8aIA

In the example, if you remove all of the 5XX numbers or remove only 502 it'll work correctly. Other than that whenever the status code is 201 or 200 at least it hits the catch-all instead of the correct case.

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