Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Conversion of derived pointer type to base pointer type in procedure type causes an internal compiler error

Open graphitemaster opened this issue 3 years ago • 0 comments

When converting a derived pointer type to a base type in a procedure type which takes the base type as a pointer type with either explicit cast or auto_cast, the Odin compiler crashes

Minimal test case here

package test
Callback :: #type proc(self: ^Base)
Base :: struct {
  callbacks: [dynamic]Callback,
}
Derived :: struct {
  using _: Base,
}
test :: proc(derived: ^Derived, callback: proc(^Derived)) {
  append(&derived.callbacks, auto_cast callback)
}
main :: proc() {
  add(&Derived{}, proc(^Derived){})
}

You can work around this with various casts to and from rawptr first on the procedure type to escape the faulty type checking inside the Odin compiler, the ICE can be seen here

src/llvm_backend_proc.cpp(726): Assertion Failure: `arg_type == param_type` Parameter types do not match: 
{ i8**, i64, i64,  %runtime.Allocator }* != { void (%test.Base*, i8*)**, i64, i64, %runtime.Allocator }*, 
argument:   %9 = getelementptr inbounds %test.Base, %test.Base* %8, i32 0, i32 0

graphitemaster avatar May 16 '22 04:05 graphitemaster