-
-
Notifications
You must be signed in to change notification settings - Fork 830
Closed
Description
Context
package main
import "core:fmt"
// Need struct with at least 3 ints. Issue didn't manifest with 2.
Foo :: struct {a, x, y, z: int}
main :: proc() {
foo_arr := [dynamic]Foo{Foo{1, 1, 1, 1}, Foo{2, 2, 2, 2}, Foo{3, 3, 3, 3}}
reserve(&foo_arr, 4)
fmt.printf("%v\n", foo_arr)
inject_at(&foo_arr, 0, foo_arr[2])
fmt.printf("%v\n", foo_arr)
}
The above program prints
[Foo{a = 1, x = 1, y = 1, z = 1}, Foo{a = 2, x = 2, y = 2, z = 2}, Foo{a = 3, x = 3, y = 3, z = 3}]
[Foo{a = 2, x = 2, y = 2, z = 2}, Foo{a = 1, x = 1, y = 1, z = 1}, Foo{a = 2, x = 2, y = 2, z = 2}, Foo{a = 3, x = 3, y = 3, z = 3}]
- Operating System & Odin Version:
Odin: dev-2024-12:0a29d36aa
OS: macOS Sonoma 14.4.1 (build 23E224, kernel 23.4.0)
CPU: Apple M2
RAM: 24576 MiB
Backend: LLVM 18.1.8
Expected Behavior
I expect the output to be:
[Foo{a = 1, x = 1, y = 1, z = 1}, Foo{a = 2, x = 2, y = 2, z = 2}, Foo{a = 3, x = 3, y = 3, z = 3}]
[Foo{a = 3, x = 3, y = 3, z = 3}, Foo{a = 1, x = 1, y = 1, z = 1}, Foo{a = 2, x = 2, y = 2, z = 2}, Foo{a = 3, x = 3, y = 3, z = 3}]
Current Behavior
inject_at will move down all elements in the array and then the arg pointer will be pointing at the wrong element
Failure Information (for bugs)
You need a struct with more than two fields for this bug to manifest. As I understand it, this is because small structs don't need to be passed by pointer.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- Compile the above program
- Run it
Metadata
Metadata
Assignees
Labels
No labels