Skip to content

Commit 40985ec

Browse files
committed
prevents metadata to be repeated in the DSL
1 parent f977ec9 commit 40985ec

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/reaction_network.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,12 @@ function push_reactions!(reactions::Vector{ReactionStruct}, sub_line::ExprValues
655655
push!(metadata_i.args, :(only_use_rate = $(in(arrow, pure_rate_arrows))))
656656
end
657657

658+
# Checks that metadata fields are unqiue.
659+
metadata_entries = [arg.args[1] for arg in metadata_i.args]
660+
if length(unique(metadata_entries)) < length(metadata_entries)
661+
error("Some reaction metadata fields where repeated: $(metadata_entries)")
662+
end
663+
658664
push!(reactions, ReactionStruct(get_tup_arg(sub_line, i), get_tup_arg(prod_line, i),
659665
get_tup_arg(rate, i), metadata_i))
660666
end

test/dsl/dsl_basics.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ let
190190
@test isequal(get_metadata_dict(rx3), get_metadata_dict(rxs[3]))
191191
end
192192

193+
# Checks that repeated metadata throws errors.
194+
let
195+
@test_throws LoadError @eval @reaction k, 0 --> X, [md1=1.0, md1=2.0]
196+
@test_throws LoadError @eval @reaction_network begin
197+
k, 0 --> X, [md1=1.0, md1=1.0]
198+
end
199+
end
200+
193201
# Tests for nested metadata.
194202
let
195203
rn1 = @reaction_network reactions begin

0 commit comments

Comments
 (0)