Skip to content

Commit b40f9e7

Browse files
committed
Support Moshi wildcards via dispatch
Fixes #945 Reported upstream: Roger-luo/Moshi.jl#43
1 parent c568c0e commit b40f9e7

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/clock.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,28 @@ discrete-time systems that assume a fixed sample time, such as PID controllers a
4040
filters.
4141
""" SolverStepClock
4242

43-
isclock(c) = @match c begin
43+
isclock(c::TimeDomain) = @match c begin
4444
PeriodicClock() => true
4545
_ => false
4646
end
4747

48-
issolverstepclock(c) = @match c begin
48+
issolverstepclock(c::TimeDomain) = @match c begin
4949
SolverStepClock() => true
5050
_ => false
5151
end
5252

53-
iscontinuous(c) = @match c begin
53+
iscontinuous(c::TimeDomain) = @match c begin
5454
ContinuousClock() => true
5555
_ => false
5656
end
5757

58-
is_discrete_time_domain(c) = !iscontinuous(c)
58+
is_discrete_time_domain(c::TimeDomain) = !iscontinuous(c)
59+
60+
# workaround for https://github.com/Roger-luo/Moshi.jl/issues/43
61+
isclock(::Any) = false
62+
issolverstepclock(::Any) = false
63+
iscontinuous(::Any) = false
64+
is_discrete_time_domain(::Any) = false
5965

6066
function first_clock_tick_time(c, t0)
6167
@match c begin

test/clock.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ using MLStyle: @match
1919
@test isclock(PeriodicClock(; dt = 1.0))
2020
@test !isclock(Continuous())
2121
@test !isclock(SolverStepClock())
22+
@test !isclock(nothing)
2223

2324
@test !issolverstepclock(PeriodicClock(; dt = 1.0))
2425
@test !issolverstepclock(Continuous())
2526
@test issolverstepclock(SolverStepClock())
27+
@test !issolverstepclock(nothing)
2628

2729
@test !iscontinuous(PeriodicClock(; dt = 1.0))
2830
@test iscontinuous(Continuous())
2931
@test !iscontinuous(SolverStepClock())
32+
@test !iscontinuous(nothing)
3033

3134
@test is_discrete_time_domain(PeriodicClock(; dt = 1.0))
3235
@test !is_discrete_time_domain(Continuous())
3336
@test is_discrete_time_domain(SolverStepClock())
37+
@test !is_discrete_time_domain(nothing)
3438

3539
@test first_clock_tick_time(PeriodicClock(; dt = 2.0), 5.0) === 6.0
3640
@test_throws ErrorException first_clock_tick_time(Continuous(), 5.0)

0 commit comments

Comments
 (0)