Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the builtin call throw bug #244

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading