parser: fix parsing attribute after fn prototype with no return type (#8727)

pull/8742/head
Nick Treleaven 2021-02-14 07:05:20 +00:00 committed by GitHub
parent e4f15605c0
commit 82650ee813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -327,8 +327,10 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
mut end_pos := p.prev_tok.position()
// Return type
mut return_type := table.void_type
if p.tok.kind.is_start_of_type()
|| (p.tok.kind == .key_fn && p.tok.line_nr == p.prev_tok.line_nr) {
// don't confuse token on the next line: fn decl, [attribute]
same_line := p.tok.line_nr == p.prev_tok.line_nr
if (p.tok.kind.is_start_of_type() && (same_line || p.tok.kind != .lsbr))
|| (same_line && p.tok.kind == .key_fn) {
return_type = p.parse_type()
}
mut type_sym_method_idx := 0

View File

@ -44,6 +44,11 @@ type F6 = fn (int, int)
type F7 = fn (time.Time, int)
fn C.atoi(byteptr) int
fn C.freec(ptr voidptr)
[trusted]
fn C.exitc(code int)
// above checks attribute doesn't conflict with `freec` return type
fn foo() {
}