Skip to content

Commit

Permalink
Merge pull request #5760 from pygy/setfield!
Browse files Browse the repository at this point in the history
setfield -> setfield!
  • Loading branch information
JeffBezanson committed Feb 11, 2014
2 parents a9bb567 + d6cf763 commit 8b3e70e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export
GetfieldNode,
# object model functions
apply, arraylen, arrayref, arrayset, arraysize, fieldtype, getfield,
setfield, yieldto, throw, tuple, tuplelen, tupleref, is, ===, isdefined,
setfield!, yieldto, throw, tuple, tuplelen, tupleref, is, ===, isdefined,
convert_default, convert_tuple, kwcall,
# type reflection
issubtype, typeassert, typeof, apply_type, isa,
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ eval(Sys, :(@deprecate shlib_list dllist))

@deprecate myindexes localindexes

@deprecate setfield setfield!

# 0.3 discontinued functions

function nnz(X)
Expand Down
2 changes: 1 addition & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ const getfield_tfunc = function (A, s, name)
end
end
t_func[getfield] = (2, 2, getfield_tfunc)
t_func[setfield] = (3, 3, (o, f, v)->v)
t_func[setfield!] = (3, 3, (o, f, v)->v)
const fieldtype_tfunc = function (A, s, name)
if !isa(s,DataType)
return Type
Expand Down
2 changes: 1 addition & 1 deletion base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ function deserialize(s, t::DataType)
for i in 1:length(t.names)
tag = int32(read(s, Uint8))
if tag==0 || !is(deser_tag[tag], UndefRefTag)
setfield(x, i, handle_deserialize(s, tag))
setfield!(x, i, handle_deserialize(s, tag))
end
end
return x
Expand Down
6 changes: 3 additions & 3 deletions doc/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,11 @@
"),

("Types","Base","setfield","setfield(value, name::Symbol, x)
("Types","Base","setfield!","setfield!(value, name::Symbol, x)
Assign \"x\" to a named field in \"value\" of composite type. The
syntax \"a.b = c\" calls \"setfield(a, :b, c)\", and the syntax
\"a.(b) = c\" calls \"setfield(a, b, c)\".
syntax \"a.b = c\" calls \"setfield!(a, :b, c)\", and the syntax
\"a.(b) = c\" calls \"setfield!(a, b, c)\".
"),

Expand Down
6 changes: 3 additions & 3 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ Types
Extract a named field from a value of composite type. The syntax ``a.b`` calls
``getfield(a, :b)``, and the syntax ``a.(b)`` calls ``getfield(a, b)``.

.. function:: setfield(value, name::Symbol, x)
.. function:: setfield!(value, name::Symbol, x)

Assign ``x`` to a named field in ``value`` of composite type.
The syntax ``a.b = c`` calls ``setfield(a, :b, c)``, and the syntax ``a.(b) = c``
calls ``setfield(a, b, c)``.
The syntax ``a.b = c`` calls ``setfield!(a, :b, c)``, and the syntax ``a.(b) = c``
calls ``setfield!(a, b, c)``.

.. function:: fieldoffsets(type)

Expand Down
10 changes: 5 additions & 5 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,13 @@ JL_CALLABLE(jl_f_get_field)

JL_CALLABLE(jl_f_set_field)
{
JL_NARGS(setfield, 3, 3);
JL_NARGS(setfield!, 3, 3);
jl_value_t *v = args[0];
jl_value_t *vt = (jl_value_t*)jl_typeof(v);
if (vt == (jl_value_t*)jl_module_type)
jl_error("cannot assign variables in other modules");
if (!jl_is_datatype(vt))
jl_type_error("setfield", (jl_value_t*)jl_datatype_type, v);
jl_type_error("setfield!", (jl_value_t*)jl_datatype_type, v);
jl_datatype_t *st = (jl_datatype_t*)vt;
if (!st->mutabl)
jl_errorf("type %s is immutable", st->name->name->name);
Expand All @@ -517,12 +517,12 @@ JL_CALLABLE(jl_f_set_field)
jl_throw(jl_bounds_exception);
}
else {
JL_TYPECHK(setfield, symbol, args[1]);
JL_TYPECHK(setfield!, symbol, args[1]);
idx = jl_field_index(st, (jl_sym_t*)args[1], 1);
}
jl_value_t *ft = jl_tupleref(st->types, idx);
if (!jl_subtype(args[2], ft, 1)) {
jl_type_error("setfield", ft, args[2]);
jl_type_error("setfield!", ft, args[2]);
}
jl_set_nth_field(v, idx, args[2]);
return args[2];
Expand Down Expand Up @@ -995,7 +995,7 @@ void jl_init_primitives(void)
add_builtin_func("tupleref", jl_f_tupleref);
add_builtin_func("tuplelen", jl_f_tuplelen);
add_builtin_func("getfield", jl_f_get_field);
add_builtin_func("setfield", jl_f_set_field);
add_builtin_func("setfield!", jl_f_set_field);
add_builtin_func("fieldtype", jl_f_field_type);

add_builtin_func("arraylen", jl_f_arraylen);
Expand Down
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ void jl_init_serializer(void)
jl_symbol("arrayset"), jl_symbol("arrayref"),
jl_symbol("arraylen"), jl_symbol("boundscheck"),
jl_symbol("convert"), jl_symbol("typeassert"),
jl_symbol("getfield"), jl_symbol("setfield"),
jl_symbol("getfield"), jl_symbol("setfield!"),
jl_symbol("tupleref"), jl_symbol("tuplelen"),
jl_symbol("apply_type"), tuple_sym,

Expand Down
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@
`(block
,.(if (eq? aa a) '() `((= ,aa ,(expand-forms a))))
,.(if (eq? bb b) '() `((= ,bb ,(expand-forms b))))
(call (top setfield) ,aa ,bb
(call (top setfield!) ,aa ,bb
(call (top convert)
(call (top fieldtype) ,aa ,bb)
,(expand-forms rhs)))))))
Expand Down
10 changes: 5 additions & 5 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,15 +538,15 @@ begin
@test_throws getfield(z, 3)

strct = LoadError("", 0, "")
setfield(strct, 2, 8)
setfield!(strct, 2, 8)
@test strct.line == 8
setfield(strct, 3, "hi")
setfield!(strct, 3, "hi")
@test strct.error == "hi"
setfield(strct, 1, "yo")
setfield!(strct, 1, "yo")
@test strct.file == "yo"
@test_throws getfield(strct, 10)
@test_throws setfield(strct, 0, "")
@test_throws setfield(strct, 4, "")
@test_throws setfield!(strct, 0, "")
@test_throws setfield!(strct, 4, "")
end

# allow typevar in Union to match as long as the arguments contain
Expand Down

0 comments on commit 8b3e70e

Please sign in to comment.