From 9901b5493c01c4907063c078eca88874e77da2c6 Mon Sep 17 00:00:00 2001 From: dcode Date: Sun, 5 Sep 2021 11:22:00 +0200 Subject: [PATCH] Fix flow assertion on invalid function expression --- src/flow.ts | 1 - tests/compiler/function-expression-error.json | 8 ++++++++ tests/compiler/function-expression-error.ts | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/compiler/function-expression-error.json create mode 100644 tests/compiler/function-expression-error.ts diff --git a/src/flow.ts b/src/flow.ts index 691a8e55d7..d685df7409 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -1193,7 +1193,6 @@ export class Flow { canOverflow(expr: ExpressionRef, type: Type): bool { // TODO: the following catches most common and a few uncommon cases, but there are additional // opportunities here, obviously. - assert(type != Type.void); // types other than i8, u8, i16, u16 and bool do not overflow if (!type.isShortIntegerValue) return false; diff --git a/tests/compiler/function-expression-error.json b/tests/compiler/function-expression-error.json new file mode 100644 index 0000000000..6476b63d8e --- /dev/null +++ b/tests/compiler/function-expression-error.json @@ -0,0 +1,8 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "TS1110: Type expected.", "missingReturnType", + "EOF" + ] +} diff --git a/tests/compiler/function-expression-error.ts b/tests/compiler/function-expression-error.ts new file mode 100644 index 0000000000..310b903961 --- /dev/null +++ b/tests/compiler/function-expression-error.ts @@ -0,0 +1,5 @@ +// see: https://github.com/AssemblyScript/assemblyscript/issues/2036 + +const missingReturnType: u32 = (() => 42).index; + +ERROR("EOF");