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

Assertion on empty union switch #1105

Closed
Skytrias opened this issue Aug 27, 2021 · 2 comments
Closed

Assertion on empty union switch #1105

Skytrias opened this issue Aug 27, 2021 · 2 comments
Labels

Comments

@Skytrias
Copy link
Sponsor Contributor

Context

  • Operating System: Linux Mint 20 - Kernel 5.4.0-73-generic
  • Please paste odin version output: 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({});
}
@ghost
Copy link

ghost commented Sep 10, 2021

@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? 🤔

@github-actions
Copy link

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..

@github-actions github-actions bot added stale and removed stale labels Jul 24, 2022
@github-actions github-actions bot added the stale label Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant