mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: disallow having builtin type as type names for enum
, sum type
and alias
(#19043)
This commit is contained in:
parent
9f5e9ba1cf
commit
6a4bfef2c5
@ -4011,7 +4011,8 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
|||||||
}
|
}
|
||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
})
|
})
|
||||||
if idx == -1 {
|
if idx in [ast.invalid_type_idx, ast.string_type_idx, ast.rune_type_idx, ast.array_type_idx,
|
||||||
|
ast.map_type_idx] {
|
||||||
p.error_with_pos('cannot register enum `${name}`, another type with this name exists',
|
p.error_with_pos('cannot register enum `${name}`, another type with this name exists',
|
||||||
end_pos)
|
end_pos)
|
||||||
}
|
}
|
||||||
@ -4109,7 +4110,8 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
|||||||
}
|
}
|
||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
})
|
})
|
||||||
if typ == ast.invalid_type_idx {
|
if typ in [ast.invalid_type_idx, ast.string_type_idx, ast.rune_type_idx, ast.array_type_idx,
|
||||||
|
ast.map_type_idx] {
|
||||||
p.error_with_pos('cannot register sum type `${name}`, another type with this name exists',
|
p.error_with_pos('cannot register sum type `${name}`, another type with this name exists',
|
||||||
name_pos)
|
name_pos)
|
||||||
return ast.SumTypeDecl{}
|
return ast.SumTypeDecl{}
|
||||||
@ -4149,7 +4151,8 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
|||||||
is_pub: is_pub
|
is_pub: is_pub
|
||||||
})
|
})
|
||||||
type_end_pos := p.prev_tok.pos()
|
type_end_pos := p.prev_tok.pos()
|
||||||
if idx == ast.invalid_type_idx {
|
if idx in [ast.invalid_type_idx, ast.string_type_idx, ast.rune_type_idx, ast.array_type_idx,
|
||||||
|
ast.map_type_idx] {
|
||||||
p.error_with_pos('cannot register alias `${name}`, another type with this name exists',
|
p.error_with_pos('cannot register alias `${name}`, another type with this name exists',
|
||||||
name_pos)
|
name_pos)
|
||||||
return ast.AliasTypeDecl{}
|
return ast.AliasTypeDecl{}
|
||||||
|
3
vlib/v/parser/tests/builtin_alias_type_name_err.out
Normal file
3
vlib/v/parser/tests/builtin_alias_type_name_err.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
vlib/v/parser/tests/builtin_alias_type_name_err.vv:1:6: error: cannot register alias `string`, another type with this name exists
|
||||||
|
1 | type string = int
|
||||||
|
| ~~~~~~
|
1
vlib/v/parser/tests/builtin_alias_type_name_err.vv
Normal file
1
vlib/v/parser/tests/builtin_alias_type_name_err.vv
Normal file
@ -0,0 +1 @@
|
|||||||
|
type string = int
|
5
vlib/v/parser/tests/builtin_enum_type_name_err.out
Normal file
5
vlib/v/parser/tests/builtin_enum_type_name_err.out
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
vlib/v/parser/tests/builtin_enum_type_name_err.vv:1:6: error: cannot register enum `rune`, another type with this name exists
|
||||||
|
1 | enum rune {
|
||||||
|
| ~~~~
|
||||||
|
2 | a
|
||||||
|
3 | b
|
5
vlib/v/parser/tests/builtin_enum_type_name_err.vv
Normal file
5
vlib/v/parser/tests/builtin_enum_type_name_err.vv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
enum rune {
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
}
|
3
vlib/v/parser/tests/builtin_sum_type_type_name_err.out
Normal file
3
vlib/v/parser/tests/builtin_sum_type_type_name_err.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
vlib/v/parser/tests/builtin_sum_type_type_name_err.vv:1:6: error: cannot register sum type `map`, another type with this name exists
|
||||||
|
1 | type map = int | u64
|
||||||
|
| ~~~
|
1
vlib/v/parser/tests/builtin_sum_type_type_name_err.vv
Normal file
1
vlib/v/parser/tests/builtin_sum_type_type_name_err.vv
Normal file
@ -0,0 +1 @@
|
|||||||
|
type map = int | u64
|
Loading…
Reference in New Issue
Block a user