vxx2 / vlib / v / checker / tests / interface_struct_comparison_err.vv
36 lines · 32 sloc · 519 bytes · 856b923cc9ec4c0628f094eae6fd735ab5c5a669
Raw
1module main
2
3@[heap]
4interface IGameObject {
5mut:
6 name string
7 speed f32
8 owner ?&IGameObject
9 collision(mut o IGameObject)
10}
11
12@[heap]
13struct GameObject implements IGameObject {
14mut:
15 name string
16 speed f32
17 owner ?&IGameObject
18}
19
20fn (mut gameobject GameObject) collision(mut o IGameObject) {
21 _ = o
22 if gameobject != gameobject.owner {
23 eprintln('Collision')
24 }
25}
26
27fn main() {
28 mut ship := &GameObject{
29 name: 'ship'
30 }
31 mut rocket := &GameObject{
32 name: 'rocket'
33 owner: ship
34 }
35 rocket.collision(mut ship)
36}
37