Cast to bool by comparing to zero (#343)

This commit is contained in:
Daniel Wirtz
2018-11-23 15:20:52 +01:00
committed by GitHub
parent b723ff3e88
commit c30c62e383
38 changed files with 1072 additions and 1023 deletions

View File

@ -7516,9 +7516,10 @@ export class Compiler extends DiagnosticEmitter {
}
case TypeKind.BOOL: {
if (flow.canOverflow(expr, type)) {
expr = module.createBinary(BinaryOp.AndI32,
// bool is special in that it compares to 0 instead of masking with 0x1
expr = module.createBinary(BinaryOp.NeI32,
expr,
module.createI32(0x1)
module.createI32(0)
);
}
break;