Skip to content

Commit fe57945

Browse files
committed
Fix #634
1 parent fb36f58 commit fe57945

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,18 @@ pub fn check_table_generic_type_compact(
6868
return Ok(());
6969
}
7070
}
71+
LuaType::Userdata => return Ok(()),
7172
// maybe support object
7273
// need check later
73-
LuaType::Ref(_) | LuaType::Def(_) | LuaType::Userdata => return Ok(()),
74+
LuaType::Ref(id) | LuaType::Def(id) => {
75+
let owner = LuaMemberOwner::Type(id.clone());
76+
return check_table_generic_compact_member_owner(
77+
db,
78+
source_generic_param,
79+
owner,
80+
check_guard.next_level()?,
81+
);
82+
}
7483
LuaType::Union(union) => {
7584
for union_type in union.into_vec() {
7685
check_table_generic_type_compact(

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(test)]
22
mod test {
3-
use crate::VirtualWorkspace;
3+
use crate::{DiagnosticCode, VirtualWorkspace};
44

55
#[test]
66
fn test_string() {
@@ -150,4 +150,23 @@ mod test {
150150
let ty2 = ws.expr_ty("(\"hello\"):match(\".*\")");
151151
assert!(ws.check_type(&ty, &ty2));
152152
}
153+
154+
#[test]
155+
fn test_issue_634() {
156+
let mut ws = VirtualWorkspace::new();
157+
158+
assert!(!ws.check_code_for(
159+
DiagnosticCode::ParamTypeNotMatch,
160+
r#"
161+
--- @class A
162+
--- @field a integer
163+
164+
--- @param x table<integer,string>
165+
local function foo(x) end
166+
167+
local y --- @type A
168+
foo(y) -- should error
169+
"#
170+
));
171+
}
153172
}

0 commit comments

Comments
 (0)