diff --git a/CHANGELOG.md b/CHANGELOG.md index 65815163..8d1626a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`でプログラムを緊急停止できるように diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 23df41ea..496e16ff 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -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); diff --git a/test/index.ts b/test/index.ts index 18e215b9..91492317 100644 --- a/test/index.ts +++ b/test/index.ts @@ -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', () => {