[]const T #26428
Unanswered
iperov
asked this question in
Questions and Answers
[]const T
#26428
Replies: 1 comment
-
|
This looks like a bug for me. // host/host.v
module host
pub struct Host {
mut:
cached []int
}
pub fn (mut self Host) numbers() []int {
if self.cached.len == 0 {
self.cached = [0, 0, 0]
}
return self.cached // Can be mutated by caller
// return self.cached.clone() // Expensive
}// main.v
import host
fn main() {
mut h := host.Host{}
mut numbers := h.numbers()
numbers[0] = 1
println(h)
}
// host.Host{
// cached: [1, 0, 0] // mutated!
// } |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How to return immutable view of a dynamic array?
for example as a data cache.
https://play.vlang.io/p/908e1b8d7d
Beta Was this translation helpful? Give feedback.
All reactions