Skip to content

Commit 8fb93e8

Browse files
committed
FIX: required find/only when searching for a datatype value
resolves: Oldes/Rebol-issues#256
1 parent b969111 commit 8fb93e8

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

src/core/t-block.c

+21-11
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,29 @@ static void No_Nones_Or_Logic(REBVAL *arg) {
150150
}
151151
// Find a datatype in block:
152152
else if (IS_DATATYPE(target) || IS_TYPESET(target)) {
153-
for (; index >= start && index < end; index += skip) {
154-
value = BLK_SKIP(series, index);
155-
// Used if's so we can trace it...
156-
if (IS_DATATYPE(target)) {
157-
if ((REBINT)VAL_TYPE(value) == VAL_DATATYPE(target)) return index;
158-
if (IS_DATATYPE(value) && VAL_DATATYPE(value) == VAL_DATATYPE(target)) return index;
153+
if (flags & AM_FIND_ONLY) {
154+
// not checking value types, only if value and target are really same
155+
for (; index >= start && index < end; index += skip) {
156+
value = BLK_SKIP(series, index);
157+
if (VAL_TYPE(value) == VAL_TYPE(target)) {
158+
if (IS_DATATYPE(target) && VAL_DATATYPE(value) == VAL_DATATYPE(target)) return index;
159+
else if EQUAL_TYPESET(value, target)
160+
return index;
161+
}
162+
if (flags & AM_FIND_MATCH) break;
159163
}
160-
if (IS_TYPESET(target)) {
161-
if (TYPE_CHECK(target, VAL_TYPE(value))) return index;
162-
//if (IS_DATATYPE(value) && TYPE_CHECK(target, VAL_DATATYPE(value))) return index; //@@ issues/256
163-
if (IS_TYPESET(value) && EQUAL_TYPESET(value, target)) return index;
164+
} else {
165+
for (; index >= start && index < end; index += skip) {
166+
value = BLK_SKIP(series, index);
167+
// Used if's so we can trace it...
168+
if (IS_DATATYPE(target)) {
169+
if ((REBINT)VAL_TYPE(value) == VAL_DATATYPE(target))
170+
return index;
171+
}
172+
else if (TYPE_CHECK(target, VAL_TYPE(value)))
173+
return index;
174+
if (flags & AM_FIND_MATCH) break;
164175
}
165-
if (flags & AM_FIND_MATCH) break;
166176
}
167177
return NOT_FOUND;
168178
}

src/tests/units/datatype-test.r3

+20-5
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,32 @@ Rebol [
2424

2525
--test-- "find datatype!"
2626
;@@ https://github.com/Oldes/Rebol-issues/issues/256
27-
--assert not none? find [#[string!] #[binary!]] #[binary!]
28-
--assert not none? find [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
29-
--assert not none? find reduce [string! binary!] binary!
30-
--assert not none? find [#[string!] #[binary!]] binary!
31-
--assert not none? find [#[datatype! string!] #[datatype! binary!]] binary!
27+
--assert none? find reduce [string! binary!] binary!
28+
--assert none? find [#[string!] #[binary!]] #[binary!]
29+
--assert none? find [#[string!] #[binary!]] binary!
30+
31+
--assert not none? find/only reduce [string! binary!] binary!
32+
--assert not none? find/only [#[string!] #[binary!]] #[binary!]
33+
--assert not none? find/only [#[string!] #[binary!]] binary!
34+
3235
--assert not none? find ["test"] string!
3336
--assert not none? find ["test"] series!
3437
--assert none? find reduce [integer! binary!] series!
3538
--assert ["aha"] = find reduce [integer! "aha"] series!
3639
--assert not none? find any-string! ref!
3740

41+
--assert 2 = index? find/only reduce ["" string! any-string! binary!] string!
42+
--assert 3 = index? find/only reduce ["" string! any-string! binary!] any-string!
43+
--assert 1 = index? find reduce ["" string! any-string! binary!] any-string!
44+
--assert 1 = index? find reduce [%a string! any-string! binary!] any-string!
45+
--assert none? find reduce [%a string! any-string! binary!] string!
46+
47+
;; using old construction syntax
48+
--assert none? find [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
49+
--assert none? find [#[datatype! string!] #[datatype! binary!]] binary!
50+
--assert not none? find/only [#[datatype! string!] #[datatype! binary!]] #[datatype! binary!]
51+
--assert not none? find/only [#[datatype! string!] #[datatype! binary!]] binary!
52+
3853
===end-group===
3954

4055
~~~end-file~~~

0 commit comments

Comments
 (0)