Skip to content

Commit

Permalink
関数の省略された引数にNULLを格納するように (#639)
Browse files Browse the repository at this point in the history
* Update index.ts

* add test

* Update CHANGELOG.md
  • Loading branch information
FineArchs authored May 14, 2024
1 parent 9e61804 commit 38f36ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- `Uri:encode_full`, `Uri:encode_component`, `Uri:decode_full`, `Uri:decode_component`を追加
- `str.starts_with`,`str.ends_with`を追加
- `arr.splice`を追加
- 関数の省略された引数にNULLを格納するように
- 一時的な措置であり、省略可能引数構文の実装と同時に廃止予定です。依存し過ぎないようにしてください

# 0.18.0
- `Core:abort`でプログラムを緊急停止できるように
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class Interpreter {
for (let i = 0; i < (fn.args ?? []).length; i++) {
_args.set(fn.args![i]!, {
isMutable: true,
value: args[i]!,
value: args[i] ?? NULL,
});
}
const fnScope = fn.scope!.createChildScope(_args);
Expand Down
10 changes: 10 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,16 @@ describe('Function call', () => {
}
assert.fail();
});

test.concurrent('omitted args', async () => {
const res = await exe(`
@f(x, y) {
[x, y]
}
<: f(1)
`);
eq(res, ARR([NUM(1), NULL]));
});
});

describe('Return', () => {
Expand Down

0 comments on commit 38f36ef

Please sign in to comment.