From a788b5f579f7456cbe4888908c003a1023d6322b Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Mon, 22 Jan 2024 15:36:58 +0100 Subject: [PATCH] remove unnecessary usage of `Expr(:toplevel)` (#69) * remove unnecessary usage of `Expr(:toplevel)` * wrap in module to stop namespace conflicts * bump compat to juliav1.6 * keep custom `isexpr` --- .github/workflows/CI.yml | 1 - Project.toml | 4 ++-- src/sum_type.jl | 4 ++-- test/runtests.jl | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7014c73..17ecbb3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -10,7 +10,6 @@ jobs: fail-fast: false matrix: version: - - '1.1' - '1.6' - '1.8' - '1.9' diff --git a/Project.toml b/Project.toml index a61f802..c4e5516 100644 --- a/Project.toml +++ b/Project.toml @@ -1,13 +1,13 @@ name = "SumTypes" uuid = "8e1ec7a9-0e02-4297-b0fe-6433085c89f2" authors = ["MasonProtter "] -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] diff --git a/src/sum_type.jl b/src/sum_type.jl index c263e3b..1910a77 100644 --- a/src/sum_type.jl +++ b/src/sum_type.jl @@ -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 #------------------------------------------------------ @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 5fa78e6..be59fb0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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