From 068076a0463b8c0fab086ca21acd4cde87a1d554 Mon Sep 17 00:00:00 2001 From: Su Yihan Date: Tue, 16 Apr 2024 15:03:54 +0800 Subject: [PATCH] fix bug of any boxed obj as return value Signed-off-by: Su Yihan --- src/backend/binaryen/wasm_expr_gen.ts | 6 +++++- tests/samples/any_box_obj_as_return_value.ts | 13 +++++++++++++ tools/validate/wamr/validation.json | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/samples/any_box_obj_as_return_value.ts diff --git a/src/backend/binaryen/wasm_expr_gen.ts b/src/backend/binaryen/wasm_expr_gen.ts index e893952..fdaa63d 100644 --- a/src/backend/binaryen/wasm_expr_gen.ts +++ b/src/backend/binaryen/wasm_expr_gen.ts @@ -4639,7 +4639,11 @@ export class WASMExpressionGen { createDynObjOps.push( this.module.local.get(tmpVar.index, tmpVar.type), ); - castedValueRef = this.module.block(null, createDynObjOps); + castedValueRef = this.module.block( + null, + createDynObjOps, + tmpVar.type, + ); } return castedValueRef; } diff --git a/tests/samples/any_box_obj_as_return_value.ts b/tests/samples/any_box_obj_as_return_value.ts new file mode 100644 index 0000000..08eb528 --- /dev/null +++ b/tests/samples/any_box_obj_as_return_value.ts @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +function getAnyObj(): any { + return { a: 1 }; +} + +export function getObjPropFromReturnValue() { + const obj: any = getAnyObj(); + console.log(obj.a); +} diff --git a/tools/validate/wamr/validation.json b/tools/validate/wamr/validation.json index cbfcd57..5cb1cf7 100644 --- a/tools/validate/wamr/validation.json +++ b/tools/validate/wamr/validation.json @@ -179,6 +179,16 @@ } ] }, + { + "module": "any_box_obj_as_return_value", + "entries": [ + { + "name": "getObjPropFromReturnValue", + "args": [], + "result": "1" + } + ] + }, { "module": "any_box_string", "entries": [