Skip to content

Commit

Permalink
call convert in Base.setfield! (fixes JuliaLang#16195)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed May 27, 2016
1 parent 9201324 commit 56d5306
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ immutable Nullable{T}
Nullable() = new(true)
Nullable(value::T, isnull::Bool=false) = new(isnull, value)
end

setfield!{T}(x::T, i, v) = Core.setfield!(x, i, convert(fieldtype(T, i), v))
2 changes: 1 addition & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export
Expr, GotoNode, LabelNode, LineNumberNode, QuoteNode,
GlobalRef, NewvarNode, SSAValue, Slot, SlotNumber, TypedSlot,
# object model functions
fieldtype, getfield, setfield!, nfields, throw, tuple, is, ===, isdefined, eval,
fieldtype, getfield, nfields, throw, tuple, is, ===, isdefined, eval,
# sizeof # not exported, to avoid conflicting with Base.sizeof
# type reflection
issubtype, typeof, isa,
Expand Down
1 change: 1 addition & 0 deletions base/coreimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Main.Core.eval(Main.Core, :(baremodule Inference
using Core.TopModule, Core.Intrinsics
import Core.setfield!
ccall(:jl_set_istopmod, Void, (Bool,), false)

eval(x) = Core.eval(Inference,x)
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ export
promote,
promote_rule,
promote_type,
setfield!,
subtypes,
instances,
supertype,
Expand Down
2 changes: 1 addition & 1 deletion base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ function deserialize(s::SerializationState, ::Type{TypeName})
ccall(:jl_set_const, Void, (Any, Any, Any), mod, name, ty)
if !isdefined(ty,:instance)
if isempty(parameters) && !abstr && size == 0 && (!mutable || isempty(names))
setfield!(ty, :instance, ccall(:jl_new_struct, Any, (Any,Any...), ty))
Core.setfield!(ty, :instance, ccall(:jl_new_struct, Any, (Any,Any...), ty))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ let
@test_throws BoundsError getfield(z, 3)

strct = LoadError("", 0, "")
setfield!(strct, 2, 8)
setfield!(strct, 2, 8.0)
@test strct.line == 8
setfield!(strct, 3, "hi")
@test strct.error == "hi"
Expand Down

0 comments on commit 56d5306

Please sign in to comment.