From 32e5f64bc1e08a1e26c36f395759ba7a13b85969 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 24 Sep 2024 09:46:18 +0800 Subject: [PATCH] fix: report error for mulitple union type Fixes: #2870 --- src/parser.ts | 2 +- tests/parser/union.ts | 9 +++++++++ tests/parser/union.ts.fixture.ts | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/parser/union.ts create mode 100644 tests/parser/union.ts.fixture.ts diff --git a/src/parser.ts b/src/parser.ts index 58050e837e..7c69843973 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -631,7 +631,7 @@ export class Parser extends DiagnosticEmitter { } // ... | type while (tn.skip(Token.Bar)) { - let nextType = this.parseType(tn, false, true); + let nextType = this.parseType(tn, true, false); if (!nextType) return null; let typeIsNull = type.kind == NodeKind.NamedType && (type).isNull; let nextTypeIsNull = nextType.kind == NodeKind.NamedType && (nextType).isNull; diff --git a/tests/parser/union.ts b/tests/parser/union.ts new file mode 100644 index 0000000000..3d947fe09a --- /dev/null +++ b/tests/parser/union.ts @@ -0,0 +1,9 @@ +export function foo(a: aaa | bbb | ccc): i32 { + return 1; +} + +export function bar(a: i32 | u32 | f32): i32 { + return 1; +} + +export let a: i32 | u32 | f32 | null = 1; diff --git a/tests/parser/union.ts.fixture.ts b/tests/parser/union.ts.fixture.ts new file mode 100644 index 0000000000..b2fb8611bf --- /dev/null +++ b/tests/parser/union.ts.fixture.ts @@ -0,0 +1,4 @@ +export let a = 1; +// ERROR 100: "Not implemented: union types" in union.ts(1,36+3) +// ERROR 100: "Not implemented: union types" in union.ts(5,36+3) +// ERROR 100: "Not implemented: union types" in union.ts(9,27+10)