From 3496cdbe20eea0f4fdcb0c425e2e45b1017519f9 Mon Sep 17 00:00:00 2001 From: Mason Protter Date: Wed, 17 Jan 2024 12:11:51 +0100 Subject: [PATCH] Explicitly disable getproperty (#59) * explicitly disable getproperty * bump version * test on 1.10 --- .github/workflows/CI.yml | 2 +- Project.toml | 2 +- src/sum_type.jl | 2 ++ test/runtests.jl | 5 ----- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 754a0eb..7014c73 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,7 +14,7 @@ jobs: - '1.6' - '1.8' - '1.9' - - '1.10.0-rc1' + - '1.10' - 'nightly' os: - ubuntu-latest diff --git a/Project.toml b/Project.toml index 6e8f823..de6441a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SumTypes" uuid = "8e1ec7a9-0e02-4297-b0fe-6433085c89f2" authors = ["MasonProtter "] -version = "0.5.1" +version = "0.5.2" [deps] MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" diff --git a/src/sum_type.jl b/src/sum_type.jl index 33d8d82..a16aa5a 100644 --- a/src/sum_type.jl +++ b/src/sum_type.jl @@ -249,6 +249,8 @@ function generate_sum_struct_expr(T, T_name, T_params, T_params_constrained, T_p ex = quote $sum_struct_def + $Base.propertynames(::$T_name) = () + $Base.getproperty(::$T_name, ::Symbol) = error("getproperty is deliberately disabled for SumTypes") $SumTypes.is_sumtype(::Type{<:$T_name}) = true $SumTypes.constructors(::Type{<:$T_name}) = $NamedTuple{$tags($T_name)}($(Expr(:tuple, (nt.store_type_uninit for nt ∈ constructors)...))) diff --git a/test/runtests.jl b/test/runtests.jl index b8970c9..8f8f7f1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,9 +23,6 @@ function log_nothrow(x::T)::Result{T} where{T<:AbstractFloat} Success(log(x)) end -Base.getproperty(f::Foo, s::Symbol) = error("Don't do that!") -Base.getproperty(f::Either, s::Symbol) = error("Don't do that!") -Base.getproperty(f::Result, s::Symbol) = error("Don't do that!") #------------------- @testset "Basics " begin @@ -147,7 +144,6 @@ end Cons{A}(::A, ::List) end Cons(x::A, y::List{Uninit}) where {A} = Cons(x, List{A}(y)) -Base.getproperty(f::List, s::Symbol) = error("Don't do that!") List(first, rest...) = Cons(first, List(rest...)) List() = Nil @@ -201,7 +197,6 @@ end C(common_field::Int, b::Float64, d::Bool, e::Float64, k::Complex{Float64}) D(common_field::Int, b::Char) end -Base.getproperty(f::AT, s::Symbol) = error("Don't do that!") A(;common=1, a=true, b=10) = A(common, a, b) B(;common=1, a=1, b=1.0, d=1 + 1.0im) = B(common, a, b, d)