@@ -1357,8 +1357,8 @@ function expand_assignment(ctx, ex, is_const=false)
13571357 # Identifer 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
@@ -2171,8 +2171,14 @@ function make_lhs_decls(ctx, stmts, declkind, declmeta, ex, type_decls=true)
21712171 if type_decls
21722172 @chk numchildren (ex) == 2
21732173 name = ex[1 ]
2174- @chk kind (name) == K " Identifier"
2175- push! (stmts, makenode (ctx, ex, K " decl" , name, ex[2 ]))
2174+ if kind (name) == K " Identifier"
2175+ push! (stmts, makenode (ctx, ex, K " decl" , name, ex[2 ]))
2176+ else
2177+ # Setting the global type of underscores is likely undesired.
2178+ # Locals are debatable, though that isn't known here.
2179+ @chk kind (name) == K " Placeholder"
2180+ return
2181+ end
21762182 end
21772183 make_lhs_decls (ctx, stmts, declkind, declmeta, ex[1 ], type_decls)
21782184 elseif k == K " tuple" || k == K " parameters"
@@ -2198,7 +2204,7 @@ function expand_decls(ctx, ex)
21982204 # expand_assignment will create the type decls
21992205 make_lhs_decls (ctx, stmts, declkind, declmeta, binding[1 ], false )
22002206 push! (stmts, expand_assignment (ctx, binding))
2201- elseif is_sym_decl (binding) || kind (binding) == K " Value"
2207+ elseif is_sym_decl (binding) || kind (binding) in ( K " Value" , K " Placeholder " )
22022208 make_lhs_decls (ctx, stmts, declkind, declmeta, binding, true )
22032209 elseif kind (binding) == K " function"
22042210 make_lhs_decls (ctx, stmts, declkind, declmeta, binding[1 ], false )
@@ -2260,7 +2266,7 @@ end
22602266# -------------------------------------------------------------------------------
22612267# Expansion of function definitions
22622268
2263- function expand_function_arg (ctx, body_stmts, arg, is_last_arg, is_kw)
2269+ function expand_function_arg (ctx, body_stmts, arg, is_last_arg, is_kw, arg_id )
22642270 ex = arg
22652271
22662272 if kind (ex) == K " ="
@@ -2311,7 +2317,13 @@ function expand_function_arg(ctx, body_stmts, arg, is_last_arg, is_kw)
23112317 K " local" (meta= CompileHints (:is_destructured_arg , true ))
23122318 [K " =" ex name]
23132319 ])
2314- elseif k == K " Identifier" || k == K " Placeholder"
2320+ elseif k == K " Placeholder"
2321+ # The user shouldn't be able to access this name, but lowering should be
2322+ # able to use it as an rvalue internally, e.g. for kw method dispatch.
2323+ # Duplicate positional placeholder names should be allowed.
2324+ name_str = is_kw ? " #kw$(ex. name_val) #" : " #arg$(string (arg_id)) #"
2325+ name = @ast ctx ex name_str:: K"Identifier"
2326+ elseif k == K " Identifier"
23152327 name = ex
23162328 else
23172329 throw (LoweringError (ex, is_kw ? " Invalid keyword name" : " Invalid function argument" ))
@@ -2649,7 +2661,7 @@ function keyword_function_defs(ctx, srcref, callex_srcref, name_str, typevar_nam
26492661 kwtmp = new_local_binding (ctx, keywords, " kwtmp" )
26502662 for (i,arg) in enumerate (children (keywords))
26512663 (aname, atype, default, is_slurp) =
2652- expand_function_arg (ctx, nothing , arg, i == numchildren (keywords), true )
2664+ expand_function_arg (ctx, nothing , arg, i == numchildren (keywords), true , i )
26532665 push! (kw_names, aname)
26542666 name_sym = @ast ctx aname aname=> K " Symbol"
26552667 push! (body_arg_names, aname)
@@ -3026,8 +3038,8 @@ function expand_function_def(ctx, ex, docs, rewrite_call=identity, rewrite_body=
30263038 first_default = 0 # index into arg_names/arg_types
30273039 arg_defaults = SyntaxList (ctx)
30283040 for (i,arg) in enumerate (args)
3029- (aname, atype, default, is_slurp) = expand_function_arg (ctx, body_stmts, arg,
3030- i == length (args), false )
3041+ (aname, atype, default, is_slurp) =
3042+ expand_function_arg (ctx, body_stmts, arg, i == length (args), false , i )
30313043 has_slurp |= is_slurp
30323044 push! (arg_names, aname)
30333045
@@ -3248,8 +3260,8 @@ function expand_opaque_closure(ctx, ex)
32483260 body_stmts = SyntaxList (ctx)
32493261 is_va = false
32503262 for (i, arg) in enumerate (children (args))
3251- (aname, atype, default, is_slurp) = expand_function_arg (ctx, body_stmts, arg,
3252- i == numchildren (args), false )
3263+ (aname, atype, default, is_slurp) =
3264+ expand_function_arg (ctx, body_stmts, arg, i == numchildren (args), false , i )
32533265 is_va |= is_slurp
32543266 push! (arg_names, aname)
32553267 push! (arg_types, atype)
0 commit comments