Skip to content

Commit 0cbcdc3

Browse files
committed
remove bad convert
1 parent bee84be commit 0cbcdc3

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/rule.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ Base.copy(entry::TestRuleEntryInputSpecification) = TestRuleEntryInputSpecificat
853853
Base.values(entry::TestRuleEntryInputSpecification) = Base.Generator((arg) -> arg.second, entry.arguments)
854854

855855
# Convert the `TestRuleEntryInputSpecification` back into the `Expr` form, e.g `(m_x = ..., q_y = ..., meta = ...)`
856-
function Base.convert(::Type{Expr}, test_entry::TestRuleEntryInputSpecification)
856+
function rule_macro_convert_to_expr(test_entry::TestRuleEntryInputSpecification)
857857
tuple = Expr(:tuple)
858858
tuple.args = map((arg) -> Expr(:(=), arg.first, arg.second), test_entry.arguments)
859859
if !isnothing(test_entry.meta)
@@ -889,8 +889,8 @@ struct TestRuleEntry
889889
end
890890

891891
# Convert the `TestRuleEntry` back into the `Expr` form, e.g `(input = ..., output = ...)`
892-
function Base.convert(::Type{Expr}, test_entry::TestRuleEntry)
893-
return Expr(:tuple, Expr(:(=), :input, convert(Expr, test_entry.input)), Expr(:(=), :output, test_entry.output))
892+
function rule_macro_convert_to_expr(test_entry::TestRuleEntry)
893+
return Expr(:tuple, Expr(:(=), :input, rule_macro_convert_to_expr(test_entry.input)), Expr(:(=), :output, test_entry.output))
894894
end
895895

896896
# This function takes a `test` parameter which is expected to be an expression of single test entry.
@@ -937,8 +937,8 @@ end
937937

938938
function test_rules_generate_testset(test_entry::TestRuleEntry, invoke_test_fn, call_macro_fn, rule_specification, configuration)
939939
# `nothing` here is a `LineNumberNode`, macrocall expects a `line` number, but we do not have it here
940-
actual_inputs = convert(Expr, test_entry.input)
941-
actual_output = Expr(:macrocall, call_macro_fn, nothing, rule_specification, convert(Expr, actual_inputs))
940+
actual_inputs = rule_macro_convert_to_expr(test_entry.input)
941+
actual_output = Expr(:macrocall, call_macro_fn, nothing, rule_specification, actual_inputs)
942942
expected_output = test_entry.output
943943
rule_spec_str = "$rule_specification"
944944
rule_inputs_str = "$actual_inputs"
@@ -1108,9 +1108,8 @@ struct RuleMethodError
11081108
node
11091109
end
11101110

1111-
rule(fform, on, vconstraint, mnames, messages, qnames, marginals, meta, addons, __node) = RuleMethodError(
1112-
fform, on, vconstraint, mnames, messages, qnames, marginals, meta, addons, __node
1113-
)
1111+
rule(fform, on, vconstraint, mnames, messages, qnames, marginals, meta, addons, __node) =
1112+
RuleMethodError(fform, on, vconstraint, mnames, messages, qnames, marginals, meta, addons, __node)
11141113

11151114
function Base.showerror(io::IO, error::RuleMethodError)
11161115
print(io, "RuleMethodError: no method matching rule for the given arguments")

test/rule_tests.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ReactiveMP: float_tolerance, float_tolerance!
1111
import ReactiveMP: extra_float_types, extra_float_types!
1212
import ReactiveMP: test_rules_parse_configuration
13+
import ReactiveMP: rule_macro_convert_to_expr
1314

1415
@testset "TestRulesConfiguration" begin
1516

@@ -59,7 +60,8 @@
5960
@test_throws ErrorException test_rules_parse_configuration(:configuration, :([options = value = broken]))
6061

6162
for name in (:configuration, :blabla),
62-
check in (true, false), atol in (1e-4, :([Float64 => 1e-11, Float32 => 1e-4])),
63+
check in (true, false),
64+
atol in (1e-4, :([Float64 => 1e-11, Float32 => 1e-4])),
6365
extra_types in (:([Float64]), :([Float32, BigFloat]))
6466

6567
expression = test_rules_parse_configuration(name, :([check_type_promotion = $check, atol = $atol, extra_float_types = $extra_types]))
@@ -95,11 +97,11 @@
9597
import ReactiveMP: TestRuleEntryInputSpecification
9698

9799
let spec = TestRuleEntryInputSpecification([:m_x => 1], nothing)
98-
@test convert(Expr, spec) == :((m_x = 1,))
100+
@test rule_macro_convert_to_expr(spec) == :((m_x = 1,))
99101
end
100102

101103
let spec = TestRuleEntryInputSpecification([:q_x => 1, :m_y => :(Normal(1.0, 1.0))], :(Meta(2)))
102-
@test convert(Expr, spec) == :((q_x = 1, m_y = Normal(1.0, 1.0), meta = Meta(2)))
104+
@test rule_macro_convert_to_expr(spec) == :((q_x = 1, m_y = Normal(1.0, 1.0), meta = Meta(2)))
103105
end
104106
end
105107

@@ -120,11 +122,11 @@
120122
import ReactiveMP: TestRuleEntry
121123

122124
let spec = TestRuleEntry(TestRuleEntryInputSpecification([:m_x => 1], nothing), :(Normal(0.0, 3.0)))
123-
@test convert(Expr, spec) == :((input = (m_x = 1,), output = Normal(0.0, 3.0)))
125+
@test rule_macro_convert_to_expr(spec) == :((input = (m_x = 1,), output = Normal(0.0, 3.0)))
124126
end
125127

126128
let spec = TestRuleEntry(TestRuleEntryInputSpecification([:q_x => 1, :m_y => :(Normal(1.0, 1.0))], :(Meta(2))), :(Gamma(2.0, 3.0)))
127-
@test convert(Expr, spec) == :((input = (q_x = 1, m_y = Normal(1.0, 1.0), meta = Meta(2)), output = Gamma(2.0, 3.0)))
129+
@test rule_macro_convert_to_expr(spec) == :((input = (q_x = 1, m_y = Normal(1.0, 1.0), meta = Meta(2)), output = Gamma(2.0, 3.0)))
128130
end
129131
end
130132

@@ -176,7 +178,7 @@
176178

177179
for m in (1, :(Normal(0.0, 1.0))), v in (2, Gamma(2.0, 3.0)), output in (3, :(Normal(2.0, 3.0))), eltype in (:Float32, Float64)
178180
let test_entry = TestRuleEntry(TestRuleEntryInputSpecification([:m => m, :v => v], :(Meta(1))), output)
179-
modified_inputs = map(e -> convert(Expr, e), test_rules_convert_paramfloattype_for_test_entry(test_entry, eltype))
181+
modified_inputs = map(e -> rule_macro_convert_to_expr(e), test_rules_convert_paramfloattype_for_test_entry(test_entry, eltype))
180182

181183
modified_m = :(ReactiveMP.BayesBase.convert_paramfloattype($eltype, $m))
182184
modified_v = :(ReactiveMP.BayesBase.convert_paramfloattype($eltype, $v))

0 commit comments

Comments
 (0)