Skip to content

fix(analyser): preserve operand types in augmented assignments 馃攷 - #224

Closed
timfennis wants to merge 3 commits into
masterfrom
fix/augmented-assignment-diagnostics
Closed

fix(analyser): preserve operand types in augmented assignments 馃攷#224
timfennis wants to merge 3 commits into
masterfrom
fix/augmented-assignment-diagnostics

Conversation

@timfennis

@timfennis timfennis commented Sep 8, 2026

Copy link
Copy Markdown
Owner

An unknown right operand could make scalar augmented assignments fail with a type mismatch: fn opaque(x) => x; let ok = false; ok |= opaque(true); was rejected even though Boolean | supports the runtime values. Unannotated recursive Boolean calls encountered the same error.

Vector fallback erased every operand type when any argument was Any, admitting map/set mutation overloads for known Boolean and integer operands. It now retains those constraints while considering tuple elements for Sequence<T> arguments. Scalar assignments and valid vector operations succeed; incompatible list and map mutations remain rejected.

For rejected container mutations, CLI diagnostics label both operands, and LSP diagnostics highlight the right operand with a related location for the target. Target spans include grouping and index delimiters.

Replace analyser tests with invented operator signatures with .ndc programs using the real standard library. LSP diagnostic tests use a concrete List<Int> ++= List<Float> mismatch. Remove recursion-specific annotation advice.

Validation:

  • Confirmed the scalar and recursive regression programs fail before the resolver fix and pass afterward.
  • cargo test --workspace --locked: 657 passed, 3 ignored (including doctests).
  • cargo build --no-default-features --locked.
  • cargo fmt --all --check and git diff --check.
  • Coverage includes +=, -=, |=, &=, and ~=, recursive calls, tuple values behind Any and Sequence<Int>, assignment widening, container rejection, and LSP ranges including UTF-16 positions.

AI disclosure: Codex generated the implementation, tests, and PR description.

Comment thread ndc_bin/src/diagnostic.rs Outdated
}

#[cfg(test)]
mod tests {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I like these tests

@timfennis timfennis changed the title fix(analyser): explain augmented assignment type mismatches 馃攷 fix(analyser): preserve operand types in augmented assignments 馃攷 Sep 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃挕 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c90a641f60

鈩癸笍 About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 馃憤.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ndc_analyser/src/scope.rs
.multi_cartesian_product();
let mut vars = Vec::new();
for signature in signatures {
for var in self.candidates_for_sig(ident, &signature) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain overlapping container candidates in vector fallback

When a known operand is Sequence<T>, candidates_for_sig only retains overload parameters subtype-comparable with either Sequence<T> or T; it misses overlapping concrete containers such as List<Any>, even though a Sequence<Int> value may be a List<Int>. Consequently, fn concat(xs: Sequence<Int>, rhs) => xs ++ rhs; concat([1], ([2], [3])) is now rejected during analysis, although at runtime the list can be broadcast across the unknown tuple and the List ++ List overload accepts each element. The previous permissive fallback included this valid candidate, so the new filtering should account for overlapping sequence-family types while still excluding genuinely incompatible scalar overloads.

Useful? React with 馃憤聽/ 馃憥.

@timfennis timfennis closed this Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant