Skip to content

Commit c9ae110

Browse files
committed
Fix infer guard
1 parent 6734760 commit c9ae110

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

crates/code_analysis/src/semantic/infer/infer_config.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ use crate::{db_index::LuaType, FileId};
88
pub struct LuaInferConfig {
99
require_function: HashSet<String>,
1010
file_id: FileId,
11-
expr_type_cache: HashMap<LuaSyntaxId, LuaType>,
11+
expr_type_cache: HashMap<LuaSyntaxId, ExprCache>,
12+
}
13+
14+
#[derive(Debug)]
15+
pub enum ExprCache {
16+
ReadyCache,
17+
Cache(LuaType),
1218
}
1319

1420
impl LuaInferConfig {
@@ -32,11 +38,15 @@ impl LuaInferConfig {
3238
self.file_id
3339
}
3440

41+
pub fn mark_ready_cache(&mut self, syntax_id: LuaSyntaxId) {
42+
self.expr_type_cache.insert(syntax_id, ExprCache::ReadyCache);
43+
}
44+
3545
pub fn cache_expr_type(&mut self, syntax_id: LuaSyntaxId, ty: LuaType) {
36-
self.expr_type_cache.insert(syntax_id, ty);
46+
self.expr_type_cache.insert(syntax_id, ExprCache::Cache(ty));
3747
}
3848

39-
pub fn get_cache_expr_type(&self, syntax_id: &LuaSyntaxId) -> Option<&LuaType> {
49+
pub fn get_cache_expr_type(&self, syntax_id: &LuaSyntaxId) -> Option<&ExprCache> {
4050
self.expr_type_cache.get(syntax_id)
4151
}
4252
}

crates/code_analysis/src/semantic/infer/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use emmylua_parser::{LuaAstNode, LuaClosureExpr, LuaExpr, LuaLiteralExpr, LuaLit
1010
use infer_binary::infer_binary_expr;
1111
use infer_call::infer_call_expr;
1212
pub use infer_call::instantiate_doc_function;
13+
use infer_config::ExprCache;
1314
pub use infer_config::LuaInferConfig;
1415
use infer_index::infer_index_expr;
1516
use infer_name::infer_name_expr;
@@ -25,8 +26,10 @@ pub type InferResult = Option<LuaType>;
2526

2627
pub fn infer_expr(db: &DbIndex, config: &mut LuaInferConfig, expr: LuaExpr) -> InferResult {
2728
let syntax_id = expr.get_syntax_id();
28-
if let Some(result) = config.get_cache_expr_type(&syntax_id) {
29-
return Some(result.clone());
29+
match config.get_cache_expr_type(&syntax_id) {
30+
Some(ExprCache::Cache(ty)) => return Some(ty.clone()),
31+
Some(ExprCache::ReadyCache) => return Some(LuaType::Unknown),
32+
None => {}
3033
}
3134

3235
// for @as
@@ -37,6 +40,7 @@ pub fn infer_expr(db: &DbIndex, config: &mut LuaInferConfig, expr: LuaExpr) -> I
3740
return Some(force_type.clone());
3841
}
3942

43+
config.mark_ready_cache(syntax_id);
4044
let result_type = match expr {
4145
LuaExpr::CallExpr(call_expr) => infer_call_expr(db, config, call_expr)?,
4246
LuaExpr::TableExpr(table_expr) => infer_table_expr(db, config, table_expr)?,

0 commit comments

Comments
 (0)