diff --git a/src/builtins.ts b/src/builtins.ts index 22228cfb22..7bc25737e0 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -1554,7 +1554,8 @@ function builtin_max(ctx: BuiltinContext): ExpressionRef { module.binary(op, module.local_get(temp1.index, typeRef), module.local_get(temp2.index, typeRef) - ) + ), + typeRef ); flow.freeTempLocal(temp2); flow.freeTempLocal(temp1); @@ -1633,7 +1634,8 @@ function builtin_min(ctx: BuiltinContext): ExpressionRef { module.binary(op, module.local_get(temp1.index, typeRef), module.local_get(temp2.index, typeRef) - ) + ), + typeRef ); flow.freeTempLocal(temp2); flow.freeTempLocal(temp1); @@ -2770,7 +2772,7 @@ function builtin_select(ctx: BuiltinContext): ExpressionRef { operands[2] ); compiler.currentType = type; - return module.select(arg0, arg1, arg2); + return module.select(arg0, arg1, arg2, type.toRef()); } builtins.set(BuiltinNames.select, builtin_select); diff --git a/src/compiler.ts b/src/compiler.ts index d8ee0cdf74..82be831671 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -5245,7 +5245,8 @@ export class Compiler extends DiagnosticEmitter { return module.select( module.i32(1), module.binary(BinaryOp.EqI32, rightExpr, module.i32(0)), - leftExpr + leftExpr, + TypeRef.I32 ); } case TypeKind.I8: diff --git a/src/module.ts b/src/module.ts index 1ee657b283..b3406bfe94 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1475,12 +1475,8 @@ export class Module { ifTrue: ExpressionRef, ifFalse: ExpressionRef, condition: ExpressionRef, - type: TypeRef = TypeRef.Auto + type: TypeRef ): ExpressionRef { - if (type == TypeRef.Auto) { - type = binaryen._BinaryenExpressionGetType(ifTrue); - assert(type == binaryen._BinaryenExpressionGetType(ifFalse)); - } return binaryen._BinaryenSelect(this.ref, condition, ifTrue, ifFalse, type); } diff --git a/tests/compiler/closure.ts b/tests/compiler/closure.ts index c542f3b1a7..fc23ecbf89 100644 --- a/tests/compiler/closure.ts +++ b/tests/compiler/closure.ts @@ -15,7 +15,7 @@ testVar(); function testLet(): (value: i32) => i32 { let $local0 = 0; - return function inner(value: i32) { + return function inner(value: i32): i32 { return $local0; // closure 3 }; }