🐛 fix(mq-check): skip Refs with Selector children in type narrowing#1434
🐛 fix(mq-check): skip Refs with Selector children in type narrowing#1434
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes an interaction between flow-sensitive type narrowing and selector-based attribute access in mq-check, preventing narrowed variable types from overwriting selector result types.
Changes:
- Build a set of
Refsymbol IDs that haveSelectorchildren. - Skip applying type narrowings to those
Refs so selector output types (e.g.,md.depth: Number) aren’t corrupted.
| let mut refs_with_selector_child: rustc_hash::FxHashSet<SymbolId> = rustc_hash::FxHashSet::default(); | ||
| for (_, sym) in hir.symbols() { | ||
| if let Some(parent_id) = sym.parent | ||
| && matches!(sym.kind, mq_hir::SymbolKind::Selector(_)) | ||
| { |
There was a problem hiding this comment.
FxHashSet is already imported (along with SymbolKind), so using the fully-qualified rustc_hash::FxHashSet / mq_hir::SymbolKind here is redundant and inconsistent with the rest of the module. Consider using the existing imports (and letting the type be inferred) to keep this block idiomatic and reduce noise.
| // Skip Refs that have Selector children (e.g., `node.row`): their stored | ||
| // type is the selector output, not the variable type, so narrowing them | ||
| // would corrupt the selector output. | ||
| if refs_with_selector_child.contains(&ref_id) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
This change fixes a subtle narrowing/selector interaction, but there’s no regression test covering it. Please add a test case where a variable is known to be Markdown (e.g., let x = .h;) and inside if (is_markdown(x)) an attribute selector like x.depth is used in a numeric context (e.g., x.depth + 1), asserting it type-checks. Without the skip, narrowing would incorrectly override the Ref’s selector-output type and the test would fail.
No description provided.