Skip to content

Commit 692928b

Browse files
fix: improve inference of variable metadata accessors
1 parent 8f1493f commit 692928b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ isdifferential(expr) = isoperator(expr, Differential)
394394
isdiffeq(eq) = isdifferential(eq.lhs) || isoperator(eq.lhs, Shift)
395395

396396
isvariable(x::Num)::Bool = isvariable(value(x))
397-
function isvariable(x)::Bool
397+
function isvariable(x)
398398
x isa SymbolicT || return false
399-
hasmetadata(x, VariableSource) || iscall(x) && operation(x) === getindex && isvariable(arguments(x)[1])
399+
hasmetadata(x, VariableSource) || iscall(x) && operation(x) === getindex && isvariable(arguments(x)[1])::Bool
400400
end
401401

402402
"""

src/variables.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ setio(x, i::Bool, o::Bool) = setoutput(setinput(x, i), o)
218218
219219
Check if variable `x` is marked as an input.
220220
"""
221-
isinput(x) = isvarkind(VariableInput, x)
221+
isinput(x) = isvarkind(VariableInput, x)::Bool
222222
"""
223223
$(TYPEDSIGNATURES)
224224
225225
Check if variable `x` is marked as an output.
226226
"""
227-
isoutput(x) = isvarkind(VariableOutput, x)
227+
isoutput(x) = isvarkind(VariableOutput, x)::Bool
228228

229229
# Before the solvability check, we already have handled IO variables, so
230230
# irreducibility is independent from IO.
@@ -234,7 +234,7 @@ isoutput(x) = isvarkind(VariableOutput, x)
234234
Check if `x` is marked as irreducible. This prevents it from being eliminated as an
235235
observed variable in `mtkcompile`.
236236
"""
237-
isirreducible(x) = isvarkind(VariableIrreducible, x)
237+
isirreducible(x) = isvarkind(VariableIrreducible, x)::Bool
238238
setirreducible(x, v::Bool) = setmetadata(x, VariableIrreducible, v)
239239
state_priority(x::Union{Num, Symbolics.Arr}) = state_priority(unwrap(x))
240240
"""
@@ -339,7 +339,7 @@ isdisturbance(x::Num) = isdisturbance(Symbolics.unwrap(x))
339339
Determine whether symbolic variable `x` is marked as a disturbance input.
340340
"""
341341
function isdisturbance(x)
342-
isvarkind(VariableDisturbance, x)
342+
isvarkind(VariableDisturbance, x)::Bool
343343
end
344344

345345
setdisturbance(x, v) = setmetadata(x, VariableDisturbance, v)
@@ -370,7 +370,7 @@ Create a tunable parameter by
370370
See also [`tunable_parameters`](@ref), [`getbounds`](@ref)
371371
"""
372372
function istunable(x, default = true)
373-
isvarkind(VariableTunable, x, default)
373+
isvarkind(VariableTunable, x, default)::Bool
374374
end
375375

376376
## Dist ========================================================================
@@ -607,10 +607,10 @@ Check if the variable `x` has a unit.
607607
hasunit(x) = getunit(x) !== nothing
608608

609609
getunshifted(x::Num) = getunshifted(unwrap(x))
610-
getunshifted(x::SymbolicT) = Symbolics.getmetadata(x, VariableUnshifted, nothing)
610+
getunshifted(x::SymbolicT) = Symbolics.getmetadata(x, VariableUnshifted, nothing)::Union{SymbolicT, Nothing}
611611

612612
getshift(x::Num) = getshift(unwrap(x))
613-
getshift(x::SymbolicT) = Symbolics.getmetadata(x, VariableShift, 0)
613+
getshift(x::SymbolicT) = Symbolics.getmetadata(x, VariableShift, 0)::Int
614614

615615
###################
616616
### Evaluate at ###

0 commit comments

Comments
 (0)