Skip to content

Commit

Permalink
Ensure different invocations of @composed produce distinct objects
Browse files Browse the repository at this point in the history
Previously, using `@composed` twice on the same named function
would override the existing `produce!`. Now, each invocation
will generate a _unique_ `produce!` method, ensuring that previously
instantiated `Composed` retain their desired function.
  • Loading branch information
Seelengrab committed Jul 2, 2024
1 parent 4adc280 commit 825731a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ A `Possibility` composed from multiple different `Possibility` through
Should not be instantiated manually; keep the object returned by `@composed`
around instead.
"""
struct Composed{S,T} <: Data.Possibility{T}
function Composed{S}() where S
prodtype = Base.promote_op(Data.produce!, TestCase, Composed{S})
new{S, prodtype}()
struct Composed{S,P,T} <: Data.Possibility{T}
function Composed{S,P}() where {S,P}
prodtype = Base.promote_op(Data.produce!, TestCase, Composed{S,P})
new{S, P, prodtype}()
end
end

Expand Down Expand Up @@ -487,15 +487,16 @@ function composed_from_func(e::Expr)
pushfirst!(funchead.args, name)
push!(structfunc.args, funchead)
push!(structfunc.args, body)
id = QuoteNode(gensym())

return esc(quote
$structfunc

function $Data.produce!($tc::$TestCase, ::$Composed{$prodname})
function $Data.produce!($tc::$TestCase, ::$Composed{$prodname,$id})
$name($strategy_let...)
end

$Composed{$prodname}()
$Composed{$prodname,$id}()
end)
end

Expand All @@ -511,13 +512,14 @@ function composed_from_call(e::Expr)
for e in kwargs
push!(args.args, :($Data.produce!($tc, $e)))
end
id = QuoteNode(gensym())

return esc(quote
function $Data.produce!($tc::$TestCase, ::$Composed{$prodname})
function $Data.produce!($tc::$TestCase, ::$Composed{$prodname,$id})
$func($args...)
end

$Composed{$prodname}()
$Composed{$prodname,$id}()
end)
end

Expand Down

0 comments on commit 825731a

Please sign in to comment.