parser: fail for section redefinition in struct

pull/4647/head
Enzo Baldisserri 2020-04-29 13:32:39 +02:00 committed by GitHub
parent 98cd013908
commit 390d88f933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -38,6 +38,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
mut mut_pos := -1
mut pub_pos := -1
mut pub_mut_pos := -1
mut global_pos := -1
mut is_field_mut := false
mut is_field_pub := false
mut is_field_global := false
@ -51,12 +52,18 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
if p.tok.kind == .key_pub {
p.check(.key_pub)
if p.tok.kind == .key_mut {
if pub_mut_pos != -1 {
p.error('redefinition of `pub mut` section')
}
p.check(.key_mut)
pub_mut_pos = fields.len
is_field_pub = true
is_field_mut = true
is_field_global = false
} else {
if pub_pos != -1 {
p.error('redefinition of `pub` section')
}
pub_pos = fields.len
is_field_pub = true
is_field_mut = false
@ -64,6 +71,9 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
}
p.check(.colon)
} else if p.tok.kind == .key_mut {
if mut_pos != -1 {
p.error('redefinition of `mut` section')
}
p.check(.key_mut)
p.check(.colon)
mut_pos = fields.len
@ -71,8 +81,12 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
is_field_mut = true
is_field_global = false
} else if p.tok.kind == .key_global {
if global_pos != -1 {
p.error('redefinition of `global` section')
}
p.check(.key_global)
p.check(.colon)
global_pos = fields.len
is_field_pub = true
is_field_mut = true
is_field_global = true