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

Make it possible to document sum types #63

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sum_type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ function generate_sum_struct_expr(T, T_abstract, T_name, T_params, T_params_cons

sum_struct_def = Expr(:struct, false, Expr(:(<:), T_full, T_abstract),
Expr(:block, :(data :: ($Union){$(store_types...)}), ))
sum_struct_def = :(Base.@__doc__ $sum_struct_def)

enumerate_constructors = collect(enumerate(constructors))

Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ using Test, SumTypes


abstract type AbstractFoo end

"""
This is a Foo.
"""
@sum_type Foo <: AbstractFoo begin
Bar(::Int)
Baz(x)
Expand Down Expand Up @@ -33,7 +37,8 @@ end
@test Bar(1) isa Foo
@test Bar(1) isa AbstractFoo
@test_throws MethodError Foo(1)

@test string(@doc Foo) == "This is a Foo.\n"

function either_test(x::Either)
let x::Either{Int, Int} = x
@cases x begin
Expand Down
Loading