From 608c17503a40c94bfc53c8307aabe3df82479692 Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:45:24 +0900 Subject: [PATCH 1/8] fix args iteration --- src/interpreter/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 23df41ea..35da882d 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 (fn.args[i]) fn._args.set(fn.args[i], { isMutable: true, value: args[i]!, }); From 628a8819dcdd2de159f9fac2b9a1b741f29e71cf Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:47:31 +0900 Subject: [PATCH 2/8] fix --- src/interpreter/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 35da882d..8b2f89c4 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -237,7 +237,7 @@ export class Interpreter { } else { const _args = new Map(); if (fn.args) for (let i = 0; i < fn.args.length; i++) { - if (fn.args[i]) fn._args.set(fn.args[i], { + if (fn.args[i]) _args.set(fn.args[i], { isMutable: true, value: args[i]!, }); From a5cf0eb44b0b049fd79821fc5df9bd9ccfb9dce4 Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:50:44 +0900 Subject: [PATCH 3/8] type fix --- src/interpreter/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 8b2f89c4..56791f48 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -237,7 +237,7 @@ export class Interpreter { } else { const _args = new Map(); if (fn.args) for (let i = 0; i < fn.args.length; i++) { - if (fn.args[i]) _args.set(fn.args[i], { + if (fn.args[i]) _args.set(fn.args[i]!, { isMutable: true, value: args[i]!, }); From 5200ed069d4c6beac80ec5e2f4184f8be06c4b2d Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:02:56 +0900 Subject: [PATCH 4/8] add test --- test/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/index.ts b/test/index.ts index 290efa73..1e62bc5f 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1296,6 +1296,24 @@ describe('Function call', () => { } assert.fail(); }); + + test.concurrent('unprovided arg', async () => { + const res = await exe(` + @f(x) { return exists x } + <: f() + `); + eq(res, FALSE); + try { + await exe(` + @f(x) { return x } + <: f() + `); + } catch (e) { + assert.ok(e instanceof AiScriptRuntimeError); + return; + } + assert.fail(); + }); }); describe('Return', () => { From 3af713a709cd3ad7f9a538f4b600f5492e9c70de Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:09:22 +0900 Subject: [PATCH 5/8] Update index.ts --- src/interpreter/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts index 56791f48..5863853c 100644 --- a/src/interpreter/index.ts +++ b/src/interpreter/index.ts @@ -237,7 +237,7 @@ export class Interpreter { } else { const _args = new Map(); if (fn.args) for (let i = 0; i < fn.args.length; i++) { - if (fn.args[i]) _args.set(fn.args[i]!, { + if (args[i]) _args.set(fn.args[i]!, { isMutable: true, value: args[i]!, }); From 0258d512063b760a0a8ab6cf1ecbaa83b02537a9 Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:26:05 +0900 Subject: [PATCH 6/8] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6785f099..54dee9e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ [Read translated version (en)](./translations/en/CHANGELOG.md) +# 未リリース分 +- 関数の省略された引数は`exists`でfalseを返すように + # 0.18.0 - `Core:abort`でプログラムを緊急停止できるように - `index_of`の配列版を追加 From 1f6307fea60c58f74c6ddf8c70af34384039b7a2 Mon Sep 17 00:00:00 2001 From: Fine Archs Date: Thu, 25 Apr 2024 16:34:17 +0900 Subject: [PATCH 7/8] api extractor --- etc/aiscript.api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From 5f70fd13550fd47f72b2413705df7623fd33d337 Mon Sep 17 00:00:00 2001 From: FineArchs <133759614+FineArchs@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:59:05 +0900 Subject: [PATCH 8/8] revise test --- test/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/index.ts b/test/index.ts index 1e62bc5f..08104a54 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1297,12 +1297,15 @@ describe('Function call', () => { assert.fail(); }); - test.concurrent('unprovided arg', async () => { + 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 }