Skip to content

fix: Expression passed to evaluateCondition asserted to be valid #2013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.