Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: fn type declaration does not check already registered name #20732

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions vlib/v/parser/parse_type.v
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@ fn (mut p Parser) parse_fn_type(name string, generic_types []ast.Type) ast.Type
// MapFooFn typedefs are manually added in cheaders.v
// because typedefs get generated after the map struct is generated
has_decl := p.builtin_mod && name.starts_with('Map') && name.ends_with('Fn')
already_exists := p.table.find_type_idx(name) != 0
idx := p.table.find_or_register_fn_type(func, false, has_decl)
if already_exists && p.table.sym_by_idx(idx).kind != .function {
p.error_with_pos('cannot register fn `${name}`, another type with this name exists',
fn_type_pos)
}
if has_generic {
return ast.new_type(idx).set_flag(.generic)
}
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/parser/tests/already_existing_sym_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vlib/v/parser/tests/already_existing_sym_err.vv:16:6: error: cannot register fn `vnkxcb.Nk_plugin_alloc`, another type with this name exists
14 | }
15 |
16 | type Nk_plugin_alloc = fn (Nk_handle, voidptr, Nk_size) voidptr
| ~~~~~~~~~~~~~~~
16 changes: 16 additions & 0 deletions vlib/v/parser/tests/already_existing_sym_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@[translated]
module vnkxcb

type Nk_size = u32

union Nk_handle {
ptr voidptr
id int
}

enum Nk_plugin_alloc {
nk_tree_node
nk_tree_tab
}

type Nk_plugin_alloc = fn (Nk_handle, voidptr, Nk_size) voidptr
Loading