Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

During struct initialization, overwriting the imported fields of an embedded struct after initializing it has no effect. #3443

Open
MineBill opened this issue Apr 17, 2024 · 0 comments

Comments

@MineBill
Copy link

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Operating System & Odin Version:
Odin:    dev-2024-04:9bbe26f80
OS:      Windows 11 Professional (version: 22H2), build 22621.3447
CPU:     Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
RAM:     16227 MiB
Backend: LLVM 17.0.1

Expected Behavior

The compiler should either accept this and produce valid code, actually modifying the field with the second initialization, or produce a compile error if it's undesirable behavior.

Current Behavior

Inside the default_struct i initialize inner by calling default_inner_struct and then attempt to overwrite one of the imported fields, inner_number_a, with the value 222. However, printing the field, we can see the output is 69, the value returned from deafult_inner_proc, and not 222, the expected value.

Steps to Reproduce

package main
import "core:fmt"

InnerStruct :: struct {
    inner_number_a: int,
    inner_number_b: int,
}

default_inner_struct :: proc() -> InnerStruct {
    return {
        inner_number_a = 69,
        inner_number_b = 420,
    }
}

Struct :: struct {
    using inner: InnerStruct,
}

default_struct :: proc() -> Struct {
    s := Struct {
        inner = default_inner_struct(),
        inner_number_a = 222,
    }
    return s
}

main :: proc() {
    s := default_struct()

    // Prints 69, ignoring the second initialization at L:23 to 222.
    fmt.printfln("%v", s.inner_number_a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant