Skip to content

Commit 58ff36c

Browse files
authored
静的な式がラベル付きの式を許容する問題を修正 (#1001)
1 parent cc03bb6 commit 58ff36c

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/parser/syntaxes/expressions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function parseAtom(s: ITokenStream, isStatic: boolean): Ast.Expression {
288288
return expr;
289289
}
290290
case TokenKind.Sharp: {
291+
if (isStatic) break;
291292
return parseExprWithLabel(s);
292293
}
293294
}

test/aison.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ greet()`)).toThrow();
6262
expect(() => AiSON.parse('{key: (3 + 5)}')).toThrow();
6363
});
6464

65+
test.concurrent('not allowed: labeled expression', () => {
66+
expect(() => AiSON.parse('#label: eval { 1 }')).toThrow();
67+
});
68+
6569
test.concurrent('not allowed: multiple statements (string)', () => {
6670
expect(() => AiSON.parse(`"hello"
6771

test/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as assert from 'assert';
7-
import { describe, test } from 'vitest';
7+
import { describe, expect, test } from 'vitest';
88
import { Parser, Interpreter, Ast } from '../src';
99
import { NUM, STR, NULL, ARR, OBJ, BOOL, TRUE, FALSE, ERROR ,FN_NATIVE } from '../src/interpreter/value';
1010
import { AiScriptSyntaxError, AiScriptRuntimeError, AiScriptIndexOutOfRangeError } from '../src/error';
@@ -948,6 +948,16 @@ describe('Attribute', () => {
948948
const attr = member.attr[0];
949949
assert.equal(attr.name, 'test');
950950
});
951+
952+
test.concurrent('non-static expression is not allowed', async () => {
953+
const parser = new Parser();
954+
expect(() => {
955+
parser.parse(`
956+
#[x #label: eval { 1 }]
957+
@f() {}
958+
`);
959+
}).toThrow();
960+
});
951961
});
952962

953963
describe('Location', () => {

test/syntax.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as assert from 'assert';
2-
import { describe, test } from 'vitest';
2+
import { describe, expect, test } from 'vitest';
33
import { utils } from '../src';
44
import { NUM, STR, NULL, ARR, OBJ, BOOL, TRUE, FALSE, ERROR ,FN_NATIVE } from '../src/interpreter/value';
55
import { AiScriptRuntimeError, AiScriptUnexpectedEOFError } from '../src/error';
@@ -1115,6 +1115,14 @@ describe('meta', () => {
11151115
assert.fail();
11161116
});
11171117
});
1118+
1119+
describe('Labeled expression', () => {
1120+
test.concurrent('invalid', async () => {
1121+
expect(() => getMeta(`
1122+
### x #label: eval { 1 }
1123+
`)).toThrow();
1124+
});
1125+
});
11181126
});
11191127

11201128
describe('namespace', () => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix: メタデータ構文や属性、AiSONにラベル付きの式を記述してもエラーが発生しない問題を修正

0 commit comments

Comments
 (0)