Skip to content

Commit eace52b

Browse files
Merge pull request #237 from CliMA/ck/fix_utils
Fix and rename has_DataType_or_UnionAll
2 parents 6db9c6a + dbe0e67 commit eace52b

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

test/integrator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ end
141141
((; saveat = save_dt, tstops = all_times), (; erase_sol = false), all_times),
142142
)
143143
integrator = init(deepcopy(prob), alg; dt, init_kwargs...)
144-
@test !@has_DataType_or_UnionAll(integrator)
144+
@test !@any_reltype(integrator, (UnionAll, DataType))
145145
solve!(integrator)
146146
reinit!(integrator, u0′; t0 = t0′, tf = tf′, reinit_kwargs...)
147147
sol = solve!(integrator)

test/integrator_utils.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
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)
28
for pn in propertynames(obj)
39
prop = getproperty(obj, pn)
410
pc_full = (pc..., ".", pn)
511
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
1417
end
18+
found = found || any_reltype(found, prop, name, ets, pc_full; warn)
1519
end
16-
return false
20+
return found
1721
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))))
2024
end

0 commit comments

Comments
 (0)