Skip to content

Commit ecf28b1

Browse files
authored
fix: Properly handle EnumValue in Flow#canOverflow (#2032)
1 parent 2e38a6e commit ecf28b1

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/flow.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import {
2626
Function,
2727
Element,
2828
ElementKind,
29-
Global,
3029
Field,
31-
Class
30+
Class,
31+
TypedElement
3232
} from "./program";
3333

3434
import {
@@ -1218,8 +1218,8 @@ export class Flow {
12181218
case ExpressionId.GlobalGet: {
12191219
// TODO: this is inefficient because it has to read a string
12201220
let global = assert(this.parentFunction.program.elementsByName.get(assert(getGlobalGetName(expr))));
1221-
assert(global.kind == ElementKind.GLOBAL);
1222-
return canConversionOverflow((<Global>global).type, type);
1221+
assert(global.kind == ElementKind.GLOBAL || global.kind == ElementKind.ENUMVALUE);
1222+
return canConversionOverflow((<TypedElement>global).type, type);
12231223
}
12241224

12251225
case ExpressionId.Binary: {

tests/compiler/enum-return-error.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"asc_flags": [
3+
],
4+
"stderr": [
5+
"AS200: Conversion from type 'i32' to 'bool' requires an explicit cast.",
6+
"EOF"
7+
]
8+
}

tests/compiler/enum-return-error.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enum Bar {
2+
Baz
3+
}
4+
5+
function foo(): boolean {
6+
return Bar.Baz;
7+
}
8+
9+
foo();
10+
11+
ERROR("EOF");

0 commit comments

Comments
 (0)