From 755f6a57c774579c5e13e50c7fa0558af10dae25 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Wed, 14 Feb 2018 00:00:27 -0500 Subject: [PATCH] Fix NamedTuple fallback constructor (#26040) Fix a typo that breaks things if inference decides it needs NamedTuples during inference. Fix signature of NamedTuple identity conversion to make sure it's more specific --- base/boot.jl | 3 ++- base/namedtuple.jl | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index 18bc67cf4a5f2..522d27df030b3 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -522,7 +522,8 @@ function NamedTuple{names,T}(args::T) where {names, T <: Tuple} arrayset(false, flds, getfield(args, i), i) i = add_int(i, 1) end - ccall(:jl_new_structv, Any, (Any, Ptr{Cvoid}, UInt32), NT, fields, N)::NT + ccall(:jl_new_structv, Any, (Any, Ptr{Cvoid}, UInt32), NT, + ccall(:jl_array_ptr, Ptr{Cvoid}, (Any,), flds), toUInt32(N))::NT end end diff --git a/base/namedtuple.jl b/base/namedtuple.jl index f88807d424ced..deeac9f489b38 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -106,10 +106,10 @@ isempty(::NamedTuple) = false promote_typejoin(::Type{NamedTuple{n, S}}, ::Type{NamedTuple{n, T}}) where {n, S, T} = NamedTuple{n, promote_typejoin(S, T)} -convert(::Type{NamedTuple{names,T}}, nt::NamedTuple{names,T}) where {names,T} = nt +convert(::Type{NamedTuple{names,T}}, nt::NamedTuple{names,T}) where {names,T<:Tuple} = nt convert(::Type{NamedTuple{names}}, nt::NamedTuple{names}) where {names} = nt -function convert(::Type{NamedTuple{names,T}}, nt::NamedTuple{names}) where {names,T} +function convert(::Type{NamedTuple{names,T}}, nt::NamedTuple{names}) where {names,T<:Tuple} NamedTuple{names,T}(T(nt)) end