Skip to content

Commit 122f37d

Browse files
committed
optimize type check
1 parent 99785b2 commit 122f37d

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

crates/emmylua_code_analysis/src/db_index/type/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl LuaType {
195195
pub fn is_table(&self) -> bool {
196196
matches!(
197197
self,
198-
LuaType::Table | LuaType::TableGeneric(_) | LuaType::TableConst(_) | LuaType::Global
198+
LuaType::Table | LuaType::TableGeneric(_) | LuaType::TableConst(_) | LuaType::Global | LuaType::Tuple(_)
199199
)
200200
}
201201

crates/emmylua_code_analysis/src/semantic/type_check/func_type.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ fn infer_doc_func_type_compact_for_params(
6666
compact_params.insert(0, ("self".to_string(), None));
6767
}
6868

69-
let source_len = source_params.len();
70-
for i in 0..source_len {
71-
let source_param = &source_params[i];
69+
let compact_len = compact_params.len();
70+
for i in 0..compact_len {
71+
let source_param = match source_params.get(i) {
72+
Some(p) => p,
73+
None => {
74+
return false;
75+
}
76+
};
77+
let compact_param = &compact_params[i];
78+
7279
let source_param_type = &source_param.1;
7380
// too many complex session to handle varargs
7481
if source_param.0 == "..." {
@@ -85,19 +92,6 @@ fn infer_doc_func_type_compact_for_params(
8592
return false;
8693
}
8794

88-
let compact_param = match compact_params.get(i) {
89-
Some(p) => p,
90-
None => {
91-
if let Some(source_type) = &source_param.1 {
92-
if source_type.is_optional() {
93-
continue;
94-
}
95-
};
96-
97-
return false;
98-
}
99-
};
100-
10195
if compact_param.0 == "..." {
10296
break;
10397
}

crates/emmylua_code_analysis/src/semantic/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn infer_type_compact(
7878
LuaType::DocStringConst(t) => *s == t,
7979
_ => false,
8080
},
81-
(LuaType::FloatConst(_), _) => compact_type.is_number(),
81+
(LuaType::FloatConst(_), right) if right.is_number() => true,
8282
(LuaType::Table, _) => {
8383
compact_type.is_table()
8484
|| compact_type.is_array()

0 commit comments

Comments
 (0)