From 38f36ef2cef10ecc7620db9f0f3d46c92d23abc6 Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Tue, 14 May 2024 20:14:37 +0900 Subject: [PATCH] =?UTF-8?q?=E9=96=A2=E6=95=B0=E3=81=AE=E7=9C=81=E7=95=A5?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=9F=E5=BC=95=E6=95=B0=E3=81=ABNULL?= =?UTF-8?q?=E3=82=92=E6=A0=BC=E7=B4=8D=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=20(#639)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update index.ts * add test * Update CHANGELOG.md --- CHANGELOG.md | 2 ++ src/interpreter/index.ts | 2 +- test/index.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) 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', () => {