Skip to content

Commit 08d1cbd

Browse files
committed
fix
1 parent 7eedc16 commit 08d1cbd

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/StructHelpers.jl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export @enumbatteries
55

66
import ConstructionBase: getproperties, constructorof, setproperties
77

8+
# Module aliases used in macro instead of gensyms
9+
# if we would use gensym, this would confuse Revise
10+
const SH = Symbol("#StructHelpers0x6b71ed784697c19c") # a gensym causes Revise.jl issues
11+
const ST = Symbol("#StructTypes0xcf319831da055023") # a gensym causes Revise.jl issues
12+
813
"""
914
hash_eq_as(obj)
1015
@@ -68,7 +73,7 @@ function def_getproperties(T, propertynames)
6873
ex = :($pname = o.$pname)
6974
push!(body.args, ex)
7075
end
71-
:(StructHelpers.getproperties(o::$T) = $body)
76+
:($SH.getproperties(o::$T) = $body)
7277
end
7378

7479
function def_selfconstructor(T)
@@ -182,16 +187,12 @@ macro batteries(T, kw...)
182187
nt = merge(BATTERIES_DEFAULTS, nt)
183188
ret = quote end
184189

185-
need_StructHelpers = nt.getproperties || nt.constructorof
186-
if need_StructHelpers
187-
push!(ret.args, :(import StructHelpers))
188-
end
190+
push!(ret.args, :(import StructHelpers as $SH))
189191
need_fieldnames = nt.kwconstructor || nt.getproperties
190192
if need_fieldnames
191193
fieldnames = Base.fieldnames(Base.eval(__module__, T))
192194
end
193195
need_StructTypes = nt.StructTypes
194-
ST = Symbol("#StructTypes2392") # a gensym causes Revise.jl issues
195196
if need_StructTypes
196197
push!(ret.args, :(import StructTypes as $ST))
197198
end
@@ -227,7 +228,7 @@ macro batteries(T, kw...)
227228
push!(ret.args, def)
228229
end
229230
if nt.constructorof
230-
def = :(StructHelpers.constructorof(::Type{<:$T}) = $T)
231+
def = :($SH.constructorof(::Type{<:$T}) = $T)
231232
push!(ret.args, def)
232233
end
233234
if nt.kwconstructor
@@ -248,7 +249,7 @@ end
248249

249250
function def_has_batteries(T)
250251
:(
251-
function ($has_batteries)(::Type{<:$T})
252+
function $(SH).has_batteries(::Type{<:$T})
252253
true
253254
end
254255
)
@@ -317,15 +318,15 @@ end
317318
function def_enum_from_string(T)::Expr
318319
body = def_symbol_or_enum_from_string_body(string_from_enum, T)
319320
:(
320-
function StructHelpers.enum_from_string(::Type{$T}, s::String)::$T
321+
function $SH.enum_from_string(::Type{$T}, s::String)::$T
321322
$body
322323
end
323324
)
324325
end
325326
function def_enum_from_symbol(T)::Expr
326327
body = def_symbol_or_enum_from_string_body(QuoteNodesymbol_from_enum, T)
327328
:(
328-
function StructHelpers.enum_from_symbol(::Type{$T}, s::Symbol)::$T
329+
function $SH.enum_from_symbol(::Type{$T}, s::Symbol)::$T
329330
$body
330331
end
331332
)
@@ -424,21 +425,21 @@ macro enumbatteries(T, kw...)
424425
TT = Base.eval(__module__, T)::Type
425426
ret = quote end
426427

427-
push!(ret.args, :(import StructHelpers))
428+
push!(ret.args, :(import StructHelpers as $SH))
428429
push!(ret.args, def_enum_from_symbol(TT))
429430
push!(ret.args, def_enum_from_string(TT))
430431
if nt.string_conversion
431-
ex1 = :(Base.convert(::Type{$TT}, s::AbstractString) = StructHelpers.enum_from_string($TT, String(s)))
432-
ex2 = :($T(s::AbstractString) = StructHelpers.enum_from_string($TT, String(s)))
433-
ex3 = :(Base.convert(::Type{String}, x::$T) = StructHelpers.string_from_enum(x))
434-
ex4 = :(Base.String(x::$T) = StructHelpers.string_from_enum(x))
432+
ex1 = :(Base.convert(::Type{$TT}, s::AbstractString) = $SH.enum_from_string($TT, String(s)))
433+
ex2 = :($T(s::AbstractString) = $SH.enum_from_string($TT, String(s)))
434+
ex3 = :(Base.convert(::Type{String}, x::$T) = $SH.string_from_enum(x))
435+
ex4 = :(Base.String(x::$T) = $SH.string_from_enum(x))
435436
push!(ret.args, ex1, ex2, ex3, ex4)
436437
end
437438
if nt.symbol_conversion
438-
ex1 = :(Base.convert(::Type{$T}, s::Symbol) = StructHelpers.enum_from_symbol($TT, Symbol(s)))
439-
ex2 = :($T(s::Symbol) = StructHelpers.enum_from_symbol($TT, Symbol(s)))
440-
ex3 = :(Base.convert(::Type{Symbol}, x::$T) = StructHelpers.symbol_from_enum(x))
441-
ex4 = :(Base.Symbol(x::$T) = StructHelpers.symbol_from_enum(x))
439+
ex1 = :(Base.convert(::Type{$T}, s::Symbol) = $SH.enum_from_symbol($TT, Symbol(s)))
440+
ex2 = :($T(s::Symbol) = $SH.enum_from_symbol($TT, Symbol(s)))
441+
ex3 = :(Base.convert(::Type{Symbol}, x::$T) = $SH.symbol_from_enum(x))
442+
ex4 = :(Base.Symbol(x::$T) = $SH.symbol_from_enum(x))
442443
push!(ret.args, ex1, ex2, ex3, ex4)
443444
end
444445
if nt.selfconstructor

0 commit comments

Comments
 (0)