Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow constrained type parameters in variant #78

Merged
merged 7 commits into from
May 21, 2024

Conversation

Tortar
Copy link
Contributor

@Tortar Tortar commented May 20, 2024

Fixes #73

@Tortar
Copy link
Contributor Author

Tortar commented May 20, 2024

This still doens't work though:

julia> using SumTypes

julia> @sum_type QP{X<:Real, Y<:Real} begin
           Q{X<:AbstractFloat}(a::X)
           P{Y<:Integer}(b::Y)
       end
ERROR: TypeError: in QP, in Y, expected Y<:Real, got Type{Uninit}
Stacktrace:
 [1] top-level scope
   @ ~/.julia/dev/SumTypes/src/sum_type.jl:203

while this does:

julia> using SumTypes

julia> @sum_type QP{X<:Union{Real, SumTypes.Uninit}, Y<:Union{Real, SumTypes.Uninit}} begin
           Q{X<:AbstractFloat}(a::X)
           P{Y<:Integer}(b::Y)
       end

but it shouldn't be necessary to have this merged, we can patch the first version in a separate PR

@Tortar
Copy link
Contributor Author

Tortar commented May 20, 2024

ok I made it work here

julia> using SumTypes

julia> @sum_type QP{X<:Real, Y<:Real} begin # now this works
           Q{X<:AbstractFloat}(a::X)
           P{Y<:Integer}(b::Y)
       end

@MasonProtter
Copy link
Owner

I'm still a little skeptical about whether this is a good idea, but I guess I also don't see the harm in it, so let's merge it. Thank you for implementing this @Tortar!

@MasonProtter MasonProtter merged commit dd4f806 into MasonProtter:master May 21, 2024
5 checks passed
@Tortar
Copy link
Contributor Author

Tortar commented May 21, 2024

thanks for merging it in so quickly, could you please release a new version? I'd like to use this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@sum_type doesn't work with constrained type parameter in variant
2 participants