mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
This commit is contained in:
parent
63a192ccb3
commit
730b3f5e0f
3 changed files with 32 additions and 0 deletions
|
@ -192,6 +192,10 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.is_method {
|
if node.is_method {
|
||||||
|
if node.receiver.name in c.global_names {
|
||||||
|
c.error('cannot use global variable name `${node.receiver.name}` as receiver',
|
||||||
|
node.receiver_pos)
|
||||||
|
}
|
||||||
if node.receiver.typ.has_flag(.option) {
|
if node.receiver.typ.has_flag(.option) {
|
||||||
c.error('option types cannot have methods', node.receiver_pos)
|
c.error('option types cannot have methods', node.receiver_pos)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/checker/tests/globals/global_receiver_var_name_err.vv:17:9: error: cannot use global variable name `game` as receiver
|
||||||
|
15 | }
|
||||||
|
16 |
|
||||||
|
17 | fn (mut game Game) init() {
|
||||||
|
| ~~~~~~~~~
|
||||||
|
18 | game.world = GameObject{}
|
||||||
|
19 | }
|
21
vlib/v/checker/tests/globals/global_receiver_var_name_err.vv
Normal file
21
vlib/v/checker/tests/globals/global_receiver_var_name_err.vv
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
struct Game {
|
||||||
|
mut:
|
||||||
|
world GameObject
|
||||||
|
object_id u32
|
||||||
|
}
|
||||||
|
|
||||||
|
__global (
|
||||||
|
game Game
|
||||||
|
)
|
||||||
|
|
||||||
|
struct GameObject {
|
||||||
|
id int = game.object_id++
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut game Game) init() {
|
||||||
|
game.world = GameObject{}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue