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

Panic on union Type Assertion #4809

Open
dozn opened this issue Feb 8, 2025 · 1 comment
Open

Panic on union Type Assertion #4809

dozn opened this issue Feb 8, 2025 · 1 comment

Comments

@dozn
Copy link
Contributor

dozn commented Feb 8, 2025

Context

package main
main :: proc() {
    x: U = []int{0}
    _ = x.([]int)
}
U :: union { []int }

Expected Behavior

No panic.

Current Behavior

Odin\src\llvm_backend_expr.cpp(3693): Panic: TODO(bill): type assertion []int

Notes

  • Does not panic using []int{}, only panics when numbers are present there

Odin: dev-2025-02:0683a3d67
OS: Windows 11 Professional (version: 23H2), build 22631.4751
CPU: AMD Ryzen 7 3700X 8-Core Processor
RAM: 65457 MiB
Backend: LLVM 18.1.8

@Creativty
Copy link

Creativty commented Feb 12, 2025

For any one hunting the isssue, I found out that doing prevents the panic from happening:

package bug

U :: union { []int }

main :: proc() {
	x: U
	x   = []int{ 0 }
	_   = x.([]int)
}

This leads me to think that maybe the type of x is not being evaluated accurately, where the compiler thinks x is of type []int when it is of type U, thus panicking while union type asserting on a slice ?

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

2 participants