diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fabbc0d..54dee9e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ [Read translated version (en)](./translations/en/CHANGELOG.md) # 未リリース分 +- 関数の省略された引数は`exists`でfalseを返すように # 0.18.0 - `Core:abort`でプログラムを緊急停止できるように diff --git a/etc/aiscript.api.md b/etc/aiscript.api.md index e06fa825..b35a710b 100644 --- a/etc/aiscript.api.md +++ b/etc/aiscript.api.md @@ -23,7 +23,7 @@ type AddAssign_2 = NodeBase_2 & { }; // @public (undocumented) -export const AISCRIPT_VERSION: "0.18.0"; +export const AISCRIPT_VERSION: "0.19.0"; // @public (undocumented) abstract class AiScriptError extends Error { diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 23df41ea..5863853c 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -236,8 +236,8 @@ export class Interpreter { return result ?? NULL; } else { const _args = new Map(); - for (let i = 0; i < (fn.args ?? []).length; i++) { - _args.set(fn.args![i]!, { + if (fn.args) for (let i = 0; i < fn.args.length; i++) { + if (args[i]) _args.set(fn.args[i]!, { isMutable: true, value: args[i]!, }); diff --git a/test/index.ts b/test/index.ts index 290efa73..08104a54 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1296,6 +1296,27 @@ describe('Function call', () => { } assert.fail(); }); + + test.concurrent('exists on unprovided arg', async () => { + const res = await exe(` + @f(x) { return exists x } + <: f() + `); + eq(res, FALSE); + }); + + test.concurrent('accessing unprovided arg', async () => { + try { + await exe(` + @f(x) { return x } + <: f() + `); + } catch (e) { + assert.ok(e instanceof AiScriptRuntimeError); + return; + } + assert.fail(); + }); }); describe('Return', () => {