Skip to content

unary-negated compound literal inside struct literal field initializes incorrectly #6361

@randyprime

Description

@randyprime

Context

  • Operating System & Odin Version: Arch Linux, Odin dev-2026-02:b942f72 (also reproduced on dev-2026-03 master build)
  • Please paste odin report output:
Useful information to add to a bug report:
	Odin:    dev-2026-02:b942f72
	OS:      Arch Linux, Linux 6.18.9-arch1-2
	CPU:     11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
	RAM:     15771 MiB
	Backend: LLVM 21.1.8

Expected Behavior

Unary-negated compound literals should behave consistently in initializers.
For this code, bad.v should be [-1, -5].

Current Behavior

When unary-negating a compound literal inside a struct literal field initializer, value initializes incorrectly to [0, 0].

-Vec2{1, 5} works in a direct assignment, and Vec2{-1, -5} works in struct literal fields, but Pair{v = -Vec2{1, 5}} is wrong.

Failure Information

Steps to Reproduce

  1. Create repro.odin:
package main

import "core:fmt"

Vec2 :: [2]f32
Pair :: struct { v: Vec2 }

main :: proc() {
	ok1 := -Vec2{1, 5}
	ok2 := Pair{v = Vec2{-1, -5}}

	// Repro line:
	bad := Pair{v = -Vec2{1, 5}}

	fmt.println("ok1:", ok1)
	fmt.println("ok2:", ok2.v)
	fmt.println("bad:", bad.v)
}
  1. Run:
odin run repro.odin -file
  1. Observe output.

Failure Logs

Actual output on affected versions (dev-2026-02, dev-2026-03 tested):

ok1: [-1, -5]
ok2: [-1, -5]
bad: [0, 0]

Expected:

ok1: [-1, -5]
ok2: [-1, -5]
bad: [-1, -5]

Bisect result (caveated):

  • First bad commit found by bisect for this repro: 8be18d9a401f898320b57379488bad1367632628
  • Commit message: Allow for constant []typeid
  • Parent (35a32d41e) produced good output; first bad commit produced bad output.
  • Bisect/build in that older range used LLVM_CONFIG=llvm-config-20 to make historical tags buildable on this machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions