Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 22, 2024
1 parent 4f39bac commit 2ab6cac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -3366,7 +3366,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as

fn (mut c Checker) check_for_mut_receiver(mut expr ast.Expr) (string, token.Pos) {
to_lock, pos := c.fail_if_immutable(mut expr)
if !expr.is_lvalue() {
if !expr.is_lvalue() && expr !is ast.CallExpr {
c.error('cannot pass expression as `mut`', expr.pos())
}
return to_lock, pos
Expand Down
54 changes: 54 additions & 0 deletions vlib/v/tests/fns/method_call_chain_mut_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
struct App {
name string
version string
mut:
commands []Command
flags []Flag
}

struct Command {
name string
execute fn (cmd Command) = unsafe { nil }
}

struct Flag {
name string
abbrev string
required bool
}

fn (mut app App) command(cmd Command) &App {
app.commands << cmd
return unsafe { app }
}

fn (mut app App) flag(flag Flag) &App {
app.flags << flag
return unsafe { app }
}

fn test_main() {
mut app := App{
name: 'amazing cli'
version: '0.1.0'
commands: []
flags: []
}

w := app.command(Command{
name: 'test'
execute: fn (cmd Command) {
println('Testing')
}
}).flag(Flag{
name: 'verbose'
abbrev: 'v'
required: true
})

println(app)
assert app.flags.len == 1
assert app.commands.len == 1
assert w.flags.len == 1
assert w.commands.len == 1
}

0 comments on commit 2ab6cac

Please sign in to comment.