diff --git a/base/pointer.jl b/base/pointer.jl index 86513c076ade6..2f67c8a6757cb 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -64,6 +64,7 @@ unsafe_convert(::Type{Ptr{Int8}}, s::String) = ccall(:jl_string_ptr, Ptr{Int8}, cconvert(::Type{<:Ptr}, a::Array) = getfield(a, :ref) unsafe_convert(::Type{Ptr{S}}, a::AbstractArray{T}) where {S,T} = convert(Ptr{S}, unsafe_convert(Ptr{T}, a)) +unsafe_convert(::Type{Ptr{T}}, a::Array{T}) where {T} = unsafe_convert(Ptr{T}, a.ref) unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where {T} = error("conversion to pointer not defined for $(typeof(a))") # TODO: add this deprecation to give a better error: # cconvert(::Type{<:Ptr}, a::AbstractArray) = error("conversion to pointer not defined for $(typeof(a))") diff --git a/test/core.jl b/test/core.jl index aa16380c8a866..0eca2251cd146 100644 --- a/test/core.jl +++ b/test/core.jl @@ -8127,3 +8127,5 @@ let M = @__MODULE__ @test Core.set_binding_type!(M, :a_typed_global) === nothing @test Core.get_binding_type(M, :a_typed_global) === Tuple{Union{Integer,Nothing}} end + +@test Base.unsafe_convert(Ptr{Int}, [1]) !== C_NULL