From 9287047ea93a0f119fe555f438fa8f50702916c7 Mon Sep 17 00:00:00 2001 From: peze Date: Tue, 21 Jan 2025 14:55:11 +0800 Subject: [PATCH] fix the builtin call throw bug --- lib/semantic.js | 2 +- test/semantic.test.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/semantic.js b/lib/semantic.js index 71bfeae..8e76399 100644 --- a/lib/semantic.js +++ b/lib/semantic.js @@ -2510,7 +2510,7 @@ class TypeChecker { ast.isStatic = definedApi.type === 'api' ? false : definedApi.isStatic; ast.isAsync = definedApi.type === 'api' ? true : definedApi.isAsync; ast.inferred = this.getType(definedApi.returnType); - ast.hasThrow = ast.isAsync || definedApi.hasThrow; + ast.hasThrow = !builtin.has(name) && (ast.isAsync || definedApi.hasThrow); } visitConstruct(ast, env) { diff --git a/test/semantic.test.js b/test/semantic.test.js index 28828d6..3ab634e 100644 --- a/test/semantic.test.js +++ b/test/semantic.test.js @@ -592,11 +592,16 @@ describe('semantic', function () { async function callId(): object { return call(); } + + async function sp(): void { + $sleep(30); + return; + } init();`, '__filename'); - var func = ast.moduleBody.nodes.find((item) => { + var func = ast.moduleBody.nodes.filter((item) => { return item.type === 'function'; }); - var returnExpr = func.functionBody.stmts.stmts[0]; + var returnExpr = func[0].functionBody.stmts.stmts[0]; expect(returnExpr).to.eql({ type: 'return', 'loc': loc(10, 11, 11, 9), @@ -626,6 +631,9 @@ describe('semantic', function () { 'loc': loc(10, 18, 10, 24) } }); + + var sleepStmt = func[1].functionBody.stmts.stmts[0]; + expect(sleepStmt.hasThrow).to.eql(false); }); it('submodel should ok', function () {