Skip to content

Commit df1f6f9

Browse files
Fix const enum compilation failure (#1120)
1 parent 209c875 commit df1f6f9

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ under the licensing terms detailed in LICENSE:
1919
* jhwgh1968 <[email protected]>
2020
* Jeffrey Charles <[email protected]>
2121
* Vladimir Tikhonov <[email protected]>
22+
* Duncan Uszkay <[email protected]>
2223

2324
Portions of this software are derived from third-party works licensed under
2425
the following terms:

src/compiler.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,10 +1084,16 @@ export class Compiler extends DiagnosticEmitter {
10841084
(<EnumValue>member).identifierNode.range.atEnd
10851085
);
10861086
}
1087-
initExpr = module.binary(BinaryOp.AddI32,
1088-
module.global_get(previousValue.internalName, NativeType.I32),
1089-
module.i32(1)
1090-
);
1087+
if (isInline) {
1088+
let value = i64_add(previousValue.constantIntegerValue, i64_new(1));
1089+
assert(!i64_high(value));
1090+
initExpr = module.i32(i64_low(value));
1091+
} else {
1092+
initExpr = module.binary(BinaryOp.AddI32,
1093+
module.global_get(previousValue.internalName, NativeType.I32),
1094+
module.i32(1)
1095+
);
1096+
}
10911097
initExpr = module.precomputeExpression(initExpr);
10921098
if (getExpressionId(initExpr) != ExpressionId.Const) {
10931099
if (element.is(CommonFlags.CONST)) {

tests/compiler/enum.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ export const enum ImplicitConst {
1212
THREE
1313
}
1414

15+
const enum ImplicitConstNoExport {
16+
ZERO,
17+
ONE,
18+
TWO,
19+
THREE
20+
}
21+
1522
export enum Explicit {
1623
ZERO = 0,
1724
ONE = 0 + 1,

0 commit comments

Comments
 (0)