Skip to content

Commit 85389f3

Browse files
authored
型引数で定義された型に型引数を与えてもエラーが発生しない問題を修正 (#1006)
1 parent 02f4fb1 commit 85389f3

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export function getTypeNameBySource(typeSource: Ast.TypeSource): string {
168168
export function getTypeBySource(typeSource: Ast.TypeSource, typeParams?: readonly Ast.TypeParam[]): Type {
169169
if (typeSource.type === 'namedTypeSource') {
170170
const typeParam = typeParams?.find((param) => param.name === typeSource.name);
171-
if (typeParam != null) {
171+
if (typeParam != null && typeSource.inner == null) {
172172
return T_PARAM(typeParam.name);
173173
}
174174

test/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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';
5-
import { AiScriptRuntimeError } from '../src/error';
5+
import { AiScriptRuntimeError, AiScriptSyntaxError } from '../src/error';
66
import { exe, getMeta, eq } from './testutils';
77

88
describe('function types', () => {
@@ -108,6 +108,12 @@ describe('generics', () => {
108108
@f<>() {}
109109
`));
110110
});
111+
112+
test.concurrent('cannot have inner type', async () => {
113+
await expect(() => exe(`
114+
@f<T>(v: T<num>) {}
115+
`)).rejects.toThrow(AiScriptSyntaxError);
116+
});
111117
});
112118
});
113119

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix: 型引数で定義された型に型引数を与えてもエラーが発生しない問題を修正

0 commit comments

Comments
 (0)