# Parametric type with \`@ccall\` compiler bug?

**URL:** <https://discourse.julialang.org/t/parametric-type-with-ccall-compiler-bug/124688>\
**Category:** General Usage\
**Created:** [January 12, 2025, 1:24am UTC](https://discourse.julialang.org/t/parametric-type-with-ccall-compiler-bug/124688 "2025-01-12T01:24:56Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 12, 2025, 5:20pm UTC](https://discourse.julialang.org/t/parametric-type-with-ccall-compiler-bug/124688/8 "2025-01-12T17:20:57Z")

</div>

Ok, one quick look with Cthulhu.jl later and it seems like the return type passed to `ccall` is taken as a literal, i.e. does not participate in the usual TypeVar resolution?

> `(arr = $(Expr(:foreigncall, "jl_malloc", Ptr{T}, svec(UInt64), 0, :(:ccall), :(%6), :(%4))))`

This would be consistent (if mildly annoying) with [the documentation](https://docs.julialang.org/en/v1/devdocs/ast/) of the `Expr(:foreigncall)`:

> - `args[2]::Type` : RT  
> The (literal) return type, computed statically when the containing method was defined.

Type inference definitely infers the type of the result correctly, since it infers `arr` as `Ptr{Int32}` correctly, so this might just be a missed bit in the compiler. People don’t usually go around having inferred `ccall`s, since one C function can generally only have one return type.

---

_[View the full topic](https://discourse.julialang.org/t/parametric-type-with-ccall-compiler-bug/124688)._
