Skip to content

Commit

Permalink
fix runtime body when api return void
Browse files Browse the repository at this point in the history
  • Loading branch information
peze committed Jul 1, 2024
1 parent 2731549 commit f6764f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/semantic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,12 +1140,9 @@ class TypeChecker {
env.inReturnsBlock = true;
env.local.set('__response', _model('$Response'));
this.visitReturnBody(ast.returns, env);
if (returnType.tag === Tag.TYPE && returnType.lexeme === 'void') {
// no check for void
return;
}

if (!this.hasReturnStmt(ast.returns.stmts)) {
if (!(returnType.tag === Tag.TYPE && returnType.lexeme === 'void') &&
!this.hasReturnStmt(ast.returns.stmts)) {
this.error(`no return statement`, ast.apiName);
}
}
Expand Down
30 changes: 30 additions & 0 deletions test/semantic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6257,6 +6257,36 @@ describe('semantic', function () {
}).to.not.throwException();
});

it('runtime inferred type should be map when return type is void', function () {
const ast = parse(`
init() {}
api hello(): void {
__request.method = 'GET';
__request.pathname = '/';
__request.headers = {
host = 'www.test.com',
};
var retry = false;
} returns {
return;
} runtime {
}`, '__filename');
const runtimeBody = ast.moduleBody.nodes[1].runtimeBody;
expect(runtimeBody.inferred).to.eql({
'type': 'map',
'keyType': {
'type': 'basic',
'name': 'string'
},
'valueType': {
'type':'basic',
'name':'any'
}
});
});

it('api runtime option can use request & response varibles', function(){
expect(function () {
parse(`
Expand Down

0 comments on commit f6764f6

Please sign in to comment.