From c11d61781020119cba427589dc96d271290d93fe Mon Sep 17 00:00:00 2001 From: ShenzhenGopher Date: Thu, 11 Jun 2026 15:08:21 +0800 Subject: [PATCH] fix: add Union branch to check_generic_type_compact When a method has both @field declaration and function implementation, resolve_member_type merges them into a Union type. check_generic_type_compact lacked a LuaType::Union branch, causing param-type-mismatch / assign-type-mismatch false positives even when all union members satisfy the generic constraint. Add a Union arm that iterates all members and checks each against the source generic type, following standard covariant semantics. --- .../src/semantic/type_check/generic_type.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/emmylua_code_analysis/src/semantic/type_check/generic_type.rs b/crates/emmylua_code_analysis/src/semantic/type_check/generic_type.rs index 0929c7ed5..c91c80424 100644 --- a/crates/emmylua_code_analysis/src/semantic/type_check/generic_type.rs +++ b/crates/emmylua_code_analysis/src/semantic/type_check/generic_type.rs @@ -99,6 +99,19 @@ pub fn check_generic_type_compact( check_guard.next_level()?, ) } + LuaType::Union(union_type) => { + // When compact_type is a Union, every member of the union must be + // assignable to the source generic type for the assignment to be safe. + for member_type in union_type.into_vec() { + check_generic_type_compact( + context, + source_generic, + &member_type, + check_guard.next_level()?, + )?; + } + Ok(()) + } _ => Err(TypeCheckFailReason::TypeNotMatch), } }