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

Compiler crash w/no error message or output when float casted to 'any' type #4726

Open
speechfreedoms opened this issue Jan 20, 2025 · 2 comments

Comments

@speechfreedoms
Copy link

minimal example

package test
main :: proc() {
	f := any(3.14)
}

compilation crashes and silently exits with no error message

compiler command

odin run . or odin build .

system info

Odin 2025-01 (source built: 19-JAN-2025)
Windows
LLVM 18.1.8

suggested labels

bug
better-error-message-needed

@cribalik
Copy link

cribalik commented Jan 21, 2025

Looks like any is not a constant type, but it is still evaluated as a constant value in lb_build_expr_internal() through this check:

if (tv.value.kind != ExactValue_Invalid) {
	// NOTE(bill): Short on constant values
	return lb_const_value(p->module, type, tv.value);

Here the tv.value is a float constant, and type is a Basic_any, and thus lb_const_value() ends up creating a LLVMConstReal() with type any

What's the convention here, I assume all constant values should be calculated at typechecking phase, rather than in the llvm backend?
If so, should we only go into lb_const_value() if the type also is a constant type? Something like:

if (is_type_constant_type(tv.type) && tv.value.kind != ExactValue_Invalid) {
	// NOTE(bill): Short on constant values
	return lb_const_value(p->module, type, tv.value);

@laytan
Copy link
Collaborator

laytan commented Jan 21, 2025

If so, should we only go into lb_const_value() if the type also is a constant type?

@cribalik That seems like a good solution from just reading this. Do you want to put that into a PR so we can have a deeper look?

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

3 participants