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: { 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