Skip to content

Commit 6ccc25e

Browse files
committed
diagnostic: AssignTypeMismatch 移除 table 过滤
1 parent e78c85d commit 6ccc25e

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

crates/emmylua_code_analysis/src/diagnostic/checker/assign_type_mismatch.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,17 @@ pub fn check_table_expr(
206206
semantic_model: &SemanticModel,
207207
table_expr: &LuaExpr,
208208
table_type: Option<&LuaType>, // 记录的类型
209-
expr_type: Option<&LuaType>, // 实际表达式推导出的类型
209+
_expr_type: Option<&LuaType>, // 实际表达式推导出的类型
210210
) -> Option<bool> {
211211
// 需要进行一些过滤
212-
if table_type == expr_type {
213-
return Some(false);
214-
}
212+
// if table_type == expr_type {
213+
// return Some(false);
214+
// }
215215
let table_type = table_type?;
216-
match table_type {
217-
LuaType::Def(_) => return Some(false),
218-
_ => {}
219-
}
216+
// match table_type {
217+
// LuaType::Def(_) => return Some(false),
218+
// _ => {}
219+
// }
220220
if let Some(table_expr) = LuaTableExpr::cast(table_expr.syntax().clone()) {
221221
return check_table_expr_content(context, semantic_model, table_type, &table_expr);
222222
}

crates/emmylua_code_analysis/src/diagnostic/test/assign_type_mismatch_test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,4 +948,18 @@ return t
948948
"#
949949
));
950950
}
951+
952+
#[test]
953+
fn test_tabe_field_type_mismatch() {
954+
let mut ws = VirtualWorkspace::new();
955+
assert!(!ws.check_code_for(
956+
DiagnosticCode::AssignTypeMismatch,
957+
r#"
958+
local export = {
959+
---@type number?
960+
vvv = "a"
961+
}
962+
"#
963+
));
964+
}
951965
}

0 commit comments

Comments
 (0)