diff --git a/src/utils.jl b/src/utils.jl index dc239e34c1..4ee221e14f 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -217,7 +217,7 @@ function iv_from_nested_derivative(x, op = Differential) end hasdefault(v) = hasmetadata(v, Symbolics.VariableDefaultValue) -getdefault(v) = value(getmetadata(v, Symbolics.VariableDefaultValue)) +getdefault(v) = value(Symbolics.getdefaultval(v)) function getdefaulttype(v) def = value(getmetadata(unwrap(v), Symbolics.VariableDefaultValue, nothing)) def === nothing ? Float64 : typeof(def) diff --git a/test/model_parsing.jl b/test/model_parsing.jl index d8665190c8..7ca5618786 100644 --- a/test/model_parsing.jl +++ b/test/model_parsing.jl @@ -263,7 +263,7 @@ end @test getdefault(model.cval) == 1 @test isequal(getdefault(model.c), model.cval + model.jval) @test getdefault(model.d) == 2 - @test_throws KeyError getdefault(model.e) + @test_throws ErrorException getdefault(model.e) @test getdefault(model.f) == 3 @test getdefault(model.i) == 4 @test all(getdefault.(scalarize(model.b2)) .== [1, 3]) diff --git a/test/variable_parsing.jl b/test/variable_parsing.jl index 14c6ca543e..1a5b0ed221 100644 --- a/test/variable_parsing.jl +++ b/test/variable_parsing.jl @@ -104,6 +104,7 @@ end y = 2, [connect = Flow] end +@test_throws ErrorException ModelingToolkit.getdefault(x) @test !hasmetadata(x, VariableDefaultValue) @test getmetadata(x, VariableConnectType) == Flow @test getmetadata(x, VariableUnit) == u @@ -111,9 +112,10 @@ end @test getmetadata(y, VariableConnectType) == Flow a = rename(value(x), :a) -@test !hasmetadata(x, VariableDefaultValue) -@test getmetadata(x, VariableConnectType) == Flow -@test getmetadata(x, VariableUnit) == u +@test_throws ErrorException ModelingToolkit.getdefault(a) +@test !hasmetadata(a, VariableDefaultValue) +@test getmetadata(a, VariableConnectType) == Flow +@test getmetadata(a, VariableUnit) == u @variables t x(t)=1 [connect = Flow, unit = u]