Repository: JuliaLang/julia
File: JuliaLowering/src/desugaring.jl (Julia)

Code before:
    push!(kwcall_method_defs,
          method_def_expr(ctx, srcref, callex_srcref, kwcall_mtable,
                          main_kwcall_typevars, kwcall_arg_names, kwcall_arg_types, kwcall_body))

    # Check kws of body method
    check_all_typevars_used(body_arg_types, typevar_names, typevar_stmts)

    kw_func_method_defs = @ast ctx srcref [K"block"
        [K"function_decl" body_func_name]
        [K"method_defs"
            body_func_name
            [K"block"
                new_typevar_stmts...
                method_def_expr(ctx, srcref, callex_srcref, "nothing"::K"core",
                                typevar_names, body_arg_names, body_arg_types,
                                [K"block"
                                    [K"meta" "nkw"::K"Symbol" numchildren(keywords)::K"Integer"]
                                    body
                                ],
                                ret_var)
            ]
        ]
        [K"method_defs"
            # We want this method to be local or global at the same time as the
            # body func, but it's really a method on Core.kwcall
            body_func_name
            [K"block"
                new_typevar_stmts...
                kwcall_method_defs...
            ]
        ]
    ]

    #--------------------------------------------------
    # Body for call with no keywords
    body_for_positional_args_only = if defaults_depend_on_kw_names
        scope_nest(ctx, kw_names, kw_defaults,
            @ast ctx srcref [K"call" body_func_name
                kw_names...
                positional_forwarding_args...
            ]
        )
    else
        @ast ctx srcref [K"call" body_func_name
            kw_defaults...
            positional_forwarding_args...
        ]
    end

    kw_func_method_defs, body_for_positional_args_only
end

Review comment (suggestion):
```suggestion
            # This should inherit the local / global status of the body func, 
            # so provide that here for closure conversion, even though this is
            # really a method on Core.kwcall
            body_func_name
```

I assume this is done for closure conversion, but the comment seems to leave that out. Also, is there any issue that this will look up the `ClosureInfo` for the body func when converting the wrapper?

That doesn't lead to https://github.com/JuliaLang/JuliaLowering.jl/issues/141, does it? (shot in the dark)

Code after:
                          main_kwcall_typevars, kwcall_arg_names, kwcall_arg_types, kwcall_body))

    # Check kws of body method
    check_all_typevars_used(body_arg_types, typevar_names, typevar_stmts)

    kw_func_method_defs = @ast ctx srcref [K"block"
        [K"function_decl" body_func_name]
        [K"method_defs"
            body_func_name
            [K"block"
                new_typevar_stmts...
                method_def_expr(ctx, srcref, callex_srcref, "nothing"::K"core",
                                typevar_names, body_arg_names, body_arg_types,
                                [K"block"
                                    [K"meta" "nkw"::K"Symbol" numchildren(keywords)::K"Integer"]
                                    body
                                ],
                                ret_var)
            ]
        ]
        [K"method_defs"
            # This should inherit the local / global status of the body func, so
            # provide that here for closure conversion, even though this is
            # really a method on Core.kwcall
            body_func_name
            [K"block"
                new_typevar_stmts...
                kwcall_method_defs...
            ]
        ]
    ]

    #--------------------------------------------------
    # Body for call with no keywords
    body_for_positional_args_only = if defaults_depend_on_kw_names
        scope_nest(ctx, kw_names, kw_defaults,
            @ast ctx srcref [K"call" body_func_name
                kw_names...
                positional_forwarding_args...
            ]
        )
    else
        @ast ctx srcref [K"call" body_func_name
            kw_defaults...
            positional_forwarding_args...
        ]
    end

    kw_func_method_defs, body_for_positional_args_only
end