Skip to content

Commit

Permalink
Fix creation of SumTypes in untyped vector (#75)
Browse files Browse the repository at this point in the history
* Fix creation of SumTypes in untyped vector

* Update runtests.jl

* actually it works fine

* Update runtests.jl

* Update runtests.jl

* Update runtests.jl

* Update runtests.jl

* add another test
  • Loading branch information
Tortar committed Feb 13, 2024
1 parent 2934ed2 commit d3966e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/sum_type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ function generate_constructor_exprs(T_name, T_params, T_params_constrained, T_na
end
if true
push!(converts, T_uninit => quote
$Base.convert(::$Type{$T_init}, $x::$T_uninit) where {$(T_params_constrained...)} = $T_init($unwrap($x))
$Base.convert(::$Type{<:$T_init}, $x::$T_uninit) where {$(T_params_constrained...)} = $T_init($unwrap($x))
(::$Type{<:$T_init})($x::$T_uninit) where {$(T_params_constrained...)} = $T_init($unwrap($x))
(::$Type{$T_init})($x::$T_uninit) where {$(T_params_constrained...)} = $T_init($unwrap($x))
Expand Down
20 changes: 19 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,24 @@ using Test, SumTypes
true
end
end
end
end

end

#-------------------------------

@sum_type WT{X,Y} begin
W{X}(x::X)
T{Y}(y::Y)
end

@testset "Test creation inside vectors" begin
# https://github.com/MasonProtter/SumTypes.jl/issues/66
@test [T(i) for i in 1:2] isa Vector{WT{Uninit, Int}}
@test [T(1)] isa Vector{WT{Uninit, Int}}
@test WT[T(1)] isa Vector{WT}
@test WT{Int}[W(1)] isa Vector{WT{Int}}
@test WT{Uninit,Int}[T(1)] isa Vector{WT{Uninit, Int}}
@test WT{Int,Int}[T(1), W(1)] isa Vector{WT{Int, Int}}
@test [T(1), W(1)] isa Vector{WT}
end

0 comments on commit d3966e8

Please sign in to comment.