Skip to content

Commit

Permalink
FIX: required find/only when searching for a datatype value
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Aug 26, 2022
1 parent b969111 commit 8fb93e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
32 changes: 21 additions & 11 deletions src/core/t-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,29 @@ static void No_Nones_Or_Logic(REBVAL *arg) {
}
// Find a datatype in block:
else if (IS_DATATYPE(target) || IS_TYPESET(target)) {
for (; index >= start && index < end; index += skip) {
value = BLK_SKIP(series, index);
// Used if's so we can trace it...
if (IS_DATATYPE(target)) {
if ((REBINT)VAL_TYPE(value) == VAL_DATATYPE(target)) return index;
if (IS_DATATYPE(value) && VAL_DATATYPE(value) == VAL_DATATYPE(target)) return index;
if (flags & AM_FIND_ONLY) {
// not checking value types, only if value and target are really same
for (; index >= start && index < end; index += skip) {
value = BLK_SKIP(series, index);
if (VAL_TYPE(value) == VAL_TYPE(target)) {
if (IS_DATATYPE(target) && VAL_DATATYPE(value) == VAL_DATATYPE(target)) return index;
else if EQUAL_TYPESET(value, target)
return index;
}
if (flags & AM_FIND_MATCH) break;
}
if (IS_TYPESET(target)) {
if (TYPE_CHECK(target, VAL_TYPE(value))) return index;
//if (IS_DATATYPE(value) && TYPE_CHECK(target, VAL_DATATYPE(value))) return index; //@@ issues/256
if (IS_TYPESET(value) && EQUAL_TYPESET(value, target)) return index;
} else {
for (; index >= start && index < end; index += skip) {
value = BLK_SKIP(series, index);
// Used if's so we can trace it...
if (IS_DATATYPE(target)) {
if ((REBINT)VAL_TYPE(value) == VAL_DATATYPE(target))
return index;
}
else if (TYPE_CHECK(target, VAL_TYPE(value)))
return index;
if (flags & AM_FIND_MATCH) break;
}
if (flags & AM_FIND_MATCH) break;
}
return NOT_FOUND;
}
Expand Down
25 changes: 20 additions & 5 deletions src/tests/units/datatype-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,32 @@ Rebol [

--test-- "find datatype!"
;@@ https://github.com/Oldes/Rebol-issues/issues/256
--assert not none? find [#[string!] #[binary!]] #[binary!]
--assert not none? find [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
--assert not none? find reduce [string! binary!] binary!
--assert not none? find [#[string!] #[binary!]] binary!
--assert not none? find [#[datatype! string!] #[datatype! binary!]] binary!
--assert none? find reduce [string! binary!] binary!
--assert none? find [#[string!] #[binary!]] #[binary!]
--assert none? find [#[string!] #[binary!]] binary!

--assert not none? find/only reduce [string! binary!] binary!
--assert not none? find/only [#[string!] #[binary!]] #[binary!]
--assert not none? find/only [#[string!] #[binary!]] binary!

--assert not none? find ["test"] string!
--assert not none? find ["test"] series!
--assert none? find reduce [integer! binary!] series!
--assert ["aha"] = find reduce [integer! "aha"] series!
--assert not none? find any-string! ref!

--assert 2 = index? find/only reduce ["" string! any-string! binary!] string!
--assert 3 = index? find/only reduce ["" string! any-string! binary!] any-string!
--assert 1 = index? find reduce ["" string! any-string! binary!] any-string!
--assert 1 = index? find reduce [%a string! any-string! binary!] any-string!
--assert none? find reduce [%a string! any-string! binary!] string!

;; using old construction syntax
--assert none? find [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
--assert none? find [#[datatype! string!] #[datatype! binary!]] binary!
--assert not none? find/only [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
--assert not none? find/only [#[datatype! string!] #[datatype! binary!]] binary!

===end-group===

~~~end-file~~~

0 comments on commit 8fb93e8

Please sign in to comment.