Skip to content

Commit

Permalink
FEAT: accept any-word as an object key
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Feb 13, 2025
1 parent 4799f5e commit a3417e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/t-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static REBSER *Trim_Object(REBSER *obj)
return PE_NONE; // Error objects may not have a frame.
}

if (IS_WORD(pvs->select)) {
if (ANY_WORD(pvs->select)) {
n = Find_Word_Index(VAL_OBJ_FRAME(pvs->value), VAL_WORD_SYM(pvs->select), FALSE);
}
if (n == 0)
Expand Down
14 changes: 13 additions & 1 deletion src/tests/units/object-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ Rebol [
--assert 3 = obj/b
--assert unset? put obj 'b #(unset)
--assert unset? obj/b


--test-- "any-word as an object's key"
obj: object []
--assert 1 = try [put obj quote 'a 1]
--assert 2 = try [put obj quote :b 2]
--assert 3 = try [put obj quote c: 3]
--assert 4 = try [put obj quote #d 4]
--assert [a: 1 b: 2 c: 3 d: 4] == body-of obj
foreach [k v] ['a 1 :b 2 c: 3 #d 4] [
--assert not error? try [obj/:k: v * 10]
]
--assert [a: 10 b: 20 c: 30 d: 40] == body-of obj

--test-- "compare extended objects"
;@@ https://github.com/Oldes/Rebol-issues/issues/2507
--assert equal? #(object! [a: 1]) #(object! [a: 1])
Expand Down

0 comments on commit a3417e9

Please sign in to comment.