@@ -262,8 +262,6 @@ function _pack_new(T, fields)
262
262
Expr (:call , T, fields... )
263
263
end
264
264
265
- const macro_hidden_nargs = length (:(@m ). args) - 1 # ==1 on Julia 0.6, ==2 on Julia 0.7
266
-
267
265
"""
268
266
This function is called by the `@with_kw` macro and does the syntax
269
267
transformation from:
@@ -341,10 +339,10 @@ function with_kw(typedef, mod::Module, withshow=true)
341
339
l, i = next (lns, start (lns))
342
340
if l isa Expr && l. head == :macrocall && l. args[1 ] == Symbol (" @deftype" )
343
341
has_deftyp = true
344
- if length (l. args) != ( 2 + macro_hidden_nargs)
342
+ if length (l. args) != 3
345
343
error (" Malformed `@deftype` line $l " )
346
344
end
347
- deftyp = l. args[2 + macro_hidden_nargs ]
345
+ deftyp = l. args[3 ]
348
346
if done (lns, i)
349
347
error (" @with_kw only supported for types which have at least one field." )
350
348
end
@@ -385,7 +383,7 @@ function with_kw(typedef, mod::Module, withshow=true)
385
383
unpack_vars = Any[]
386
384
# the type def
387
385
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[]
389
387
kws = OrderedDict {Any, Any} ()
390
388
# assertions in the body
391
389
asserts = Any[]
@@ -523,6 +521,20 @@ function with_kw(typedef, mod::Module, withshow=true)
523
521
# constructors are to allow both calls:
524
522
# `MT4(r=4, a=5.0)` (outer kwarg-constructor) and
525
523
# `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
+
526
538
527
539
# # outer copy constructor
528
540
# ##
0 commit comments