Skip to content

Commit 445cdb1

Browse files
authored
fix: Added missing QuoteNode encapsulation in expressions (#10)
1 parent 9abfd5a commit 445cdb1

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/forward_interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Given `x::T`, forwards the method `\$field(x::T)` to `getfield(x, \$field)`, for
248248
"""
249249
function getfields_interface(T; omit::AbstractVector{Symbol}=Symbol[])
250250
return wrap_define_interface(T, :getfields, Base.remove_linenums!(quote
251-
local omit_fields = $(Expr(:tuple, omit...))
251+
local omit_fields = $(Expr(:tuple, QuoteNode.(omit)...))
252252
local fields = fieldnames($T)
253253
local def_fields_expr = Expr(:block)
254254
local var = gensym("x")
@@ -271,7 +271,7 @@ Given `x::T`, forwards the method `\$field!(x::T, value)` to `setfield!(x, \$fie
271271
"""
272272
function setfields_interface(T; omit::AbstractVector{Symbol}=Symbol[])
273273
return wrap_define_interface(T, :setfields, Base.remove_linenums!(quote
274-
local omit_fields = $(Expr(:tuple, omit...))
274+
local omit_fields = $(Expr(:tuple, QuoteNode.(omit)...))
275275
local fields = fieldnames($T)
276276
local def_fields_expr = Expr(:block)
277277
local var = gensym("x")

test/TestForwardMethods.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ module TestForwardMethods
8383
@test ForwardMethods.has_defined_interface(SettableProperties, Val(:getfields))
8484
@test ForwardMethods.has_defined_interface(SettableProperties, Val(:setfields))
8585

86+
mutable struct SettablePropertiesNoKey2Key3
87+
key1::String
88+
key2::Int
89+
key3::Bool
90+
end
91+
@define_interface SettablePropertiesNoKey2Key3 interface=(getfields, setfields) omit=(key2, key3)
92+
8693
mutable struct CompositeProperties
8794
settable::SettableProperties
8895
key4::Float64
@@ -430,5 +437,20 @@ module TestForwardMethods
430437
e = EqualityUsingProperties(Dict(:a => 1))
431438
@Test e == EqualityUsingProperties(Dict(:a => 1))
432439
@Test e != EqualityUsingProperties(Dict(:a => 1, :b => 2))
440+
441+
@test hasmethod(key1, Tuple{SettableProperties})
442+
@test hasmethod(key1!, Tuple{SettableProperties, String})
443+
@test hasmethod(key2, Tuple{SettableProperties})
444+
@test hasmethod(key2!, Tuple{SettableProperties, Int})
445+
@test hasmethod(key3, Tuple{SettableProperties})
446+
@test hasmethod(key3!, Tuple{SettableProperties, Bool})
447+
448+
@test hasmethod(key1, Tuple{SettablePropertiesNoKey2Key3})
449+
@test hasmethod(key1!, Tuple{SettablePropertiesNoKey2Key3, String})
450+
@test !hasmethod(key2, Tuple{SettablePropertiesNoKey2Key3})
451+
@test !hasmethod(key2!, Tuple{SettablePropertiesNoKey2Key3, Int})
452+
@test !hasmethod(key3, Tuple{SettablePropertiesNoKey2Key3})
453+
@test !hasmethod(key3!, Tuple{SettablePropertiesNoKey2Key3, Bool})
454+
433455
end
434456
end

0 commit comments

Comments
 (0)