Search code examples
recursionlessmixins

Less recursion bug - calling recursive mixin contained in nested namespace from the containing namespace produces "is undefined"


The following code produces an error when compiled via Web Essentials for Visual Studio 2013. I think that plugin uses Winless but it has failed on other compilers as well.

.root {

    #namespace {

        .not-recursive(@x) {
            .margin-@{x} { margin: (1px * @x); }
        }

        .recursive(@x; @i: 0) when (@i =< @x) {
            .not-recursive(@i);
            .recursive(@x; (@i + 1) );
        }

    }

    /* This works */

    .sub-class {
        #namespace > .not-recursive(99);

        #namespace > .recursive(5);
    }

    /* Recursion fails */

    #namespace > .not-recursive(100);

    #namespace > .recursive(5);         // Why???

}

If I comment out the last line, with the comment Why???, it compiles.

If I place #namespace outside of .root and still use #namespace > .recursive() it compiles.

If I had to venture a guess I would guess that it is trying to call .root .recursive() rather than .root #namespace .recursive() once in the mixin, but this is merely a guess based on playing around and seeing what works/doesn't work.

This is not a big deal, but it's really bothering me and I want to know if I missed something in the docs or discovered a new issue.


Solution

  • Well, I do think it's a bug. But after some tests ("Trial and Error") I found a working solution:

    .root {
        (...)
        // Problem solved.
        & { #namespace > .recursive(5); }
    }