Skip to content

Labelled arguments passed out of order are evaluated in the declared order #9340

Description

@cknitt

When labelled arguments are passed in a different order than the function declares them, they are evaluated in the declared order, not in source order.

let log = []
let a = () => {log->Array.push("a"); 1}
let b = () => {log->Array.push("b"); 2}
let c = () => {log->Array.push("c"); 3}

type t
let t: t = %raw(`{p: (...xs) => {}}`)
@send external p: (t, int, ~extra: int, int) => unit = "p"

p(t, ~extra=b(), a(), c())
Console.log(log)

compiles to

t.p(a(), b(), c());

and logs ["a", "b", "c"]. Expected: ["b", "a", "c"], the order in the source.

It is not specific to externals. A plain function value of type (int, ~extra: int, int) => unit called as pp(~extra=b(), a(), c()) also compiles to pp(a(), b(), c()).

ReScript otherwise evaluates arguments left to right (see #9154), so the reordering should bind the arguments that move to temporaries when they have side effects.

Found while reviewing #9231. Reproduced on master 54b923a.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions