Skip to content

[bug] incorrect return type annotation for Stdlib_RegExp.Result.matches #252

Closed
@tx46

Description

@tx46
  @send external matches: (t, @as(1) _) => array<string> = "slice"

This has the return type array<string>, but it should likely be array<option<string>>. Minimal repro:

let foo ="x"
let re = %re("/(y)?(z)?/")

switch foo->String.match(re) {
  | Some(m) =>
  let matches = m->RegExp.Result.matches
  switch matches {
    | [a, b] =>
    Console.log2(a, b)
    Console.log(matches)
  }
}

Output:

undefined undefined

[null,null]

If array<string> was correct, output should be ["", ""]. Replace Console.log2(a, b) with the following for runtime breakage:

    Console.log(a->String.length)

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