Skip to content

Commit

Permalink
fix: Expression passed to evaluateCondition asserted to be valid (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
romdotdog authored Aug 2, 2021
1 parent dd5111b commit 81c2bad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10067,7 +10067,11 @@ export class Compiler extends DiagnosticEmitter {

/** Evaluates a boolean condition, determining whether it is TRUE, FALSE or UNKNOWN. */
evaluateCondition(expr: ExpressionRef): ConditionKind {
assert(getExpressionType(expr) == TypeRef.I32);
let type = getExpressionType(expr);
if (type == TypeRef.Unreachable)
return ConditionKind.UNKNOWN;

assert(type == TypeRef.I32);
var module = this.module;
var evaled = module.runExpression(expr, ExpressionRunnerFlags.Default);
if (evaled) {
Expand Down
8 changes: 8 additions & 0 deletions tests/compiler/unknown-bool-ident.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"asc_flags": [
],
"stderr": [
"TS2304: Cannot find name 'unknown_var'.",
"EOF"
]
}
2 changes: 2 additions & 0 deletions tests/compiler/unknown-bool-ident.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if (1 <= unknown_var) {}
ERROR("EOF");
Empty file.

0 comments on commit 81c2bad

Please sign in to comment.