@@ -1312,8 +1312,8 @@ function expand_assignment(ctx, ex, is_const=false)
13121312 # Identifer in lhs[1] is a variable type declaration, eg
13131313 # x::T = rhs
13141314 @ast ctx ex [K " block"
1315- [K " decl" lhs[ 1 ] lhs[ 2 ] ]
1316- is_const ? [K " const" [K " =" lhs[ 1 ] rhs]] : [K " =" lhs[ 1 ] rhs]
1315+ kind (x) === K " Placeholder " ? nothing : [K " decl" x T ]
1316+ is_const ? [K " const" [K " =" x rhs]] : [K " =" x rhs]
13171317 ]
13181318 else
13191319 # Otherwise just a type assertion, eg
@@ -2149,8 +2149,14 @@ function make_lhs_decls(ctx, stmts, declkind, declmeta, ex, type_decls=true)
21492149 if type_decls
21502150 @chk numchildren (ex) == 2
21512151 name = ex[1 ]
2152- @chk kind (name) == K " Identifier"
2153- push! (stmts, makenode (ctx, ex, K " decl" , name, ex[2 ]))
2152+ if kind (name) == K " Identifier"
2153+ push! (stmts, makenode (ctx, ex, K " decl" , name, ex[2 ]))
2154+ else
2155+ # Setting the global type of underscores is likely undesired.
2156+ # Locals are debatable, though that isn't known here.
2157+ @chk kind (name) == K " Placeholder"
2158+ return
2159+ end
21542160 end
21552161 make_lhs_decls (ctx, stmts, declkind, declmeta, ex[1 ], type_decls)
21562162 elseif k == K " tuple" || k == K " parameters"
@@ -2176,7 +2182,7 @@ function expand_decls(ctx, ex)
21762182 # expand_assignment will create the type decls
21772183 make_lhs_decls (ctx, stmts, declkind, declmeta, binding[1 ], false )
21782184 push! (stmts, expand_assignment (ctx, binding))
2179- elseif is_sym_decl (binding) || kind (binding) == K " Value"
2185+ elseif is_sym_decl (binding) || kind (binding) in ( K " Value" , K " Placeholder " )
21802186 make_lhs_decls (ctx, stmts, declkind, declmeta, binding, true )
21812187 elseif kind (binding) == K " function"
21822188 make_lhs_decls (ctx, stmts, declkind, declmeta, binding[1 ], false )
@@ -2238,7 +2244,7 @@ end
22382244# -------------------------------------------------------------------------------
22392245# Expansion of function definitions
22402246
2241- function expand_function_arg (ctx, body_stmts, arg, is_last_arg, is_kw)
2247+ function expand_function_arg (ctx, body_stmts, arg, is_last_arg, is_kw, arg_id )
22422248 ex = arg
22432249
22442250 if kind (ex) == K " ="
@@ -2289,7 +2295,13 @@ function expand_function_arg(ctx, body_stmts, arg, is_last_arg, is_kw)
22892295 K " local" (meta= CompileHints (:is_destructured_arg , true ))
22902296 [K " =" ex name]
22912297 ])
2292- elseif k == K " Identifier" || k == K " Placeholder"
2298+ elseif k == K " Placeholder"
2299+ # The user shouldn't be able to access this name, but lowering should be
2300+ # able to use it as an rvalue internally, e.g. for kw method dispatch.
2301+ # Duplicate positional placeholder names should be allowed.
2302+ name_str = is_kw ? " #kw$(ex. name_val) #" : " #arg$(string (arg_id)) #"
2303+ name = @ast ctx ex name_str:: K"Identifier"
2304+ elseif k == K " Identifier"
22932305 name = ex
22942306 else
22952307 throw (LoweringError (ex, is_kw ? " Invalid keyword name" : " Invalid function argument" ))
@@ -2627,7 +2639,7 @@ function keyword_function_defs(ctx, srcref, callex_srcref, name_str, typevar_nam
26272639 kwtmp = new_local_binding (ctx, keywords, " kwtmp" )
26282640 for (i,arg) in enumerate (children (keywords))
26292641 (aname, atype, default, is_slurp) =
2630- expand_function_arg (ctx, nothing , arg, i == numchildren (keywords), true )
2642+ expand_function_arg (ctx, nothing , arg, i == numchildren (keywords), true , i )
26312643 push! (kw_names, aname)
26322644 name_sym = @ast ctx aname aname=> K " Symbol"
26332645 push! (body_arg_names, aname)
@@ -3004,8 +3016,8 @@ function expand_function_def(ctx, ex, docs, rewrite_call=identity, rewrite_body=
30043016 first_default = 0 # index into arg_names/arg_types
30053017 arg_defaults = SyntaxList (ctx)
30063018 for (i,arg) in enumerate (args)
3007- (aname, atype, default, is_slurp) = expand_function_arg (ctx, body_stmts, arg,
3008- i == length (args), false )
3019+ (aname, atype, default, is_slurp) =
3020+ expand_function_arg (ctx, body_stmts, arg, i == length (args), false , i )
30093021 has_slurp |= is_slurp
30103022 push! (arg_names, aname)
30113023
@@ -3226,8 +3238,8 @@ function expand_opaque_closure(ctx, ex)
32263238 body_stmts = SyntaxList (ctx)
32273239 is_va = false
32283240 for (i, arg) in enumerate (children (args))
3229- (aname, atype, default, is_slurp) = expand_function_arg (ctx, body_stmts, arg,
3230- i == numchildren (args), false )
3241+ (aname, atype, default, is_slurp) =
3242+ expand_function_arg (ctx, body_stmts, arg, i == numchildren (args), false , i )
32313243 is_va |= is_slurp
32323244 push! (arg_names, aname)
32333245 push! (arg_types, atype)
0 commit comments