Skip to content

Commit 81c2bad

Browse files
authored
fix: Expression passed to evaluateCondition asserted to be valid (#2013)
1 parent dd5111b commit 81c2bad

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/compiler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10067,7 +10067,11 @@ export class Compiler extends DiagnosticEmitter {
1006710067

1006810068
/** Evaluates a boolean condition, determining whether it is TRUE, FALSE or UNKNOWN. */
1006910069
evaluateCondition(expr: ExpressionRef): ConditionKind {
10070-
assert(getExpressionType(expr) == TypeRef.I32);
10070+
let type = getExpressionType(expr);
10071+
if (type == TypeRef.Unreachable)
10072+
return ConditionKind.UNKNOWN;
10073+
10074+
assert(type == TypeRef.I32);
1007110075
var module = this.module;
1007210076
var evaled = module.runExpression(expr, ExpressionRunnerFlags.Default);
1007310077
if (evaled) {
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+
"TS2304: Cannot find name 'unknown_var'.",
6+
"EOF"
7+
]
8+
}

tests/compiler/unknown-bool-ident.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if (1 <= unknown_var) {}
2+
ERROR("EOF");

tests/compiler/unknown-bool-ident.untouched.wat

Whitespace-only changes.

0 commit comments

Comments
 (0)