Skip to content

Conversation

@lewis6991
Copy link
Collaborator

  • allow intersection types to be checked against class refs
  • add tests for intersection<->class assignment behavior
  • update intersection docs (EN/CN) and overload docs
  • keep annotation tests aligned with intersection semantics

@gemini-code-assist
Copy link

Summary of Changes

Hello @lewis6991, 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 improves the type analysis capabilities by enabling the type checker to properly handle assignments involving intersection types and class definitions. It ensures that complex type compositions, where properties from multiple types are merged, are correctly validated against class structures, leading to more robust and accurate type inference.

Highlights

  • Enhanced Type Checking for Intersections: The type checker now correctly processes intersection types when assigned to or from class references, improving the accuracy of type analysis.
  • New Test Cases: Comprehensive tests have been added to validate the behavior of intersection type assignments, including property merging and policy-based overwrites.
  • Updated Documentation: The English and Chinese documentation for intersection types has been expanded to clarify their order-sensitive nature and field conflict resolution.
  • Code Refactoring: Introduced an intersection_to_object utility and integrated it into the type checking logic for LuaType::Def, LuaType::Ref, and LuaType::Intersection cases.

🧠 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.

Changelog
  • crates/emmylua_code_analysis/src/compilation/test/annotation_test.rs
    • Added test_merge_right_mapped_type to verify property merging in intersection types.
    • Added test_extend_with_policy_overwrite to test explicit policy-based property overwrites in intersection types.
  • crates/emmylua_code_analysis/src/diagnostic/test/assign_type_mismatch_test.rs
    • Introduced test_intersection_assign_to_class to check type mismatch when assigning an intersection to a class.
    • Introduced test_intersection_assign_from_class to check type mismatch when assigning a class to an intersection.
  • crates/emmylua_code_analysis/src/semantic/type_check/complex_type/intersection_type_check.rs
    • Modified check_intersection_type_compact to convert LuaType::Def and LuaType::Ref intersection components into object types for type checking.
    • Imported intersection_to_object utility.
  • crates/emmylua_code_analysis/src/semantic/type_check/mod.rs
    • Added intersection_utils module.
  • crates/emmylua_code_analysis/src/semantic/type_check/ref_type.rs
    • Updated check_ref_class to handle LuaType::Intersection by converting it to an object type for comparison.
    • Imported intersection_to_object utility.
  • docs/emmylua_doc/annotations_CN/type.md
    • Added detailed explanation for intersection types, including order sensitivity and field conflict resolution.
  • docs/emmylua_doc/annotations_EN/overload.md
    • Minor formatting adjustment (added a blank line).
  • docs/emmylua_doc/annotations_EN/type.md
    • Added detailed explanation for intersection types, including order sensitivity and field conflict resolution.
Activity
  • The pull request was opened by lewis6991 with a clear description outlining the intent to allow intersection types to be checked against class references, add relevant tests, and update documentation.
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

@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 successfully implements type checking for assignments involving intersection types and class references. The changes are well-supported by new tests that cover various scenarios, including property overwriting based on intersection order. The documentation for intersection types has also been updated in both English and Chinese, which is a great addition for users. The core logic changes in intersection_type_check.rs and ref_type.rs correctly handle the conversion of intersection types to object types for comparison. I have one suggestion to improve code style for consistency. Overall, this is a great enhancement.

Comment on lines 25 to 34
if let Some(object_type) = intersection_to_object(context.db, source_intersection) {
let object_type = LuaType::Object(Arc::new(object_type));
return check_general_type_compact(
context,
&object_type,
compact_type,
check_guard.next_level()?,
);
}
Err(TypeCheckFailReason::TypeNotMatch)

Choose a reason for hiding this comment

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

medium

For better readability and consistency with idiomatic Rust, you can refactor this if block to be an expression. This avoids the explicit return and makes the code flow similar to the new logic in ref_type.rs.

            if let Some(object_type) = intersection_to_object(context.db, source_intersection) {
                let object_type = LuaType::Object(Arc::new(object_type));
                check_general_type_compact(
                    context,
                    &object_type,
                    compact_type,
                    check_guard.next_level()?,
                )
            } else {
                Err(TypeCheckFailReason::TypeNotMatch)
            }

@xuhuanzy
Copy link
Member

xuhuanzy commented Feb 4, 2026

You should install the Git hooks first. The hooks include some basic checks to prevent failures in basic GitHub Actions checks.

Also, regarding AI usage, I recommend using gpt-5.2 in Codex (don’t use gpt-5.2-codex), with the reasoning effort set to xhigh. For backend work, Codex’s capabilities far exceed CC.

@lewis6991
Copy link
Collaborator Author

Ah ok, I have been using gpt-5.2-codex. I'll try gpt-5.2.

@xuhuanzy
Copy link
Member

xuhuanzy commented Feb 4, 2026

gpt-5.2-codex trades quality for speed, and its output quality is very poor. It should only be used for asking questions, not for generating code.

@xuhuanzy
Copy link
Member

xuhuanzy commented Feb 4, 2026

You can use gpt-5.2 to improve the previous PR.

From what I’ve seen, code generated by gpt-5.2 is usually two tiers better than gpt-5.2-codex, and most importantly, it tends to take edge cases into account.

@lewis6991
Copy link
Collaborator Author

The previous PR already handles some pretty whacky edge cases (with tests). I can try though.

@lewis6991 lewis6991 force-pushed the fix/interassign branch 3 times, most recently from e32ebd4 to 7754eef Compare February 4, 2026 17:06
- allow intersection types to be checked against class refs
- include inherited class members when checking intersection-derived
  objects against class refs
- add regression tests for intersection<->class assignment and table
  literal behavior
- update intersection docs (EN/CN) and overload docs
- keep annotation tests aligned with intersection semantics
@CppCXY CppCXY merged commit 1704736 into EmmyLuaLs:main Feb 6, 2026
22 checks passed
@lewis6991 lewis6991 deleted the fix/interassign branch February 6, 2026 11:27
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.

3 participants