Odin
Odin copied to clipboard
Trying to apply a function that modifies a struct by pointer while iterating an soa array fails silently
Context
Odin: dev-2025-01
OS: NixOS 24.11 (Vicuna), Linux 6.6.63
CPU: AMD Ryzen 9 7950X3D 16-Core Processor
RAM: 31240 MiB
Backend: LLVM 18.1.8
Expected Behavior
The struct field should be correctly modified, or there should be a compile time error disallowing it entirely.
Current Behavior
The field is silently not modified in the soa array, even though it looks modified from inside the updating function.
Failure Information (for bugs)
Steps to Reproduce
Minimal repro:
package repro
import "core:fmt"
Object :: struct {
a: int,
}
main :: proc() {
objects: #soa[1]Object
for &object in objects {
update_object(&object)
fmt.println(object) // prints Object{a = 0}, this should be Object{a = 10} or be disallowed entirely
}
}
update_object :: proc(object: ^Object) {
object.a = 10
fmt.println(object) // prints &Object{a = 10}
}
Still occurs using dev-2025-06:805f7ce97
Expected
&Object{a = 10}
Object{a = 10}
Actual
&Object{a = 10}
Object{a = 0}
The object pointer type is wrong, this is why it can be passed to update_object.
for &object, idx in objects {
obj_ptr := &object // obj_ptr should have type `#soa^#soa[1]Object` but has `^Object`
idx_ptr := &objects[idx] // idx_ptr has type `#soa^#soa[1]Object`
}