checker: don't disallow method call chains (#7128)
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(?))
|
// No automatic lock for array slicing (yet(?))
|
||||||
explicit_lock_needed = true
|
explicit_lock_needed = true
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.error('cannot use function call as mut', expr.pos)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.ArrayInit {
|
ast.ArrayInit {
|
||||||
|
|
|
@ -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