Skip to content

@cfunction does not throw MethodError / enforce argument types for single-dispatch targets #62246

Description

@topolarity

We do not check that single-target @cfunction dispatches are fully-covered, which is required for to implement :call semantics properly:

julia> f(a::Cint,b::Cint) = a+b
julia> f(a::Float32, b::Cint) = a+b
julia> g(a::Float32, b::Cint) = a+b

julia> p = @cfunction(f, Any, (Any, Cint))
julia> q = @cfunction(g, Any, (Any, Cint))


julia> ccall(p, Any, (Any, Cint), Float32(1.52), 2)
3.52f0
julia> ccall(q, Any, (Any, Cint), Float32(1.52), 2)
3.52f0

julia> ccall(p, Any, (Any, Cint), 1.52, 2)
ERROR: MethodError: no method matching f(::Float64, ::Int32)
# ...
julia> ccall(q, Any, (Any, Cint), 1.52, 2)
2.0f0 # should be `MethodError` but instead UB

(and avoid UB)

found while trying to convince myself of the dispatch behavior in #62245

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions