Skip to content

Adding a default value to a mixin causes arity match failure #4234

Closed

Description

@matthew-dean

To reproduce:

In the docs, it describes how mixins match on arity (number of arguments).

That is, you can do this:

.mixin(@a) {
  value: @a;
}
.mixin(@a, @b) {
  value: @a + @b;
}

.box {
  .mixin(3);
}

This will produce:

.box {
  value: 3;
}

However, if you add a default value to the first parameter, like so:

.mixin(@a) {
  value: @a;
}
.mixin(@a: 1, @b) {
  value: @a + @b;
}

.box {
  .mixin(3);
}

... then you get the error: wrong number of arguments for .mixin (1 for 2)

Expected behavior:

I would expect this to still match the first mixin by arity.

Something else that's unexpected is that you can't match the second mixin by arity by doing this:

.box {
  .mixin(@b: 3);
}

However, the Less docs don't sufficiently explain (IMO) what the expected behavior should be in that case. Technically, there is a mixin that matches, but it's not clear from the Less docs if overloading mixins means you can "pass over" mixins with only one named argument. I'm really not sure what the behavior should be because the docs don't say, so I'd welcome opinions.

Environment information:

Latest Less / Node 16

Activity

  1. matthew-dean commented on Sep 25, 2023

    @matthew-dean
    MemberAuthor

    I feel like the section on mixins implies that mixins, at the least, must:

    1. Always have the same named parameters (yet it doesn't say this) - i.e. you can add named parameters to further mixins - this seems to be implied because mixin matches fail if the name isn't found.
    2. Cannot use named parameters unless all mixins of the same name contain that named parameter? This to me is somewhat counter-intuitive since the positional arguments can be optional / matched by arity, therefore I somewhat intuited that named args would match mixins by named parameter, but that seems to fail.
  2. matthew-dean commented on Sep 25, 2023

    @matthew-dean
    MemberAuthor

    Always have the same named parameters

    Note that this appears to only be true in the case of named parameters, which is more related to #2.

  3. added a commit that references this issue on Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions