Skip to content

Commit 2d45564

Browse files
authored
fix: Remove automatic type detection when emitting a select (AssemblyScript#2074)
1 parent 647cc5e commit 2d45564

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/builtins.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,8 @@ function builtin_max(ctx: BuiltinContext): ExpressionRef {
15541554
module.binary(op,
15551555
module.local_get(temp1.index, typeRef),
15561556
module.local_get(temp2.index, typeRef)
1557-
)
1557+
),
1558+
typeRef
15581559
);
15591560
flow.freeTempLocal(temp2);
15601561
flow.freeTempLocal(temp1);
@@ -1633,7 +1634,8 @@ function builtin_min(ctx: BuiltinContext): ExpressionRef {
16331634
module.binary(op,
16341635
module.local_get(temp1.index, typeRef),
16351636
module.local_get(temp2.index, typeRef)
1636-
)
1637+
),
1638+
typeRef
16371639
);
16381640
flow.freeTempLocal(temp2);
16391641
flow.freeTempLocal(temp1);
@@ -2770,7 +2772,7 @@ function builtin_select(ctx: BuiltinContext): ExpressionRef {
27702772
operands[2]
27712773
);
27722774
compiler.currentType = type;
2773-
return module.select(arg0, arg1, arg2);
2775+
return module.select(arg0, arg1, arg2, type.toRef());
27742776
}
27752777
builtins.set(BuiltinNames.select, builtin_select);
27762778

src/compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5245,7 +5245,8 @@ export class Compiler extends DiagnosticEmitter {
52455245
return module.select(
52465246
module.i32(1),
52475247
module.binary(BinaryOp.EqI32, rightExpr, module.i32(0)),
5248-
leftExpr
5248+
leftExpr,
5249+
TypeRef.I32
52495250
);
52505251
}
52515252
case TypeKind.I8:

src/module.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,12 +1475,8 @@ export class Module {
14751475
ifTrue: ExpressionRef,
14761476
ifFalse: ExpressionRef,
14771477
condition: ExpressionRef,
1478-
type: TypeRef = TypeRef.Auto
1478+
type: TypeRef
14791479
): ExpressionRef {
1480-
if (type == TypeRef.Auto) {
1481-
type = binaryen._BinaryenExpressionGetType(ifTrue);
1482-
assert(type == binaryen._BinaryenExpressionGetType(ifFalse));
1483-
}
14841480
return binaryen._BinaryenSelect(this.ref, condition, ifTrue, ifFalse, type);
14851481
}
14861482

tests/compiler/closure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ testVar();
1515

1616
function testLet(): (value: i32) => i32 {
1717
let $local0 = 0;
18-
return function inner(value: i32) {
18+
return function inner(value: i32): i32 {
1919
return $local0; // closure 3
2020
};
2121
}

0 commit comments

Comments
 (0)