Skip to content

Commit 879a908

Browse files
authored
getproperty bugfix (#45)
* Some fixes for type constrained parameters * use `[]` for lists of similar variants in `@cases` * README fixes * compat fix * make coverage happy * avoid getproperty * bump version
1 parent 0cf9c82 commit 879a908

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SumTypes"
22
uuid = "8e1ec7a9-0e02-4297-b0fe-6433085c89f2"
33
authors = ["MasonProtter <[email protected]>"]
4-
version = "0.4.7"
4+
version = "0.4.8"
55

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

src/compute_storage.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ unwrap(x::ST, var) where {ST} = unwrap(x, var, variants_Tuple(ST))
127127
bit_sigs = nt.bit_sigs
128128
quote
129129
names = ($(QuoteNode.(bit_names[i])...),)
130-
bits = unsafe_padded_reinterpret(Variant{names, Tuple{$(bit_sigs[i]...)}}, x.bits)
130+
bits = unsafe_padded_reinterpret(Variant{names, Tuple{$(bit_sigs[i]...)}}, getfield(x, :bits))
131131
args = $(Expr(:tuple,
132132
(bit_names[i][j] ptr_names[i] ? let k = findfirst(x -> x == bit_names[i][j], ptr_names[i])
133-
:(x.ptrs[$k]:: $(ptrss[i][k][2]))
133+
:(getfield(x, :ptrs)[$k]:: $(ptrss[i][k][2]))
134134
end : :(bits.data[$j]) for j eachindex(bit_names[i]))...))
135135
Variant{names, $(Var.parameters[2])}(args)
136136
end

test/runtests.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function log_nothrow(x::T)::Result{T} where{T<:AbstractFloat}
2323
Success(log(x))
2424
end
2525

26+
Base.getproperty(f::Foo, s::Symbol) = error("Don't do that!")
27+
Base.getproperty(f::Either, s::Symbol) = error("Don't do that!")
28+
Base.getproperty(f::Result, s::Symbol) = error("Don't do that!")
29+
2630
#-------------------
2731
@testset "Basics " begin
2832
@test SumTypes.is_sumtype(Int) == false
@@ -163,6 +167,7 @@ end
163167
Cons{A}(::A, ::List)
164168
end
165169
Cons(x::A, y::List{Uninit}) where {A} = Cons(x, List{A}(y))
170+
Base.getproperty(f::List, s::Symbol) = error("Don't do that!")
166171

167172
List(first, rest...) = Cons(first, List(rest...))
168173
List() = Nil
@@ -216,6 +221,7 @@ end
216221
C(common_field::Int, b::Float64, d::Bool, e::Float64, k::Complex{Real})
217222
D(common_field::Int, b::Any)
218223
end
224+
Base.getproperty(f::AT, s::Symbol) = error("Don't do that!")
219225

220226
A(;common=1, a=true, b=10) = A(common, a, b)
221227
B(;common=1, a=1, b=1.0, d=1 + 1.0im) = B(common, a, b, d)
@@ -350,7 +356,6 @@ foo(x::Foo) = @cases x begin
350356
D((_, x)) => x
351357
end
352358

353-
354359
@sum_type Re begin
355360
Empty
356361
Class(::UInt8)
@@ -367,8 +372,7 @@ count_classes(r::Re, c=0) = @cases r begin
367372
Rep(x) => c + count_classes(x)
368373
[Alt, Cat, Diff, And](x, y) => c + count_classes(x) + count_classes(y)
369374
end;
370-
371-
375+
372376
@testset "Collection of variants" begin
373377
@test foo(A(1, 1)) == 2
374378
@test foo(B(1, 1.5)) == 2.5

0 commit comments

Comments
 (0)