Skip to content

Commit ffc37d3

Browse files
authored
Merge pull request #286 from ReactiveBayes/273-where-expression-in-the-meta-is-broken
Fix where bug in meta
2 parents 57759bf + 334129e commit ffc37d3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/plugins/meta/meta_macro.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ function add_meta_construction(e::Expr)
3434
return __meta__
3535
end
3636
end
37+
elseif @capture(
38+
e, (function m_name_(m_args__; m_kwargs__) where {m_where_args__}
39+
c_body_
40+
end) | (function m_name_(m_args__) where {m_where_args__}
41+
c_body_
42+
end)
43+
)
44+
m_kwargs = m_kwargs === nothing ? [] : m_kwargs
45+
return quote
46+
$(c_body_string_symbol)::String = $(c_body_string)
47+
function $m_name($(m_args...); $(m_kwargs...)) where {$(m_where_args...)}
48+
__meta__ = GraphPPL.MetaSpecification($(c_body_string_symbol))
49+
$c_body
50+
return __meta__
51+
end
52+
end
3753
else
3854
return quote
3955
$(c_body_string_symbol)::String = $(c_body_string)

test/plugins/meta/meta_macro_tests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,19 @@ end
386386
end
387387
@test_expression_generating meta_macro_interior(input) output
388388
end
389+
390+
@testitem "meta_macro_interior_with_where" begin
391+
import GraphPPL: meta_macro_interior
392+
393+
include("../../testutils.jl")
394+
395+
@meta function make_learning_meta(f::F) where {F}
396+
ContinuousTransition() -> CTMeta(f)
397+
end
398+
399+
@meta function make_learning_meta(f::F, b::G; a::G) where {F, G}
400+
ContinuousTransition() -> CTMeta(f)
401+
end
402+
403+
@test length(methods(make_learning_meta)) == 2
404+
end

0 commit comments

Comments
 (0)