Repository navigation
Evaluate labelled arguments passed out of order in source order #9344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cknitt
wants to merge
1
commit into
master
Choose a base branch
from
labelled-arg-order
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+347
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Labelled arguments passed before arguments declared ahead of them are evaluated in source order. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
|
||
| import * as Mocha from "mocha"; | ||
| import * as Test_utils from "./test_utils.mjs"; | ||
| import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; | ||
|
|
||
| let target = ({send: (...xs) => xs}); | ||
|
|
||
| function f(x, extra, y) { | ||
| return [ | ||
| x, | ||
| extra, | ||
| y | ||
| ]; | ||
| } | ||
|
|
||
| function withOpt(x, extra, y) { | ||
| return [ | ||
| x, | ||
| Stdlib_Option.getOr(extra, 0), | ||
| y | ||
| ]; | ||
| } | ||
|
|
||
| Mocha.describe("Labelled_argument_order_test", () => { | ||
| let log = []; | ||
| let mark = (name, v) => { | ||
| log.push(name); | ||
| return v; | ||
| }; | ||
| let take = () => { | ||
| let names = log.join(""); | ||
| log.splice(0, log.length); | ||
| return names; | ||
| }; | ||
| Mocha.test("a function", () => { | ||
| let arg = mark("b", 2); | ||
| let arg$1 = mark("a", 1); | ||
| let arg$2 = mark("c", 3); | ||
| let r = [ | ||
| arg$1, | ||
| arg, | ||
| arg$2 | ||
| ]; | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 30, characters 7-14", "bac", take()); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 31, characters 7-14", [ | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ], r); | ||
| }); | ||
| Mocha.test("a @send external", () => { | ||
| let arg = mark("b", 2); | ||
| let arg$1 = mark("a", 1); | ||
| let arg$2 = mark("c", 3); | ||
| let r = target.send(arg$1, arg, arg$2); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 36, characters 7-14", "bac", take()); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 37, characters 7-14", [ | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ], r); | ||
| }); | ||
| Mocha.test("an @obj external", () => { | ||
| let arg = mark("y", 2); | ||
| let arg$1 = mark("x", 1); | ||
| let o = { | ||
| x: arg$1, | ||
| y: arg | ||
| }; | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 42, characters 7-14", "yx", take()); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 43, characters 7-14", [ | ||
| 1, | ||
| 2 | ||
| ], [ | ||
| o.x, | ||
| o.y | ||
| ]); | ||
| }); | ||
| Mocha.test("a callee that is a call", () => { | ||
| let arg = mark("f", f); | ||
| let arg$1 = mark("b", 2); | ||
| let arg$2 = mark("a", 1); | ||
| let arg$3 = mark("c", 3); | ||
| let r = arg(arg$2, arg$1, arg$3); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 49, characters 7-14", "fbac", take()); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 50, characters 7-14", [ | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ], r); | ||
| }); | ||
| Mocha.test("a read after an effect that changes it", () => { | ||
| let n = 0; | ||
| let bump = () => { | ||
| n = n + 1 | 0; | ||
| return 10; | ||
| }; | ||
| let arg = bump(); | ||
| let arg$1 = n; | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 59, characters 7-14", [ | ||
| 1, | ||
| 10, | ||
| 5 | ||
| ], [ | ||
| arg$1, | ||
| arg, | ||
| 5 | ||
| ]); | ||
| }); | ||
| Mocha.test("an optional argument", () => { | ||
| let arg = mark("b", 2); | ||
| let arg$1 = mark("a", 1); | ||
| let arg$2 = mark("c", 3); | ||
| let r = withOpt(arg$1, arg, arg$2); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 64, characters 7-14", "bac", take()); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 65, characters 7-14", [ | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ], r); | ||
| }); | ||
| Mocha.test("a partial application", () => { | ||
| let arg = mark("b", 2); | ||
| let arg$1 = mark("a", 1); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 70, characters 7-14", "ba", take()); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 71, characters 7-14", [ | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ], [ | ||
| arg$1, | ||
| arg, | ||
| 3 | ||
| ]); | ||
| }); | ||
| Mocha.test("arguments already in order", () => { | ||
| let r = [ | ||
| mark("a", 1), | ||
| mark("b", 2), | ||
| mark("c", 3) | ||
| ]; | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 76, characters 7-14", "abc", take()); | ||
| Test_utils.eq("File \"labelled_argument_order_test.res\", line 77, characters 7-14", [ | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ], r); | ||
| }); | ||
| }); | ||
|
|
||
| export { | ||
| target, | ||
| f, | ||
| withOpt, | ||
| } | ||
| /* target Not a pure module */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| open Mocha | ||
| open Test_utils | ||
|
|
||
| // Labelled arguments passed before arguments declared ahead of them are still | ||
| // evaluated in source order. | ||
|
|
||
| type t | ||
| @send external send: (t, int, ~extra: int, int) => array<int> = "send" | ||
| @obj external makeObj: (~x: int, ~y: int) => {"x": int, "y": int} = "" | ||
|
|
||
| let target: t = %raw(`{send: (...xs) => xs}`) | ||
|
|
||
| let f = (x: int, ~extra: int, y: int) => [x, extra, y] | ||
| let withOpt = (x: int, ~extra: option<int>=?, y: int) => [x, extra->Option.getOr(0), y] | ||
|
|
||
| describe(__MODULE__, () => { | ||
| let log = [] | ||
| let mark = (name, v) => { | ||
| log->Array.push(name) | ||
| v | ||
| } | ||
| let take = () => { | ||
| let names = log->Array.join("") | ||
| log->Array.splice(~start=0, ~remove=log->Array.length, ~insert=[]) | ||
| names | ||
| } | ||
|
|
||
| test("a function", () => { | ||
| let r = f(~extra=mark("b", 2), mark("a", 1), mark("c", 3)) | ||
| eq(__LOC__, "bac", take()) | ||
| eq(__LOC__, [1, 2, 3], r) | ||
| }) | ||
|
|
||
| test("a @send external", () => { | ||
| let r = send(target, ~extra=mark("b", 2), mark("a", 1), mark("c", 3)) | ||
| eq(__LOC__, "bac", take()) | ||
| eq(__LOC__, [1, 2, 3], r) | ||
| }) | ||
|
|
||
| test("an @obj external", () => { | ||
| let o = makeObj(~y=mark("y", 2), ~x=mark("x", 1)) | ||
| eq(__LOC__, "yx", take()) | ||
| eq(__LOC__, (1, 2), (o["x"], o["y"])) | ||
| }) | ||
|
|
||
| test("a callee that is a call", () => { | ||
| let getF = () => mark("f", f) | ||
| let r = getF()(~extra=mark("b", 2), mark("a", 1), mark("c", 3)) | ||
| eq(__LOC__, "fbac", take()) | ||
| eq(__LOC__, [1, 2, 3], r) | ||
| }) | ||
|
|
||
| test("a read after an effect that changes it", () => { | ||
| let n = ref(0) | ||
| let bump = () => { | ||
| n := n.contents + 1 | ||
| 10 | ||
| } | ||
| eq(__LOC__, [1, 10, 5], f(~extra=bump(), n.contents, 5)) | ||
| }) | ||
|
|
||
| test("an optional argument", () => { | ||
| let r = withOpt(~extra=?mark("b", Some(2)), mark("a", 1), mark("c", 3)) | ||
| eq(__LOC__, "bac", take()) | ||
| eq(__LOC__, [1, 2, 3], r) | ||
| }) | ||
|
|
||
| test("a partial application", () => { | ||
| let g = f(~extra=mark("b", 2), mark("a", 1), ...) | ||
| eq(__LOC__, "ba", take()) | ||
| eq(__LOC__, [1, 2, 3], g(3)) | ||
| }) | ||
|
|
||
| test("arguments already in order", () => { | ||
| let r = f(mark("a", 1), ~extra=mark("b", 2), mark("c", 3)) | ||
| eq(__LOC__, "abc", take()) | ||
| eq(__LOC__, [1, 2, 3], r) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.