Odin
Odin copied to clipboard
Assertion on empty union switch
Context
- Operating System:
Linux Mint 20 - Kernel 5.4.0-73-generic - Please paste
odin versionoutput:odin version dev-2021-08:7b2f6aaa
Expected Behavior
Compilation should be disallowed when switching on an empty union.
Current Behavior
Compiles, but asserts at runtime / startup.
Failure Information (for bugs)
src/llvm_backend_general.cpp(1108): Assertion Failure: type_size_of(ut) > 0
Steps to Reproduce
Test :: struct {
a: TestState,
}
TestState :: union {
}
call_a :: proc(test: ^Test) {
#partial switch thing in &test.a { // <--- this is really it
}
}
call_b :: proc(test: Test) {
#partial switch thing in test.a { // <--- this is really it
}
}
main :: proc() {
// both break
call_a({});
call_b({});
}
@Skytrias does this really break at runtime? I'm not even able to compile it. The compiler fails on that assertion.
No binary is produced when I run it over here.
System info
OS Name: Microsoft Windows 10 Enterprise OS Version: 10.0.18363 N/A Build 18363 OS Manufacturer: Microsoft Corporation Odin version: dev-2021-09:461ca408
Console output:
p:\>\Odin\odin.exe build repro.odin -debug -opt:0
p:\Odin\src\llvm_backend_general.cpp(1106): Assertion Failure: `type_size_of(ut) > 0`
In any case, maybe empty unions should be disallowed entirely? I'm not sure I see the case for allowing it at all. This should probably be a semantic analysis check to fail even before code gen starts.
@gingerBill is allowing empty unions something intended? 🤔
Hello!
I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue
- open a PR referencing and resolving the issue;
- leave a comment on it and discuss ideas how you could contribute towards resolving it;
- leave a comment and describe in detail why this issue is critical for your use case;
- open a new issue with updated details and a plan on resolving the issue.
The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..