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

Quaternion construction fails assertion and panics #3665

Open
Feoramund opened this issue Jun 3, 2024 · 2 comments
Open

Quaternion construction fails assertion and panics #3665

Feoramund opened this issue Jun 3, 2024 · 2 comments

Comments

@Feoramund
Copy link
Contributor

I tried to make a quaternion, and any method other than direct field assignment after definition caused either an assertion failure or a panic. I saw the first error and thought that was fine, but both methods of construction that are said to be required are not functioning. I decided to try assigning the values first with explicit types, then placing them in the struct, and that resulted in the panic.

package cq

import "core:fmt"

main :: proc () {
	// Error: 'quaternion' requires that all arguments are named (w, x, y, z; or real, imag, jmag, kmag)
	fmt.printfln("%#v", quaternion(-0,0,0,-0))

	// src/llvm_backend_const.cpp(155): Assertion Failure: `bt->kind == Type_Struct`
	fmt.printfln("%#v", quaternion(w = -0, x = 0, y = 0, z = -0))

	// src/llvm_backend_const.cpp(155): Assertion Failure: `bt->kind == Type_Struct`
	fmt.printfln("%#v", quaternion(real = -0, imag = 0, jmag = 0, kmag = -0))

	// src/types.cpp(1746): Panic: Invalid complex type
	w, x, y, z: f32 = 0, 0, 0, 0
	fmt.printfln("%#v", quaternion(w = w, x = x, y = y, z = z))

	// This works fine:
	q: quaternion64
	q.w = 3
	fmt.printfln("%#v", q)
}
@Feoramund
Copy link
Contributor Author

I did some more investigation into this. It is at least partly connected to the assignment by the BuiltinProc to an any datatype. A similar issue is happening with complex and swizzle.

@Feoramund
Copy link
Contributor Author

This appears to be at least two problems in one.

One is that BuiltinProc_* is not taking into account the assignment of complex and quaternions to an any datatype, which I was able to figure out how to solve for complex at least, by building a new complex on the stack and putting that in the any. The other is that the const backend doesn't seem to handle that situation either. You can produce two different segfaults, depending on if you do a: any = complex(1,2) or a: any = complex(i,j).

I'm at the moment stumped on how to handle the second problem. I had a look at constant strings, since they're internally structs and somehow get assigned to an any type just fine, but I haven't found out how that happens yet.

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

1 participant