Skip to content

Commit 53c2803

Browse files
committed
Better type promotion computation in _varmap_to_vars
1 parent 84d8e12 commit 53c2803

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/variables.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,21 @@ function _varmap_to_vars(varmap::Dict, varlist; defaults=Dict(), check=false, to
7272
varmap = merge(defaults, varmap) # prefers the `varmap`
7373
varmap = Dict(toterm(value(k))=>value(varmap[k]) for k in keys(varmap))
7474
# resolve symbolic parameter expressions
75+
example_val = nothing
7576
for (p, v) in pairs(varmap)
76-
varmap[p] = fixpoint_sub(v, varmap)
77+
val = varmap[p] = fixpoint_sub(v, varmap)
78+
if example_val === nothing && unwrap(val) isa Number
79+
example_val = val
80+
end
7781
end
7882
vs = values(varmap)
7983
T′ = eltype(vs)
80-
T = Base.isconcretetype(T′) ? T′ : float(typeof(first(vs)))
84+
if Base.isconcretetype(T′)
85+
T = T′
86+
else
87+
example_val === nothing && throw_missingvars(varlist)
88+
T = float(typeof(example_val))
89+
end
8190
out = Vector{T}(undef, length(varlist))
8291
missingvars = setdiff(varlist, keys(varmap))
8392
check && (isempty(missingvars) || throw_missingvars(missingvars))

0 commit comments

Comments
 (0)