mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: don't disallow method call chains (#7128)
This commit is contained in:
parent
f14bd10c00
commit
76ed8e3750
@ -994,8 +994,6 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
|
||||
// No automatic lock for array slicing (yet(?))
|
||||
explicit_lock_needed = true
|
||||
}
|
||||
} else {
|
||||
c.error('cannot use function call as mut', expr.pos)
|
||||
}
|
||||
}
|
||||
ast.ArrayInit {
|
||||
|
16
vlib/v/tests/method_call_chain_test.v
Normal file
16
vlib/v/tests/method_call_chain_test.v
Normal file
@ -0,0 +1,16 @@
|
||||
struct Test {
|
||||
mut:
|
||||
val int
|
||||
}
|
||||
|
||||
// this must return a reference, or else you'll get a C error
|
||||
// TODO: add a proper checker check for that case
|
||||
fn new(x int) &Test { return &Test{ x } }
|
||||
fn (mut t Test) inc() &Test { t.val++ return t }
|
||||
fn (mut t Test) add(x int) &Test { t.val += x return t }
|
||||
fn (mut t Test) div(x int) &Test { t.val /= x return t }
|
||||
|
||||
fn test_method_call_chains() {
|
||||
mut x := new(4).inc().inc().inc().inc().add(4).div(2).inc()
|
||||
assert x.val == 7
|
||||
}
|
Loading…
Reference in New Issue
Block a user