Skip to content

Commit

Permalink
fix the builtin call throw bug
Browse files Browse the repository at this point in the history
  • Loading branch information
peze authored and yndu13 committed Jan 21, 2025
1 parent 99b0905 commit 69f9ea3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/semantic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions test/semantic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 69f9ea3

Please sign in to comment.