Skip to content

Commit e83a3de

Browse files
committed
update type_check
1 parent 939aa34 commit e83a3de

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,29 @@ mod tests {
213213
assert!(ws.check_code_for(
214214
DiagnosticCode::ReturnTypeMismatch,
215215
r#"
216-
---@return string?
217-
local function a()
218-
---@type int?
219-
local ccc
220-
return ccc and a() or nil
221-
end
216+
---@return string?
217+
local function a()
218+
---@type int?
219+
local ccc
220+
return ccc and a() or nil
221+
end
222+
"#
223+
));
224+
}
225+
226+
#[test]
227+
fn test_2() {
228+
let mut ws = VirtualWorkspace::new();
222229

230+
assert!(ws.check_code_for(
231+
DiagnosticCode::ReturnTypeMismatch,
232+
r#"
233+
---@return any[]
234+
local function a()
235+
---@type table|table<any, any>
236+
local ccc
237+
return ccc
238+
end
223239
"#
224240
));
225241
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ pub fn check_complex_type_compact(
6262
);
6363
}
6464
LuaType::Table => return Ok(()),
65+
LuaType::TableGeneric(compact_types) => {
66+
if compact_types.len() == 2 {
67+
for typ in compact_types.iter() {
68+
if check_general_type_compact(
69+
db,
70+
source_base,
71+
typ,
72+
check_guard.next_level()?,
73+
)
74+
.is_err()
75+
{
76+
return Err(TypeCheckFailReason::TypeNotMatch);
77+
}
78+
}
79+
80+
return Ok(());
81+
}
82+
}
6583
_ => {}
6684
},
6785
LuaType::Tuple(tuple) => {

0 commit comments

Comments
 (0)