Skip to content

Commit bdf423e

Browse files
fix: fix parameter default parsing in @mtkmodel
1 parent 13bdba9 commit bdf423e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/systems/model_parsing.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ function unit_handled_variable_value(meta, varname)
259259
return varval
260260
end
261261

262+
no_value_default_to_nothing(::NoValue) = nothing
263+
no_value_default_to_nothing(x) = x
264+
262265
# This function parses various variable/parameter definitions.
263266
#
264267
# The comments indicate the syntax matched by a block; either when parsed directly
@@ -336,17 +339,17 @@ Base.@nospecializeinfer function parse_variable_def!(
336339
unit_handled_variable_value(meta, varname)
337340
if varclass == :parameters
338341
Meta.isexpr(a, :call) && assert_unique_independent_var(dict, a.args[end])
339-
var = :($varname = $first(@parameters ($a[$(indices...)]::$type = $varval),
342+
var = :($varname = $first(@parameters ($a[$(indices...)]::$type = $no_value_default_to_nothing($varval)),
340343
$meta_val))
341344
elseif varclass == :constants
342345
Meta.isexpr(a, :call) && assert_unique_independent_var(dict, a.args[end])
343-
var = :($varname = $first(@constants ($a[$(indices...)]::$type = $varval),
346+
var = :($varname = $first(@constants ($a[$(indices...)]::$type = $no_value_default_to_nothing($varval)),
344347
$meta_val))
345348
else
346349
Meta.isexpr(a, :call) ||
347350
throw("$a is not a variable of the independent variable")
348351
assert_unique_independent_var(dict, a.args[end])
349-
var = :($varname = $first(@variables ($a[$(indices)]::$type = $varval),
352+
var = :($varname = $first(@variables ($a[$(indices)]::$type = $no_value_default_to_nothing($varval)),
350353
$meta_val))
351354
end
352355
update_array_kwargs_and_metadata!(

0 commit comments

Comments
 (0)