slint-ui/slint · warning

. Use space before the '-' if you meant a subtraction

Error message

. Use space before the '-' if you meant a subtraction

What it means

This is a Slint compiler diagnostic emitted by the name-resolution pass (continue_lookup_within_element, reached via lookup_qualified_name_node) when a hyphenated identifier lookup fails and the parser suspects the '-' was intended as subtraction. Slint identifiers may contain hyphens, so `a-b` is lexed as one identifier; if that identifier does not resolve but `a` is a valid element/property, the compiler suggests you may have meant subtraction. It is a hint accompanying a resolution error, not a panic.

Solutions

  1. Add spaces around the '-' operator: `width - 10px`
  2. Check the spelling of the hyphenated identifier; if it is a real element/property name, ensure it is in scope
  3. If subtraction was intended, parenthesize: `(a) - (b)`
  4. Report upstream if the diagnostic appears despite correct spacing

Example fix

// before
x: parent.width-20px;
// after
x: parent.width - 20px;
Defensive patterns

Strategy: validation

Validate before calling

// Ensure spaces around '-' in .slint expressions:
// x: parent.width - 20px;  (not parent.width-20px)

Prevention

When it happens

Trigger: Writing an expression like `width - 10px` where `width` is not in scope, or `parent.property` minus a value, such that the whole `a-b` token fails qualified-name lookup while the prefix before '-' resolves and its property_type is valid.

Common situations: Migrating CSS-like habits into .slint expressions, doing arithmetic on a property name with no space around the minus, or typos in hyphenated identifiers where the prefix alone happens to be valid.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16). Data as JSON: /api/errors/79c5e63503a235d0. Report an issue: GitHub.

Appendix: source

Thrown at internal/compiler/passes/resolving.rs:2945

                }
            };
            ctx.diag.push_error(
                format!("{} does not have a property '{}'{}", what, second.text(), extra),
                &second,
            );
        };
        if let Some(minus_pos) = second.text().find('-') {
            // Attempt to recover if the user wanted to write "-"
            if elem
                .borrow()
                .lookup_property(
                    &crate::parser::normalize_identifier(&second.text()[0..minus_pos]),
                    mode,
                )
                .property_type
                != Type::Invalid
            {
                err(". Use space before the '-' if you meant a subtraction");
                return None;
            }
        }
        err("");
        None
    }
}

fn maybe_lookup_object(
    mut base: LookupResult,
    it: impl Iterator<Item = crate::parser::SyntaxToken>,
    ctx: &mut LookupCtx,
) -> Option<LookupResult> {
    for next in it {
        let next_str = crate::parser::normalize_identifier(next.text());
        ctx.current_token = Some(next.clone().into());
        match base.lookup(ctx, &next_str) {
            Some(r) => {

View on GitHub (pinned to 3a7e700487)