Skip to content

Commit

Permalink
remove more destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
zot committed Jul 17, 2024
1 parent df55699 commit 62495f0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,44 +331,44 @@ function updateproto(o::T) where {T}
return true
end

function updatefield(o, oldfields, (; name, type, isconst, hasdefault, default))
function updatefield(o, oldfields, info)
local err = ""
local orig_type = type
local orig_type = info.type

if type isa Integer
type = typeof(o).parameters[type]
if info.type isa Integer
info.type = typeof(o).parameters[info.type]
end
if !isconst
type = Ref{type}
if !info.isconst
info.type = Ref{info.type}
end
if name keys(oldfields)
if info.name keys(oldfields)
try
return updatevalue(type, oldfields[name])
return updatevalue(info.type, oldfields[info.name])
catch
err = "Could not convert old value $(oldfields[name]) to type $type"
err = "Could not convert old value $(oldfields[info.name]) to type $info.type"
end
end
if !hasdefault
if !info.hasdefault
try
default = typemin(orig_type)
info.default = typemin(orig_type)
if !isempty(err)
err = "$err and no default value for field $name, choosing typemin"
err = "$err and no default value for field $info.name, choosing typemin"
else
err = "No default value for field $name, choosing typemin"
err = "No default value for field $info.name, choosing typemin"
end
catch
if !isempty(err)
error("$err and no default value or typemin for field $name")
error("$err and no default value or typemin for field $info.name")
else
error("No default value or typemin for field $name")
error("No default value or typemin for field $info.name")
end
end
elseif !isempty(err)
err = "$err, using default instead"
end
!isempty(err) &&
@warn err
return default
return info.default
end

updatevalue(newtype, value) = convert(newtype, value)
Expand Down

0 comments on commit 62495f0

Please sign in to comment.