Skip to content

Commit 8cae6cf

Browse files
authored
Merge pull request #1023 from SciML/myb/fix
Fix `connect` with varargs
2 parents 6ba3585 + b4ede1a commit 8cae6cf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ end
715715

716716
promote_connect_rule(::Type{T}, ::Type{S}) where {T, S} = Union{}
717717
promote_connect_rule(::Type{T}, ::Type{T}) where {T} = T
718-
promote_connect_type(t1::Type, t2::Type, ts::Type...) = promote_connect_rule(promote_connect_rule(t1, t2), ts...)
718+
promote_connect_type(t1::Type, t2::Type, ts::Type...) = promote_connect_type(promote_connect_rule(t1, t2), ts...)
719719
@inline function promote_connect_type(::Type{T}, ::Type{S}) where {T,S}
720720
promote_connect_result(
721721
T,

test/connectors.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ end
1313
ODESystem(Equation[], t, [x], [p], defaults=Dict(x=>1.0, p=>1.0))
1414
end
1515

16-
ModelingToolkit.connect(::Type{<:Foo}, sys1, sys2) = [sys1.x ~ sys2.x]
16+
function ModelingToolkit.connect(::Type{<:Foo}, ss...)
17+
n = length(ss)-1
18+
eqs = Vector{Equation}(undef, n)
19+
for i in 1:n
20+
eqs[i] = ss[i].x ~ ss[i+1].x
21+
end
22+
eqs
23+
end
24+
1725
@named f1 = Foo()
1826
@named f2 = Foo()
27+
@named f3 = Foo()
28+
@named f4 = Foo()
1929
@named g = Goo()
2030

2131
@test isequal(connect(f1, f2), [f1.x ~ f2.x])
@@ -24,6 +34,9 @@ ModelingToolkit.connect(::Type{<:Foo}, sys1, sys2) = [sys1.x ~ sys2.x]
2434
# Note that since there're overloadings, these tests are not re-runable.
2535
ModelingToolkit.promote_connect_rule(::Type{<:Foo}, ::Type{<:Goo}) = Foo
2636
@test isequal(connect(f1, g), [f1.x ~ g.x])
37+
@test isequal(connect(f1, f2, g), [f1.x ~ f2.x; f2.x ~ g.x])
38+
@test isequal(connect(f1, f2, g, f3), [f1.x ~ f2.x; f2.x ~ g.x; g.x ~ f3.x])
39+
@test isequal(connect(f1, f2, g, f3, f4), [f1.x ~ f2.x; f2.x ~ g.x; g.x ~ f3.x; f3.x ~ f4.x])
2740
ModelingToolkit.promote_connect_rule(::Type{<:Goo}, ::Type{<:Foo}) = Foo
2841
@test isequal(connect(f1, g), [f1.x ~ g.x])
2942
# test conflict

0 commit comments

Comments
 (0)