Skip to content

Commit

Permalink
Add warning about deprecation of adjoint syntax (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Oct 17, 2024
1 parent 00a8be0 commit 29a2e0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LightSumTypes"
uuid = "f56206fc-af4c-5561-a72a-43fe2ca5a923"
version = "4.1.0"
version = "4.2.0"

[deps]
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Expand Down
19 changes: 13 additions & 6 deletions src/LightSumTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ function sumtype_expr(typedef)

constructors = [:(@inline $(namify(type))(v::Union{$(variants...)}) where {$(typeparams...)} =
$(branchs(variants, variants_with_P, :(return new{$(typeparams...)}(v)))...))]
constructors_extra = [:($Base.adjoint(SumT::Type{$typename}) = $(Expr(:tuple, (:($nv = (args...; kwargs...) ->
$LightSumTypes.constructor($typename, $v, args...; kwargs...)) for (nv, v) in
zip(variants_names, variants_bounded))...)))]
constructors_extra = [:(function $Base.adjoint(SumT::Type{$typename})
@warn "Using A'.B syntax is deprecated in favour of the native A∘B syntax; \
the functionality will be removed in a future release of the package"
return $(Expr(:tuple, (:($nv = (args...; kwargs...) ->
$LightSumTypes.constructor($typename, $v, args...; kwargs...)) for (nv, v) in
zip(variants_names, variants_bounded))...))
end)]

if type isa Expr
push!(
Expand All @@ -77,9 +81,12 @@ function sumtype_expr(typedef)
)
push!(
constructors_extra,
:($Base.adjoint(SumT::Type{$type}) where {$(typeparams...)} =
$(Expr(:tuple, (:($nv = (args...; kwargs...) -> $LightSumTypes.constructor($type, $v, args...; kwargs...))
for (nv, v) in zip(variants_names, variants))...)))
:(function $Base.adjoint(SumT::Type{$type}) where {$(typeparams...)}
@warn "Using A'.B syntax is deprecated in favour of the native A∘B syntax; \
the functionality will be removed in a future release of the package"
return $(Expr(:tuple, (:($nv = (args...; kwargs...) -> $LightSumTypes.constructor($type, $v, args...; kwargs...))
for (nv, v) in zip(variants_names, variants))...))
end)
)
end

Expand Down

0 comments on commit 29a2e0a

Please sign in to comment.