Skip to content

Commit 3c589ee

Browse files
committed
update type check
1 parent 9ef30ae commit 3c589ee

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,4 +1308,30 @@ mod test {
13081308
"#
13091309
));
13101310
}
1311+
1312+
#[test]
1313+
fn test_self_contain_tpl() {
1314+
let mut ws = VirtualWorkspace::new();
1315+
ws.def_file(
1316+
"test.lua",
1317+
r#"
1318+
---@class Observable<T>
1319+
Observable = {}
1320+
1321+
---@param ... Observable<any>
1322+
function zip(...)
1323+
end
1324+
1325+
"#,
1326+
);
1327+
1328+
assert!(ws.check_code_for_namespace(
1329+
DiagnosticCode::ParamTypeNotMatch,
1330+
r#"
1331+
function Observable:test()
1332+
zip(self)
1333+
end
1334+
"#
1335+
));
1336+
}
13111337
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,15 @@ fn check_generic_type_compact_ref_type(
284284
}
285285
}
286286

287+
// 如果泛型参数是`any`, 那么我们只需要匹配基础类型
288+
if source_generic.get_params().iter().any(|p| p.is_any()) {
289+
return check_general_type_compact(
290+
context,
291+
&source_generic.get_base_type(),
292+
&LuaType::Ref(ref_id.clone()),
293+
check_guard.next_level()?,
294+
);
295+
}
296+
287297
Err(TypeCheckFailReason::TypeNotMatch)
288298
}

0 commit comments

Comments
 (0)