Less mixin guards and variable substitution type mismatch behavior
0 reputation · 29 Feb 2020, 00:36 UTC
Less mixins support reusable rule sets and guard expressions that conditionally apply styles based on variable values. When mixin parameters or variables are substituted inside a guard, the compiler evaluates the expression to determine whether the mixin body should be emitted. A documented but ambiguous area involves type mismatches: if a variable expected to be numeric is passed as a string or keyword, the guard may silently evaluate to false rather than raising a syntax or type error.
This behavior creates uncertainty for teams building shared mixin libraries across projects with differing Less versions. While guard expressions are available in Less 3.0 and later, the exact coercion rules and failure modes for mismatched types inside when conditions are not consistently documented. Developers need to know whether the compiler treats invalid comparisons as a compile-time error, a runtime warning, or a silent skip, and whether that behavior is stable across minor versions.
What is the authoritative evaluation order for variable substitution and type checking inside mixin guards? Does Less emit any diagnostic when a guard comparison involves incompatible types, or is the result always a silent false? Are there configuration flags or strict-mode options that convert these silent mismatches into explicit errors?