Skip to content

Commit ecbf8df

Browse files
committed
Removed some pre Julia-1.0 cruft and some comments
1 parent cf8fec6 commit ecbf8df

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/Parameters.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ function _pack_new(T, fields)
262262
Expr(:call, T, fields...)
263263
end
264264

265-
const macro_hidden_nargs = length(:(@m).args) - 1 # ==1 on Julia 0.6, ==2 on Julia 0.7
266-
267265
"""
268266
This function is called by the `@with_kw` macro and does the syntax
269267
transformation from:
@@ -341,10 +339,10 @@ function with_kw(typedef, mod::Module, withshow=true)
341339
l, i = next(lns, start(lns))
342340
if l isa Expr && l.head == :macrocall && l.args[1] == Symbol("@deftype")
343341
has_deftyp = true
344-
if length(l.args) != (2 + macro_hidden_nargs)
342+
if length(l.args) != 3
345343
error("Malformed `@deftype` line $l")
346344
end
347-
deftyp = l.args[2 + macro_hidden_nargs]
345+
deftyp = l.args[3]
348346
if done(lns, i)
349347
error("@with_kw only supported for types which have at least one field.")
350348
end
@@ -385,7 +383,7 @@ function with_kw(typedef, mod::Module, withshow=true)
385383
unpack_vars = Any[]
386384
# the type def
387385
fielddefs = quote end # holds r::R etc
388-
fielddefs.args = Any[] # in julia 0.5 this is [:( # /home/mauro/.julia/v0.5/Parameters/src/Parameters.jl, line 228:)]
386+
fielddefs.args = Any[]
389387
kws = OrderedDict{Any, Any}()
390388
# assertions in the body
391389
asserts = Any[]
@@ -523,6 +521,20 @@ function with_kw(typedef, mod::Module, withshow=true)
523521
# constructors are to allow both calls:
524522
# `MT4(r=4, a=5.0)` (outer kwarg-constructor) and
525523
# `MT4{Float32, Int}(r=4, a=5.)` (inner kwarg constructor).
524+
#
525+
# NOTE to above NOTE: this is probably not the case (anymore?),
526+
# as Base.@kwdef does not define inner constructors:
527+
# julia> Base.@kwdef struct MT4_{R,I}
528+
# r::R=5
529+
# a::I
530+
# end
531+
#
532+
# julia> MT4_(r=4, a=5.0)
533+
# MT4_{Int64,Float64}(4, 5.0)
534+
#
535+
# julia> MT4_{Float32, Int}(r=4, a=5.)
536+
# MT4_{Float32,Int64}(4.0f0, 5)
537+
526538

527539
## outer copy constructor
528540
###

0 commit comments

Comments
 (0)