Ruby function declared with var_kwargs => true not called properly within @if directive
gpakosz opened this issue · comments
Hello,
Assuming the following Ruby function exposed to Sass:
def foo(string, params)
assert_type string, :String
assert_type params, :Hash
result = ... // real business logic irrelevant to the bug report
case result
when TrueClass, FalseClass
bool(result)
when Array
list(result, :comma)
when Hash
map(result)
when nil
null
when Numeric
number(result)
else
params['unquote'] ? unquoted_string(result) : quoted_string(result)
end
end
declare :foo, [:string], var_kwargs: true
When calling this function within an @if
directive:
@if foo('...') {
...
}
Sass reports a syntax error:
Sass::SyntaxError: wrong number of arguments (1 for 2) for `foo'
Despite the documentation stating:
Whether the function accepts other keyword arguments in addition to those in
:args
. If this is true, the Ruby function will be passed a hash from strings to Values as the last argument. In addition, if this is true and:var_args
is not, Sass will ensure that the last argument passed is a hash.
Declaring the Ruby function with params = {}
mitigates the problem:
def foo(string, params = {})
...
end
declare :foo, [:string], var_kwargs: true
Forgot to verify versions, it seems the bug happens at least in 3.4.25
but not in 3.6.0
. I can't pinpoint what solves it though
If this is working in 3.6.0, then the bug is already fixed.