From 6b551fbfea1f68526374effbeac925d201c5d800 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Thu, 12 Aug 2021 16:58:13 -0500 Subject: [PATCH 1/2] fix flow.canOverflow --- src/flow.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/flow.ts b/src/flow.ts index ee8671ee8f..691a8e55d7 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -26,9 +26,9 @@ import { Function, Element, ElementKind, - Global, Field, - Class + Class, + TypedElement } from "./program"; import { @@ -1218,8 +1218,8 @@ export class Flow { case ExpressionId.GlobalGet: { // TODO: this is inefficient because it has to read a string let global = assert(this.parentFunction.program.elementsByName.get(assert(getGlobalGetName(expr)))); - assert(global.kind == ElementKind.GLOBAL); - return canConversionOverflow((global).type, type); + assert(global.kind == ElementKind.GLOBAL || global.kind == ElementKind.ENUMVALUE); + return canConversionOverflow((global).type, type); } case ExpressionId.Binary: { From 6322c4542d90b0d4516bf10a1409d14c7b875643 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Thu, 12 Aug 2021 16:58:35 -0500 Subject: [PATCH 2/2] add test --- tests/compiler/enum-return-error.json | 8 ++++++++ tests/compiler/enum-return-error.ts | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/compiler/enum-return-error.json create mode 100644 tests/compiler/enum-return-error.ts diff --git a/tests/compiler/enum-return-error.json b/tests/compiler/enum-return-error.json new file mode 100644 index 0000000000..3ca34eef92 --- /dev/null +++ b/tests/compiler/enum-return-error.json @@ -0,0 +1,8 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "AS200: Conversion from type 'i32' to 'bool' requires an explicit cast.", + "EOF" + ] +} diff --git a/tests/compiler/enum-return-error.ts b/tests/compiler/enum-return-error.ts new file mode 100644 index 0000000000..2f1a2df409 --- /dev/null +++ b/tests/compiler/enum-return-error.ts @@ -0,0 +1,11 @@ +enum Bar { + Baz +} + +function foo(): boolean { + return Bar.Baz; +} + +foo(); + +ERROR("EOF"); \ No newline at end of file