Skip to content

convert(::Type{Ptr{T1}}, x::Array{T2}) should fail if T1 != T2 #6073

Closed
@stevengj

Description

Right now, Julia will happily do:

julia> convert(Ptr{Int}, [1.0])
Ptr{Int64} @0x000000010367e470

This is an invitation for bugs; I just ran into this today with a student who was doing ccall(:foo, Void, (Ptr{Cint},), x) and didn't understand why it was failing for x = [1,2,3] or x = [4.0, 5.0].

My preference would be to throw an error in this case. We can still allow convert(::Type{Ptr{T1}}, x::Ptr{T2}) to work, so if you want to do an explicit cast from one pointer type to another you can still do so.

Metadata

Assignees

No one assigned

    Labels

    breakingThis change will break codeneeds decisionA decision on this change is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions