@@ -1357,8 +1357,8 @@ function expand_assignment(ctx, ex, is_const=false)
13571357 # Identifier in lhs[1] is a variable type declaration, eg
13581358 # x::T = rhs
13591359 @ast ctx ex [K " block"
1360- [K " decl" lhs[ 1 ] lhs[ 2 ] ]
1361- is_const ? [K " const" [K " =" lhs[ 1 ] rhs]] : [K " =" lhs[ 1 ] rhs]
1360+ kind (x) === K " Placeholder " ? nothing : [K " decl" x T ]
1361+ is_const ? [K " const" [K " =" x rhs]] : [K " =" x rhs]
13621362 ]
13631363 else
13641364 # Otherwise just a type assertion, eg
@@ -2169,8 +2169,14 @@ function make_lhs_decls(ctx, stmts, declkind, declmeta, ex, type_decls=true)
21692169 if type_decls
21702170 @chk numchildren (ex) == 2
21712171 name = ex[1 ]
2172- @chk kind (name) == K " Identifier"
2173- push! (stmts, makenode (ctx, ex, K " decl" , name, ex[2 ]))
2172+ if kind (name) == K " Identifier"
2173+ push! (stmts, makenode (ctx, ex, K " decl" , name, ex[2 ]))
2174+ else
2175+ # Setting the global type of underscores is likely undesired.
2176+ # Locals are debatable, though that isn't known here.
2177+ @chk kind (name) == K " Placeholder"
2178+ return
2179+ end
21742180 end
21752181 make_lhs_decls (ctx, stmts, declkind, declmeta, ex[1 ], type_decls)
21762182 elseif k == K " tuple" || k == K " parameters"
@@ -2196,7 +2202,7 @@ function expand_decls(ctx, ex)
21962202 # expand_assignment will create the type decls
21972203 make_lhs_decls (ctx, stmts, declkind, declmeta, binding[1 ], false )
21982204 push! (stmts, expand_assignment (ctx, binding))
2199- elseif is_sym_decl (binding) || kind (binding) == K " Value"
2205+ elseif is_sym_decl (binding) || kind (binding) in ( K " Value" , K " Placeholder " )
22002206 make_lhs_decls (ctx, stmts, declkind, declmeta, binding, true )
22012207 elseif kind (binding) == K " function"
22022208 make_lhs_decls (ctx, stmts, declkind, declmeta, binding[1 ], false )
@@ -2258,7 +2264,7 @@ end
22582264# -------------------------------------------------------------------------------
22592265# Expansion of function definitions
22602266
2261- function expand_function_arg (ctx, body_stmts, arg, is_last_arg, is_kw)
2267+ function expand_function_arg (ctx, body_stmts, arg, is_last_arg, is_kw, arg_id )
22622268 ex = arg
22632269
22642270 if kind (ex) == K " ="
@@ -2309,7 +2315,13 @@ function expand_function_arg(ctx, body_stmts, arg, is_last_arg, is_kw)
23092315 K " local" (meta= CompileHints (:is_destructured_arg , true ))
23102316 [K " =" ex name]
23112317 ])
2312- elseif k == K " Identifier" || k == K " Placeholder"
2318+ elseif k == K " Placeholder"
2319+ # The user shouldn't be able to access this name, but lowering should be
2320+ # able to use it as an rvalue internally, e.g. for kw method dispatch.
2321+ # Duplicate positional placeholder names should be allowed.
2322+ name_str = is_kw ? " #kw$(ex. name_val) #" : " #arg$(string (arg_id)) #"
2323+ name = @ast ctx ex name_str:: K"Identifier"
2324+ elseif k == K " Identifier"
23132325 name = ex
23142326 else
23152327 throw (LoweringError (ex, is_kw ? " Invalid keyword name" : " Invalid function argument" ))
@@ -2647,7 +2659,7 @@ function keyword_function_defs(ctx, srcref, callex_srcref, name_str, typevar_nam
26472659 kwtmp = new_local_binding (ctx, keywords, " kwtmp" )
26482660 for (i,arg) in enumerate (children (keywords))
26492661 (aname, atype, default, is_slurp) =
2650- expand_function_arg (ctx, nothing , arg, i == numchildren (keywords), true )
2662+ expand_function_arg (ctx, nothing , arg, i == numchildren (keywords), true , i )
26512663 push! (kw_names, aname)
26522664 name_sym = @ast ctx aname aname=> K " Symbol"
26532665 push! (body_arg_names, aname)
@@ -3024,8 +3036,8 @@ function expand_function_def(ctx, ex, docs, rewrite_call=identity, rewrite_body=
30243036 first_default = 0 # index into arg_names/arg_types
30253037 arg_defaults = SyntaxList (ctx)
30263038 for (i,arg) in enumerate (args)
3027- (aname, atype, default, is_slurp) = expand_function_arg (ctx, body_stmts, arg,
3028- i == length (args), false )
3039+ (aname, atype, default, is_slurp) =
3040+ expand_function_arg (ctx, body_stmts, arg, i == length (args), false , i )
30293041 has_slurp |= is_slurp
30303042 push! (arg_names, aname)
30313043
@@ -3246,8 +3258,8 @@ function expand_opaque_closure(ctx, ex)
32463258 body_stmts = SyntaxList (ctx)
32473259 is_va = false
32483260 for (i, arg) in enumerate (children (args))
3249- (aname, atype, default, is_slurp) = expand_function_arg (ctx, body_stmts, arg,
3250- i == numchildren (args), false )
3261+ (aname, atype, default, is_slurp) =
3262+ expand_function_arg (ctx, body_stmts, arg, i == numchildren (args), false , i )
32513263 is_va |= is_slurp
32523264 push! (arg_names, aname)
32533265 push! (arg_types, atype)
0 commit comments