diagnostic#297
Conversation
| ---@overload fun(e:number, base?: int):number | ||
| ---@overload fun(e:string, base?: int):number? | ||
| ---@overload fun(e:any, base?:int):nil | ||
| ---@overload fun(e: string, base: integer):integer |
There was a problem hiding this comment.
e 为 string 下必然返回integer或者nil吧
There was a problem hiding this comment.
Pull Request Overview
This PR titled "diagnostic" addresses issues #283 and #290 by refining type checking and diagnostic reporting.
- Updates type comparison logic in Lua function type checking and binary expression inference.
- Enhances diagnostic tests for parameter type mismatches and incomplete signature documentation.
- Refines behavior for constant type removal and adds an additional flow test for type humanization.
Reviewed Changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/emmylua_code_analysis/src/semantic/type_check/func_type.rs | Adds an early continue when both parameter types are self-inferred. |
| crates/emmylua_code_analysis/src/semantic/infer/infer_binary.rs | Expands binary expression type inference to account for nil, any, or unknown types. |
| crates/emmylua_code_analysis/src/diagnostic/test/param_type_check_test.rs | Introduces a new test for parameter type mismatch. |
| crates/emmylua_code_analysis/src/diagnostic/test/incomplete_signature_doc_test.rs | Adds a new test case for incomplete signature documentation. |
| crates/emmylua_code_analysis/src/diagnostic/checker/incomplete_signature_doc.rs | Updates parameter checking to ignore the "_" parameter. |
| crates/emmylua_code_analysis/src/db_index/type/type_ops/remove_type.rs | Adjusts constant type removal to convert integer/float constants to general types. |
| crates/emmylua_code_analysis/src/compilation/test/flow.rs | Adds a new flow test to validate type humanization for variables. |
Files not reviewed (2)
- crates/emmylua_code_analysis/resources/std/global.lua: Language not supported
- crates/emmylua_code_analysis/resources/std/math.lua: Language not supported
d4140be to
877ada9
Compare
| unresolve_table_field.reason, | ||
| InferFailReason::UnResolveExpr(_) | ||
| ) { | ||
| return None; |
| matches!(self, LuaType::Ref(_) | LuaType::TableConst(_)) | ||
| } | ||
|
|
||
| pub fn has_nil(&self) -> bool { |
There was a problem hiding this comment.
Pull Request Overview
This PR aims to resolve several diagnostic issues and improve type handling in the codebase, as evidenced by fixes for multiple issue numbers. Key changes include:
- Adding new tests for duplicate require and type mismatch diagnostics.
- Refining diagnostic checkers (e.g. incomplete signature documentation and duplicate require) and enhancing type operations.
- Introducing new resolution paths and unresolve handling for table fields and improving humanization and member key operations.
Reviewed Changes
Copilot reviewed 28 out of 31 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/emmylua_code_analysis/src/diagnostic/test/duplicate_require_test.rs | Added a new test (test_field) for duplicate require diagnostic handling on table field accesses. |
| crates/emmylua_code_analysis/src/diagnostic/test/assign_type_mismatch_test.rs | Inserted tests for issues 295 and 285 to validate assign type mismatch diagnostics. |
| crates/emmylua_code_analysis/src/diagnostic/checker/incomplete_signature_doc.rs | Updated param checking to allow "_" as a valid parameter name. |
| crates/emmylua_code_analysis/src/diagnostic/checker/duplicate_require.rs | Modified duplicate require checking to ignore calls when used as part of field access. |
| crates/emmylua_code_analysis/src/diagnostic/checker/check_field.rs | Refactored member key extraction and validation logic for improved robustness. |
| crates/emmylua_code_analysis/src/db_index/type/types.rs | Added a helper method (has_nil) to determine if a type contains nil. |
| crates/emmylua_code_analysis/src/db_index/type/type_ops/remove_type.rs | Adjusted removal behavior for constant types (IntegerConst and FloatConst). |
| crates/emmylua_code_analysis/src/db_index/type/type_assert.rs | Introduced an is_reassign check for type assertions. |
| crates/emmylua_code_analysis/src/db_index/type/humanize_type.rs | Enhanced union type humanization and added handling for SyntaxId member keys. |
| crates/emmylua_code_analysis/src/db_index/member/lua_member.rs | Added a SyntaxId variant with corresponding ordering and helper methods. |
| crates/emmylua_code_analysis/src/compilation/test/flow.rs | Provided an additional test (test_docint) to verify type humanization with delayed table analysis. |
| crates/emmylua_code_analysis/src/compilation/analyzer/unresolve/resolve.rs | Added try_resolve_table_field to improve table field resolution along with extended unresolve support. |
| crates/emmylua_code_analysis/src/compilation/analyzer/unresolve/mod.rs | Added the UnResolve::TableField variant and its corresponding struct for delayed resolution. |
| crates/emmylua_code_analysis/src/compilation/analyzer/lua/stats.rs | Introduced a helper to detect call expressions with non-empty table arguments. |
| crates/emmylua_code_analysis/src/compilation/analyzer/flow/var_analyze.rs | Renamed variables for clarity and adjusted the arithmetic for selecting the matching value expression. |
| crates/emmylua_code_analysis/src/compilation/analyzer/decl/mod.rs | Updated the declaration analyzer to capture and forward unresolved declarations. |
| crates/emmylua_code_analysis/src/compilation/analyzer/decl/exprs.rs | Refined table expression analysis by adding unresolve handling for fields missing a valid key. |
Files not reviewed (3)
- crates/emmylua_code_analysis/resources/std/global.lua: Language not supported
- crates/emmylua_code_analysis/resources/std/math.lua: Language not supported
- crates/emmylua_code_analysis/resources/std/table.lua: Language not supported
| ( | ||
| value_exprs.last()?.clone(), | ||
| (index - value_exprs.len()) as i32, | ||
| (var_index - (value_exprs.len() - 1)) as i32, |
There was a problem hiding this comment.
The change in the arithmetic for computing the index offset in the else branch may be error prone; please double-check that the new formula correctly determines the intended offset compared to the previous implementation.
| (var_index - (value_exprs.len() - 1)) as i32, | |
| (var_index - value_exprs.len() + 1) as i32, |
fixes #283
fixes #290
fixes #295
fixes #286
fixes #300
fixes #292
fixes #296
fixes #285
fixes #302