Skip to content

Commit 2069b45

Browse files
committed
fix flow analyze
1 parent 8c10f90 commit 2069b45

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

crates/emmylua_code_analysis/src/db_index/flow/flow_chain.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ impl LuaFlowChain {
7777
})
7878
})
7979
}
80+
81+
pub fn merge_chain(&mut self, chain: LuaFlowChain) {
82+
if self.type_asserts.is_empty() {
83+
self.type_asserts = chain.type_asserts;
84+
return;
85+
}
86+
87+
for (path, entries) in chain.type_asserts {
88+
self.type_asserts
89+
.entry(path)
90+
.or_insert_with(Vec::new)
91+
.extend(entries);
92+
}
93+
}
8094
}
8195

8296
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]

crates/emmylua_code_analysis/src/db_index/flow/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ impl LuaFlowIndex {
2222

2323
pub fn add_flow_chain(&mut self, file_id: FileId, chain: LuaFlowChain) {
2424
let id = chain.get_flow_id();
25-
self.chains_map
26-
.entry(file_id)
27-
.or_insert_with(HashMap::new)
28-
.insert(id, chain);
25+
let old_chain = self.get_or_create_flow_chain(file_id, id);
26+
old_chain.merge_chain(chain);
2927
}
3028

3129
pub fn get_flow_chain(&self, file_id: FileId, flow_id: LuaFlowId) -> Option<&LuaFlowChain> {

crates/emmylua_code_analysis/src/db_index/type/type_ops/narrow_type.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use crate::{LuaType, LuaUnionType};
22

33
// need to be optimized
44
pub fn narrow_down_type(source: LuaType, target: LuaType) -> Option<LuaType> {
5+
if source == target {
6+
return Some(source);
7+
}
8+
59
match &target {
610
LuaType::Number => {
711
if source.is_number() {

0 commit comments

Comments
 (0)