gleam-lang/gleam

Changing order of labels in a function call does not change order of evaluation.

オープン

#5,272 opened on 2026/01/07

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (960 件のフォーク)batch import
help wantedhigh priority

Repository metrics

Stars
 (21,417 個のスター)
PR merge metrics
 (平均マージ 10d 19h) (30d で 69 merged PRs)

説明

I've noticed that when using labels in a function call, the order arguments are evaulated in does not correspond to the order written in the source code. Instead, the arguments are evaluated in the order they are defined in the function itself.

I have this function:

pub fn fit(into viewport: Bounds, box box: Bounds) -> Transform

You can see it has two arguments, labelled into: and box: respectively. If we take this call:

transform.fit(
  into: echo bounds.new(..) as "viewport",
  box: echo graph.fold(..) as "box",
)

and look at the console output, we can see:

[Log] dev/experiments/layout.gleam:40 viewport (layout.mjs, line 246)
#(0, 0, 300, 300)

[Log] dev/experiments/layout.gleam:41 box (layout.mjs, line 246)
#(0, 0, 293.48392537260776, 291.62981208738245)

All is expected. "viewport" is logged first, then "box".

However, if we flip the order we provide the labels, so now the function call is:

transform.fit(
  box: echo graph.fold(..) as "box",
  into: echo bounds.new(..) as "viewport",
)

We can see the that the logs have not changed, and "viewport" is still logged first.

[Log] dev/experiments/layout.gleam:51 viewport (layout.mjs, line 246)
#(0, 0, 300, 300)

[Log] dev/experiments/layout.gleam:40 box (layout.mjs, line 246)
#(0, 0, 293.48392537260776, 291.62981208738245)

Is this a bug? It is very surprising that side effects can happen in a different order to the one provided in the source code!

コントリビューターガイド