-
Notifications
You must be signed in to change notification settings - Fork 50
update #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update #857
Conversation
Summary of ChangesHello @xuhuanzy, 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 refines the handling of generic type constraints within the EmmyLua code analysis engine. By integrating type constraints directly into generic type representations and updating the type inference and checking mechanisms, the system can now more accurately understand and validate generic type usage, leading to more robust code analysis. It also introduces new fundamental types for better type system expressiveness and includes a new test case to ensure the correct application of these enhancements. Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 support for generic constraints, allowing them to be used as default types when a generic argument is not specified. This is achieved by adding a constraint field to GenericTpl and related types, and updating the type inference and instantiation logic accordingly. The changes are logical and implement a valuable feature.
My review has identified a high-severity correctness issue regarding the Hash implementation for LuaType, which violates the Hash contract and could lead to incorrect behavior. Additionally, I've pointed out a couple of medium-severity maintainability issues where comments were written in Chinese within a predominantly English codebase.
| LuaType::TplRef(a) => { | ||
| let ptr = Arc::as_ptr(a); | ||
| (32, ptr).hash(state) | ||
| } | ||
| LuaType::StrTplRef(a) => { | ||
| let ptr = Arc::as_ptr(a); | ||
| (33, ptr).hash(state) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Hash implementation for Arc-wrapped types like TplRef and StrTplRef uses pointer hashing (Arc::as_ptr). However, the PartialEq implementation for LuaType compares the contained values, not the pointers. This violates the Hash contract, which requires that if a == b, then hash(a) == hash(b).
This can lead to subtle bugs. For example, LuaType::from_vec uses a HashSet<LuaType> to deduplicate types. With this Hash implementation, two equal LuaType values that are allocated separately will have different hashes and will not be considered duplicates by the HashSet. This can result in unions with duplicate types (e.g., string | string).
This seems to be a pre-existing issue in the codebase that is being extended in this PR. A proper fix would be complex, likely involving a recursive Hash implementation with cycle detection or interning all Arc-wrapped types. Given the potential for incorrect behavior, this is a significant issue to be aware of.
| let result_ty = ws.expr_ty("result"); | ||
| assert_eq!(result_ty, ws.ty("number")); | ||
| } | ||
| // 类的默认泛型约束暂时不支持 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.