Skip to content

Commit 2391a32

Browse files
committed
fix type check: 两个 function 的第一个参数均为self时允许匹配
1 parent 06f27c2 commit 2391a32

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,4 +897,27 @@ mod test {
897897
"#
898898
));
899899
}
900+
901+
#[test]
902+
fn test_function_self() {
903+
let mut ws = VirtualWorkspace::new();
904+
assert!(ws.check_code_for(
905+
DiagnosticCode::ParamTypeNotMatch,
906+
r#"
907+
---@class D23.A
908+
909+
---@generic Extends: string
910+
---@param init? fun(self: self, super: Extends)
911+
local function extends(init)
912+
end
913+
914+
---@generic Super: string
915+
---@param super? `Super`
916+
---@param superInit? fun(self: D23.A, super: Super, ...)
917+
local function declare(super, superInit)
918+
extends(superInit)
919+
end
920+
"#
921+
));
922+
}
900923
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ fn check_doc_func_type_compact_for_params(
9999
)
100100
.is_err()
101101
{
102+
if i == 0 && source_type.is_self_infer() && compact_param.0 == "self" {
103+
continue;
104+
}
102105
// add error message
103106
return Err(TypeCheckFailReason::TypeNotMatch);
104107
}

0 commit comments

Comments
 (0)