parser: error on duplicate enum declaration

pull/7264/head
joe-conigliaro 2020-12-11 19:30:47 +11:00
parent 668483ee56
commit 14c4ba6dd9
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
1 changed files with 6 additions and 1 deletions

View File

@ -1890,6 +1890,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
} }
p.check(.key_enum) p.check(.key_enum)
end_pos := p.tok.position() end_pos := p.tok.position()
name_pos := p.tok.position()
enum_name := p.check_name() enum_name := p.check_name()
if enum_name.len == 1 { if enum_name.len == 1 {
p.error_with_pos('single letter capital names are reserved for generic template types.', p.error_with_pos('single letter capital names are reserved for generic template types.',
@ -1948,7 +1949,7 @@ $pubfn (mut e $enum_name) toggle(flag $enum_name) { unsafe{ *e = int(*e) ^ (
// //
') ')
} }
p.table.register_type_symbol(table.TypeSymbol{ idx := p.table.register_type_symbol(table.TypeSymbol{
kind: .enum_ kind: .enum_
name: name name: name
cname: util.no_dots(name) cname: util.no_dots(name)
@ -1959,6 +1960,10 @@ $pubfn (mut e $enum_name) toggle(flag $enum_name) { unsafe{ *e = int(*e) ^ (
is_multi_allowed: is_multi_allowed is_multi_allowed: is_multi_allowed
} }
}) })
if idx == -1 {
p.error_with_pos('cannot register enum `$name`, another type with this name exists',
name_pos)
}
return ast.EnumDecl{ return ast.EnumDecl{
name: name name: name
is_pub: is_pub is_pub: is_pub