Visitar URL original
Do not allow addition/subtractions with null and number · Issue #4059 · sass/sass · GitHub
Skip to content

Do not allow addition/subtractions with null and number #4059

Open

Description

@Goodwine

[playground]

Addition and subtraction with null values results in string concatenation rather than an error.

@debug 2% + null - 10px; // -> 2%-10px

Doing the same operation within calc() results on the expected error.

@debug calc(2% + null - 10px);

// This expression can't be used in a calculation.
//   ╷
// 2 │ @debug calc(2% + null - 10px);
//   │                  ^^^^
//   ╵
//   - 2:18  root stylesheet

I'm not sure whether this requires a spec change, or whether the spec is right but the implementation isn't

Activity

  1. nex3 commented on Apr 2, 2025

    @nex3
    Contributor

    The spec doesn't cover this at all currently, so it does require a spec change.

  2. transferred this issue fromsass/dart-sasson Apr 2, 2025
  3. stof commented on Jun 13, 2025

    @stof
    Contributor

    why would "number and null" suddenly become forbidden but not "number and string" then ? should this apply to any type used with numbers instead ?

    SassNumber.plus and SassNumber.minus has 3 cases only in dart-sass:

    • other is SassNumber: perform number addition
    • other is SassColor: trigger error due to forbidding color math (which was supported in ruby-sass and libsass)
    • anything else: delegate to Value.plus or Value.minus which treats + as concatenation and - as a delimited concatenation

    Note that the documentation of https://sass-lang.com/documentation/operators/string/ does not exactly match the behavior (it says numbers cannot be used at all on the left of string operators).
    So even though the spec does not say anything (because the spec for the string type is not written at all, and no spec is written either for binary operators), the documentation says something (and it does not match the implementation)

  4. nex3 commented on Jun 14, 2025

    @nex3
    Contributor

    I think it makes sense to still do string concatenation when strings are already involved (which is very common behavior across programming languages), but defaulting to string concatenation when none of the operands are strings is likely to be unexpected.

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