diff --git a/src/rule_definition_tools.jl b/src/rule_definition_tools.jl index f3e19cd6f..5faf44dcd 100644 --- a/src/rule_definition_tools.jl +++ b/src/rule_definition_tools.jl @@ -424,11 +424,13 @@ function _nondiff_frule_expr(__source__, primal_sig_parts, primal_invoke) return @strip_linenos quote # Manually defined kw version to save compiler work. See explanation in rules.jl function (::Core.kwftype(typeof(ChainRulesCore.frule)))( - @nospecialize($kwargs::Any), + $(esc(kwargs))::Any, frule::typeof(ChainRulesCore.frule), @nospecialize(::Tuple), $(map(esc, primal_sig_parts)...), ) + # `esc` is not accepted inside `@nospecialize(arg)` in a signature + $(Expr(:meta, :nospecialize, kwargs)) return ($(esc(_with_kwargs_expr(primal_invoke, kwargs))), NoTangent()) end function ChainRulesCore.frule(