Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 4, 2025
1 parent cb490a7 commit 53f920f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
mut right_len := node.right.len
mut right_first_type := ast.void_type
old_recheck := c.inside_recheck

// check if we are rechecking an already checked expression on generic rechecking
c.inside_recheck = old_recheck || node.right_types.len > 0
defer {
Expand Down Expand Up @@ -75,6 +76,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
c.error('cannot use `<-` on the right-hand side of an assignment, as it does not return any values',
right.pos)
} else if c.inside_recheck {
c.expected_type = node.right_types[i]
mut right_type := c.expr(mut right)
right_type_sym := c.table.sym(right_type)
// fixed array returns an struct, but when assigning it must be the array type
Expand Down
43 changes: 43 additions & 0 deletions vlib/v/tests/enums/enum_assign_on_anon_fn_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pub type FnGridObject = fn (mut object GridObject)

@[flag]
pub enum GridObjectAuto {
drag
drop
scale_on_hover
pickup
sound
off // auto "deactivation"
}

@[params]
pub struct GridObjectConfig {
auto GridObjectAuto = ~GridObjectAuto.zero()
on ?FnGridObject
}

@[heap]
struct GridObject {
mut:
config GridObjectConfig
auto GridObjectAuto = ~GridObjectAuto.zero()
}

pub fn on(config GridObjectConfig) &GridObject {
mut ob := &GridObject{}
ob.config = config
ob.auto = config.auto
if func := ob.config.on {
func(mut ob)
}
return ob
}

fn test_main() {
_ := on(
on: fn (mut o GridObject) {
o.auto = .off | .pickup | .sound
}
)
assert true
}

0 comments on commit 53f920f

Please sign in to comment.