odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.17k stars 550 forks source link

Invalid type panic on struct literal with using bit_field #3682

Closed hitchh1k3r closed 1 month ago

hitchh1k3r commented 1 month ago

Context

I was trying to expose multiple bit_fields in one type.

Odin: dev-2024-06:a0b1b8d1c OS: Windows 10 Professional (version: 22H2), build 19045.4412 CPU: Intel(R) Core(TM) i7-4771 CPU @ 3.50GHz RAM: 16311 MiB Backend: LLVM 17.0.1

Expected Behavior

The compiler should not crash.

Current Behavior

The compiler crashes with:

[...]\Odin\src\check_expr.cpp(8870): Panic: invalid type: bit_field u8 {feild: u8 | 8 }

Failure Information

The compiler crashes when there is a struct literal assigning a value of an exposed (using) bit_field.

Here is a minimal reproduction:

package main

CompositeBitField :: struct {
  using _ : bit_field u8 {
    feild : u8 | 8,
  },
}

main :: proc() {
  var := CompositeBitField{ feild = 1 }
}

Interestingly if the struct literal is written: CompositeBitField{ { feild = 1 } } the compiler does not crash.