Skip to content

Commit e8856fe

Browse files
committed
update type_check
1 parent b59b7e5 commit e8856fe

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-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
@@ -1089,4 +1089,27 @@ mod test {
10891089
"#
10901090
));
10911091
}
1092+
1093+
#[test]
1094+
fn test_super_type_match() {
1095+
let mut ws = VirtualWorkspace::new_with_init_std_lib();
1096+
assert!(ws.check_code_for(
1097+
DiagnosticCode::ParamTypeNotMatch,
1098+
r#"
1099+
---@class UnitKey: integer
1100+
1101+
---@alias IdAlias
1102+
---| 10101
1103+
1104+
---@param key IdAlias
1105+
local function get(key)
1106+
end
1107+
1108+
---@type UnitKey
1109+
local key
1110+
1111+
get(key)
1112+
"#
1113+
));
1114+
}
10921115
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ pub fn check_simple_type_compact(
143143

144144
return Err(TypeCheckFailReason::TypeNotMatch);
145145
}
146+
LuaType::Ref(_) => {
147+
match check_base_type_for_ref_compact(db, source, compact_type, check_guard) {
148+
Ok(_) => return Ok(()),
149+
Err(err) if err.is_type_not_match() => {}
150+
Err(err) => return Err(err),
151+
}
152+
}
146153
_ => {}
147154
},
148155
LuaType::DocStringConst(s) => match compact_type {
@@ -161,6 +168,13 @@ pub fn check_simple_type_compact(
161168

162169
return Err(TypeCheckFailReason::TypeNotMatch);
163170
}
171+
LuaType::Ref(_) => {
172+
match check_base_type_for_ref_compact(db, source, compact_type, check_guard) {
173+
Ok(_) => return Ok(()),
174+
Err(err) if err.is_type_not_match() => {}
175+
Err(err) => return Err(err),
176+
}
177+
}
164178
_ => {}
165179
},
166180
LuaType::DocBooleanConst(b) => match compact_type {
@@ -242,6 +256,7 @@ fn get_alias_real_type<'a>(
242256
Ok(compact_type)
243257
}
244258

259+
/// 检查基础类型是否匹配自定义类型
245260
fn check_base_type_for_ref_compact(
246261
db: &DbIndex,
247262
source: &LuaType,

0 commit comments

Comments
 (0)