Skip to content

Conversation

@hongjr03
Copy link
Contributor

Propagates contextual types through destructuring and tuple/array constraints, including field-access backprop. Adds tuple destructuring and include for-loop fixtures/snapshots.

Depends on #2385.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hongjr03, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly advances the type checking capabilities by implementing contextual type propagation across various language constructs. It focuses on improving type inference for destructuring, tuple/array flows, and field access, which leads to more precise type suggestions and error detection. The changes also refine how paths are typed in import and include statements and enhance type resolution within for loops, making the type system more intelligent and helpful for developers.

Highlights

  • Contextual Type Propagation: Enhanced the type checking system to propagate contextual types more effectively through destructuring assignments, tuple and array constraints, and field access expressions.
  • Destructuring Type Inference: Introduced comprehensive support for type inference in destructuring patterns, including handling positional and named bindings, and spread operators.
  • Improved Path Type Checking: Refined type inference for import and include expressions, ensuring that source paths are correctly constrained and checked.
  • Dynamic Key Handling: Improved the evaluation of dynamic keys in dictionary literals and dict.at() calls, allowing constant string keys to be correctly identified and used for type inference.
  • Enhanced For Loop Typing: Added contextual typing for for loops, enabling more accurate type inference for elements iterated over in arrays or tuples.
  • New Test Fixtures: Added a suite of new completion and post-type-check fixtures to validate the correctness and robustness of the new contextual typing features.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant enhancements to the type checking system, enabling contextual type propagation for destructuring assignments and flows involving tuples and arrays. Key changes include back-propagation of types for field access (e.g., through dict.at("key")), improved type inference for for loops, and constant folding for string concatenation. The changes are extensive and well-supported by new test cases.

I have identified a couple of areas for improvement. One is a potential bug in destructuring logic that could lead to loss of type information when spreads are used. The other is a suggestion to generalize the new for loop type inference to support more complex patterns beyond simple identifiers.

Overall, this is a great feature addition that will improve the accuracy of type analysis.

Comment on lines 445 to 448
if trailing_pos_after_spread {
has_pos = false;
pos.clear();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This block of code incorrectly clears all inferred positional pattern types if a spread is followed by another positional pattern (e.g., in (a, ..rest, b)). This results in losing the type information for prefix patterns like a. According to the comment on line 443, the intention is to keep the prefix mapping, so this block should be removed to prevent discarding valid type information.

Comment on lines 694 to 738
if matches!(for_loop.pattern.as_ref(), Pattern::Simple(..)) {
self.constrain(&iter, &Ty::Array(pattern.clone().into()));

match &iter {
Ty::Array(elem) => self.constrain(elem, &pattern),
Ty::Tuple(elems) => {
for elem in elems.iter() {
self.constrain(elem, &pattern);
}
}
_ => {}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The type constraint logic for for loops is currently limited to Pattern::Simple. This prevents type propagation for more complex patterns like destructuring (k, v), which is a common use case. The logic for constraining the iterable and its elements seems general enough to be applied to all pattern types, which would make this feature more powerful and consistent.

Consider removing the if matches!(...) condition to apply the type constraints for all for loop patterns.

        self.constrain(&iter, &Ty::Array(pattern.clone().into()));

        match &iter {
            Ty::Array(elem) => self.constrain(elem, &pattern),
            Ty::Tuple(elems) => {
                for elem in elems.iter() {
                    self.constrain(elem, &pattern);
                }
            }
            _ => {}
        }

@hongjr03 hongjr03 force-pushed the split/03-contextual-typing branch from 41a23d6 to 729f5fa Compare January 29, 2026 09:50
@hongjr03 hongjr03 force-pushed the split/03-contextual-typing branch from 729f5fa to 5f625da Compare January 29, 2026 10:33
@hongjr03 hongjr03 force-pushed the split/03-contextual-typing branch from 5f625da to 73a8f7a Compare January 29, 2026 11:55
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