fix(inference): improve member and Promise inference - #10971
Conversation
|
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
cf9f112 to
1bb5720
Compare
9d9f35a to
2c81541
Compare
1bb5720 to
efbb8c9
Compare
2c81541 to
6e59183
Compare
efbb8c9 to
7bc7004
Compare
6e59183 to
dd1cc2c
Compare
7bc7004 to
d4621d0
Compare
dd1cc2c to
cb77297
Compare
cb77297 to
3e0b12a
Compare
d4621d0 to
e8bb18f
Compare
3e0b12a to
4bf9b21
Compare
e8bb18f to
04f414a
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe module graph type inference engine preserves local handles for recursive cycles and resolves Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/biome_module_graph/src/db/queries/type_inference.rs`:
- Around line 1849-1862: Update the default-resolution loop around
function.type_parameters(db) so each generic default is substituted through all
previously accumulated substitutions before replacing the current generic.
Ensure chained defaults such as T = string and U = T resolve U to string rather
than leaving T, and add a regression case covering dependent defaults.
In `@crates/biome_module_graph/tests/spec_tests_v2.rs`:
- Around line 4202-4206: The snapshot key passed to
assert_inferred_type_snapshot in
test_infer_module_types_resolves_inherited_static_members is incorrect; rename
it to match that test’s inherited-static behavior, rather than the copied
resolves_this_member_in_object_method name.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e369659b-8173-4f65-8110-62ffb152f5eb
⛔ Files ignored due to path filters (16)
crates/biome_module_graph/tests/snapshots/test_infer_call_expression_type_selects_function_declaration_overload_by_callback_return_type.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_call_expression_type_selects_imported_function_declaration_overload_by_callback_return_type.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_call_expression_type_substitutes_generic_from_callback_promise_return_type.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_call_expression_type_substitutes_generic_from_callback_promise_union_return_type.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_call_expression_type_substitutes_generic_inside_promise_union_return_type.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_call_expression_type_substitutes_multiple_generics_inside_union_return_type.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_call_expression_type_substitutes_nested_generic_return_type.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_evaluates_await_expressions_on_build.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_evaluates_await_union_expressions_on_build.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_evaluates_this_and_super_edge_expressions_on_build.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_infers_new_expression_nested_generic_instances_on_build.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_preserves_floating_promise_shapes.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_preserves_generic_class_this_parameters.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_preserves_new_expression_generic_instances_on_build.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_resolves_promise_member_chain.snapis excluded by!**/*.snapand included by**crates/biome_module_graph/tests/snapshots/test_infer_module_types_resolves_this_member_in_object_method.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (6)
crates/biome_module_graph/src/db/queries/type_inference.rscrates/biome_module_graph/src/db/type_inference/expressions.rscrates/biome_module_graph/src/db/type_inference/lookup.rscrates/biome_module_graph/src/db/type_inference/qualifiers.rscrates/biome_module_graph/src/db/type_inference/resolver.rscrates/biome_module_graph/tests/spec_tests_v2.rs
Merging this PR will regress 0 benchmarks
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
crates/biome_module_graph/src/db/type_inference/expressions.rs (2)
1159-1258: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winStatic vs. instance members aren't distinguished in the in-progress fast path.
resolve_in_progress_local_membermatchesclass.memberspurelyby has_name(member_name), with no check againstmember.kind.is_static(). Both call sites (Line 973-976 for a direct static access, Line 987-990 for an instance access) rely on this, so a class with both a static and instance member sharing the same name (legal in JS/TS, they live on different sides) can return the wrong one whenever the enclosing class is stillin_progress(e.g. resolved viathis/self-reference). The normal traversal path threadsMemberLookupModeeverywhere else — this fast path silently drops that discrimination.🛠️ Proposed fix
fn resolve_in_progress_local_member( &mut self, local: InferredLocalTypeHandle<'db>, member_name: &str, + is_static: bool, ) -> Option<InferredTypeData<'db>> { ... let member = match raw { - RawTypeData::Class(class) => class - .members - .iter() - .find(|member| member.kind.has_name(member_name)), + RawTypeData::Class(class) => class.members.iter().find(|member| { + member.kind.has_name(member_name) && member.kind.is_static() == is_static + }), RawTypeData::Interface(interface) => interfaceCallers then pass the appropriate flag:
// Line 973-976 (static access on the object itself) self.resolve_in_progress_local_member(local, member_name, true) // Line 987-990 (access through an instance) self.resolve_in_progress_local_member(local, member_name, false)Also applies to: 973-976, 987-990
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/biome_module_graph/src/db/type_inference/expressions.rs` around lines 1159 - 1258, Update resolve_in_progress_local_member to accept a static-member flag and filter class member matching by member.kind.is_static() accordingly. Pass true from the direct static access call site and false from the instance access call site, while preserving existing behavior for interfaces, objects, and literals.
1077-1094: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winTuple/Array member lookup should cross
InstanceOfThe tuple branch builds a rawArraylookup and applies substitutions afterwards, socrossed_instancenever flips totrueandresolve_member_references()is skipped. Use the normalInstanceOfpath here so generic return types on methods like.pop()/.shift()don’t stay unresolved.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/biome_module_graph/src/db/type_inference/expressions.rs` around lines 1077 - 1094, Update the tuple branch of the member lookup logic to route the resolved Array type through the normal InstanceOf path instead of directly calling find_member_type_on_resolved_type. Preserve the tuple element union and Array substitutions, while ensuring crossed_instance becomes true so resolve_member_references() resolves generic method return types such as pop() and shift().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/biome_module_graph/src/db/type_inference/lookup.rs`:
- Around line 506-511: Update the Class arm in the type lookup match to pass
mode.allows_index_signature() to find, matching the Interface, Object, and
Literal(Object) arms. Remove the matches!(mode, MemberLookupMode::Instance)
check so MemberLookupMode::Any also permits index-signature fallback.
In `@crates/biome_module_graph/tests/spec_tests_v2/substitutions.test.rs`:
- Around line 109-113: Update the assertion in the substitution test to verify
that success_ty is the canonical InferredTypeData::Boolean union containing both
true and false branches, rather than relying on is_inferred_boolean, which also
accepts a single literal. Preserve the existing diagnostic context when the
assertion fails.
---
Outside diff comments:
In `@crates/biome_module_graph/src/db/type_inference/expressions.rs`:
- Around line 1159-1258: Update resolve_in_progress_local_member to accept a
static-member flag and filter class member matching by member.kind.is_static()
accordingly. Pass true from the direct static access call site and false from
the instance access call site, while preserving existing behavior for
interfaces, objects, and literals.
- Around line 1077-1094: Update the tuple branch of the member lookup logic to
route the resolved Array type through the normal InstanceOf path instead of
directly calling find_member_type_on_resolved_type. Preserve the tuple element
union and Array substitutions, while ensuring crossed_instance becomes true so
resolve_member_references() resolves generic method return types such as pop()
and shift().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f2ef0fa6-49e3-4084-88af-c8111aa96dba
📒 Files selected for processing (3)
crates/biome_module_graph/src/db/type_inference/expressions.rscrates/biome_module_graph/src/db/type_inference/lookup.rscrates/biome_module_graph/tests/spec_tests_v2/substitutions.test.rs
| /// Member lookup runs both while raw module types are being converted and | ||
| /// after inferred type tables are available. Implementations supply the local | ||
| /// type resolution and member finalization appropriate for either phase. | ||
| pub(in crate::db::type_inference) trait MemberLookupResolver<'db> { |
There was a problem hiding this comment.
The member lookup logic has been moved into this trait, because it's now a shared logic and there was a regression caused by the two original logic to drift
Summary
Improves internal member, array, Promise, and await inference. The new engine resolves additional inherited, computed, intersection, generic, and chained member shapes while preserving non-Promise branches of awaited unions. No lint rule changes inference engines in this PR, so no changeset is included.
Test Plan
Extended module graph tests for member chains, typed arrays, Promise results, and await expressions.
Docs
N/A