mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.parser: prohibit redeclaration of builtin types (#10563)
This commit is contained in:
parent
e9de30373f
commit
be8be3d319
@ -85,18 +85,22 @@ fn on_error(receiver voidptr, e &Error, work &Work) {
|
||||
```v oksyntax
|
||||
module main
|
||||
|
||||
import eventbus
|
||||
|
||||
const eb = eventbus.new()
|
||||
|
||||
struct Work {
|
||||
hours int
|
||||
}
|
||||
|
||||
struct Error {
|
||||
struct AnError {
|
||||
message string
|
||||
}
|
||||
|
||||
fn do_work() {
|
||||
work := Work{20}
|
||||
// get a mutable Params instance & put some data into it
|
||||
error := &Error{'Error: no internet connection.'}
|
||||
error := &AnError{'Error: no internet connection.'}
|
||||
// publish the event
|
||||
eb.publish('error', work, error)
|
||||
}
|
||||
|
@ -542,11 +542,7 @@ pub fn (t &Table) unalias_num_type(typ Type) Type {
|
||||
return typ
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||
// println('register_type_symbol( $typ.name )')
|
||||
existing_idx := t.type_idxs[typ.name]
|
||||
if existing_idx > 0 {
|
||||
fn (mut t Table) check_for_already_registered_symbol(typ TypeSymbol, existing_idx int) int {
|
||||
ex_type := t.type_symbols[existing_idx]
|
||||
match ex_type.kind {
|
||||
.placeholder {
|
||||
@ -578,8 +574,29 @@ pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return -2
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||
mut typ_idx := -2
|
||||
mut existing_idx := t.type_idxs[typ.name]
|
||||
if existing_idx > 0 {
|
||||
typ_idx = t.check_for_already_registered_symbol(typ, existing_idx)
|
||||
if typ_idx != -2 {
|
||||
return typ_idx
|
||||
}
|
||||
typ_idx := t.type_symbols.len
|
||||
}
|
||||
if typ.mod == 'main' {
|
||||
existing_idx = t.type_idxs[typ.name.trim_prefix('main.')]
|
||||
if existing_idx > 0 {
|
||||
typ_idx = t.check_for_already_registered_symbol(typ, existing_idx)
|
||||
if typ_idx != -2 {
|
||||
return typ_idx
|
||||
}
|
||||
}
|
||||
}
|
||||
typ_idx = t.type_symbols.len
|
||||
t.type_symbols << typ
|
||||
t.type_idxs[typ.name] = typ_idx
|
||||
return typ_idx
|
||||
|
@ -0,0 +1,3 @@
|
||||
vlib/v/parser/tests/prohibit_redeclaration_of_builtin_types.vv:1:8: error: cannot register struct `Option`, another type with this name exists
|
||||
1 | struct Option {}
|
||||
| ~~~~~~
|
@ -0,0 +1 @@
|
||||
struct Option {}
|
Loading…
Reference in New Issue
Block a user