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

Compilation error not caught until llvm backend, when using function ptr variable as a parapoly parameter #4663

Open
tadeohepperle opened this issue Jan 7, 2025 · 0 comments

Comments

@tadeohepperle
Copy link
Contributor

Context

        Odin:    dev-2024-12:6e1d02886
        OS:      Manjaro Linux, Linux 6.1.112-1-MANJARO
        CPU:     12th Gen Intel(R) Core(TM) i7-1260P
        RAM:     31806 MiB
        Backend: LLVM 14.0.6

Expected Behavior

This code is wrong, because it should be clone_fn :: ... instead of clone_fn := , such that the $CLONE_FN: proc(_: T) -> T parameter can be baked correctly:

package main
import "core:slice"

main :: proc() {
	clone_fn := proc(nums: [dynamic]int) -> [dynamic]int {
		return slice.clone_to_dynamic(nums[:])
	}
	make_type_punned_clone([dynamic]int, clone_fn)
}

type_punned_clone :: #type proc(src: rawptr, dst: rawptr)

// converts  proc(T) -> T to  proc(src: ^rawptr, dst: ^rawptr)
make_type_punned_clone :: proc($T: typeid, $CLONE_FN: proc(_: T) -> T) -> type_punned_clone {
	MODIFIED_FN := proc(src, dst: rawptr) {
		src_t := cast(^T)src
		dst_t := cast(^T)dst
		dst_t^ = CLONE_FN(src_t^)
	}
	return MODIFIED_FN
}

But the error message src/llvm_backend_general.cpp(2778): Assertion Failure: e->kind == Entity_Procedure is not helpful for the user. I assume this error should have been caught at an earlier stage of compilation.

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