|
1 | | -function has_DataType_or_UnionAll(obj, name, pc = ()) |
| 1 | +""" |
| 2 | + @any_reltype(::Any, t::Tuple, warn=true) |
| 3 | +
|
| 4 | +Returns a Bool (and prints warnings) if the given |
| 5 | +data structure has an instance of any types in `t`. |
| 6 | +""" |
| 7 | +function any_reltype(found, obj, name, ets, pc = (); warn = true) |
2 | 8 | for pn in propertynames(obj) |
3 | 9 | prop = getproperty(obj, pn) |
4 | 10 | pc_full = (pc..., ".", pn) |
5 | 11 | pc_string = name * string(join(pc_full)) |
6 | | - if prop isa DataType |
7 | | - @warn "$pc_string::$(typeof(prop)) is a DataType" |
8 | | - return true |
9 | | - elseif prop isa UnionAll |
10 | | - @warn "$pc_string::$(typeof(prop)) is a UnionAll" |
11 | | - return true |
12 | | - else |
13 | | - has_DataType_or_UnionAll(prop, name, pc_full) |
| 12 | + for et in ets |
| 13 | + if prop isa et |
| 14 | + warn && @warn "$pc_string::$(typeof(prop)) is a DataType" |
| 15 | + found = true |
| 16 | + end |
14 | 17 | end |
| 18 | + found = found || any_reltype(found, prop, name, ets, pc_full; warn) |
15 | 19 | end |
16 | | - return false |
| 20 | + return found |
17 | 21 | end |
18 | | -macro has_DataType_or_UnionAll(obj) |
19 | | - return :(has_DataType_or_UnionAll($(esc(obj)), $(string(obj)))) |
| 22 | +macro any_reltype(obj, ets, warn = true) |
| 23 | + return :(any_reltype(false, $(esc(obj)), $(string(obj)), $(esc(ets)); warn = $(esc(warn)))) |
20 | 24 | end |
0 commit comments