Skip to content

Commit

Permalink
fix union type in dynamiccall
Browse files Browse the repository at this point in the history
Signed-off-by: Su Yihan <[email protected]>
  • Loading branch information
yviansu committed Oct 24, 2023
1 parent 562723e commit 7d81c5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/backend/binaryen/wasm_expr_gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ export class WASMExpressionGen {
const methodName = value.name;
const owner = value.owner;
switch (owner.type.kind) {
case ValueTypeKind.UNION:
case ValueTypeKind.ANY: {
/* Fallback to libdyntype */
let invokeArgs = [owner];
Expand Down
19 changes: 19 additions & 0 deletions tests/samples/any_func_call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,22 @@ export function anyFuncCallWithNoCast() {
b.log();
b.increase();
}

class A1 {
test() {
console.log(1);
}
}
class B1 {
a?: A1 = new A1();
fun() {
if (this.a) {
this.a.test();
}
}
}

export function unionFuncCall() {
const b = new B1();
b.fun();
}
5 changes: 5 additions & 0 deletions tools/validate/wamr/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@
"name": "anyFuncCallWithNoCast",
"args": [],
"result": "Page class\n1"
},
{
"name": "unionFuncCall",
"args": [],
"result": "1"
}
]
},
Expand Down

0 comments on commit 7d81c5c

Please sign in to comment.