refactor generic#1081
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
|
/gemini review |
|
/gemini review |
|
/gemini review |
现在 std.Unpack 的目标泛型必须使用 std.ConstTpl 包裹以保持常量传播
9ddc9a4 to
9a4ec66
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request significantly refactors the generic type system, replacing the TypeSubstitutor with a more flexible TypeMapper and introducing a dedicated inference module to handle complex generic scenarios. It adds support for built-in utility types like Pick and Omit, implements mapped types, and improves the inference of nested table literals in function calls. Reviewers identified opportunities to improve string template matching by including documentation-defined constants, suggested a more robust approach for handling iterator return types in __pairs metamethods, and provided a correction to ensure consistent literal preservation logic during type resolution.
| } | ||
| } | ||
| LuaType::StrTplRef(str_tpl) => { | ||
| if let LuaType::StringConst(s) = target { |
There was a problem hiding this comment.
The pattern matching for StrTplRef only handles LuaType::StringConst, but it should also handle LuaType::DocStringConst to support string literals defined in documentation annotations. This ensures consistent behavior between source-code literals and annotation-defined literals.
if let LuaType::StringConst(s) | LuaType::DocStringConst(s) = target {| if let Some(LuaType::Variadic(variadic)) = &final_return_type { | ||
| let key_type = variadic.get_type(0).ok_or(InferFailReason::None)?; | ||
| let value_type = variadic.get_type(1).ok_or(InferFailReason::None)?; |
There was a problem hiding this comment.
The check for LuaType::Variadic might be too restrictive. If the iterator function returns only a single value (the key), final_return_type will be a simple type rather than a Variadic multi-return. Using get_result_slot_type would handle both single and multiple return values more robustly.
if let Some(key_type) = final_return_type.as_ref().and_then(|t| t.get_result_slot_type(0)) {
let value_type = final_return_type.as_ref().and_then(|t| t.get_result_slot_type(1)).unwrap_or(LuaType::Nil);
let (key_type, value_type) = (&key_type, &value_type);| let preserve_root_literal_form = | ||
| primitive_constraint || const_preserving || return_top_level; |
There was a problem hiding this comment.
For consistency with the resolution of covariant candidates (see line 84), the preserve_root_literal_form logic for multi-type candidates should also include the !info.top_level check. This ensures that literals are regularized correctly when matched against nested structures, preventing premature widening.
| let preserve_root_literal_form = | |
| primitive_constraint || const_preserving || return_top_level; | |
| let preserve_root_literal_form = | |
| primitive_constraint || const_preserving || !info.top_level || return_top_level; |
No description provided.