File tree 2 files changed +47
-0
lines changed
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
24
24
mut right_len := node.right.len
25
25
mut right_first_type := ast.void_type
26
26
old_recheck := c.inside_recheck
27
+
27
28
// check if we are rechecking an already checked expression on generic rechecking
28
29
c.inside_recheck = old_recheck || node.right_types.len > 0
29
30
defer {
@@ -75,6 +76,9 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
75
76
c.error ('cannot use `<-` on the right-hand side of an assignment, as it does not return any values' ,
76
77
right.pos)
77
78
} else if c.inside_recheck {
79
+ if i < node.right_types.len {
80
+ c.expected_type = node.right_types[i]
81
+ }
78
82
mut right_type := c.expr (mut right)
79
83
right_type_sym := c.table.sym (right_type)
80
84
// fixed array returns an struct, but when assigning it must be the array type
Original file line number Diff line number Diff line change
1
+ pub type FnGridObject = fn (mut object GridObject)
2
+
3
+ @[flag]
4
+ pub enum GridObjectAuto {
5
+ drag
6
+ drop
7
+ scale_on_hover
8
+ pickup
9
+ sound
10
+ off // auto "deactivation"
11
+ }
12
+
13
+ @[params]
14
+ pub struct GridObjectConfig {
15
+ auto GridObjectAuto = ~ GridObjectAuto.zero ()
16
+ on ? FnGridObject
17
+ }
18
+
19
+ @[heap]
20
+ struct GridObject {
21
+ mut :
22
+ config GridObjectConfig
23
+ auto GridObjectAuto = ~ GridObjectAuto.zero ()
24
+ }
25
+
26
+ pub fn on (config GridObjectConfig) & GridObject {
27
+ mut ob := & GridObject{}
28
+ ob.config = config
29
+ ob.auto = config.auto
30
+ if func := ob.config.on {
31
+ func (mut ob)
32
+ }
33
+ return ob
34
+ }
35
+
36
+ fn test_main () {
37
+ _ := on (
38
+ on: fn (mut o GridObject) {
39
+ o.auto = .off | .pickup | .sound
40
+ }
41
+ )
42
+ assert true
43
+ }
You can’t perform that action at this time.
0 commit comments