Skip to content

Commit

Permalink
remove unnecessary usage of Expr(:toplevel) (#69)
Browse files Browse the repository at this point in the history
* remove unnecessary usage of `Expr(:toplevel)`

* wrap in module to stop namespace conflicts

* bump compat to juliav1.6

* keep custom `isexpr`
  • Loading branch information
MasonProtter committed Jan 22, 2024
1 parent abfc960 commit a788b5f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.1'
- '1.6'
- '1.8'
- '1.9'
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name = "SumTypes"
uuid = "8e1ec7a9-0e02-4297-b0fe-6433085c89f2"
authors = ["MasonProtter <[email protected]>"]
version = "0.5.5"
version = "0.5.6"

[deps]
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"

[compat]
julia = "1.1"
julia = "1.6"
MacroTools = "0.5"

[extras]
Expand Down
4 changes: 2 additions & 2 deletions src/sum_type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function _sum_type(T, hidden, blk)

con_expr, con_structs = generate_constructor_exprs(T_name, T_params, T_params_constrained, T_nameparam, constructors)
out = generate_sum_struct_expr(T, T_abstract, T_name, T_params, T_params_constrained, T_param_bounds, T_nameparam, constructors)
Expr(:toplevel, con_structs, out, con_expr)
Expr(:block, con_structs, out, con_expr)
end

#------------------------------------------------------
Expand Down Expand Up @@ -143,7 +143,7 @@ end
#------------------------------------------------------

function generate_constructor_exprs(T_name, T_params, T_params_constrained, T_nameparam, constructors)
out = Expr(:toplevel)
out = Expr(:block)
converts = []
con_structs = Expr(:block)
@gensym _tag _T x
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,22 @@ end
end
end

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

module ToplevelTest
using Test, SumTypes
@testset "Weird toplevel stuff" begin
# https://github.com/MasonProtter/SumTypes.jl/issues/67
@test @eval begin
mutable struct A{X}
x::X
end
@sum_type B{X} begin
C{X}(a::A{X})
end
true
end
end
end

end

0 comments on commit a788b5f

Please sign in to comment.