Skip to content

Commit 6fd49cf

Browse files
committed
update diagnostic: CastTypeMismatch
1 parent 3c589ee commit 6fd49cf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

crates/emmylua_code_analysis/src/diagnostic/checker/cast_type_mismatch.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn check_cast_compatibility(
7070
return Some(());
7171
}
7272

73-
// 检查是否可以从原始类型转换为目标类型
73+
// 检查是否可以从原始类型转换为目标类型, 允许父类转为子类
7474
let result = match origin_type {
7575
LuaType::Union(union_type) => {
7676
for member_type in union_type.into_vec() {
@@ -137,6 +137,7 @@ fn add_cast_type_mismatch_diagnostic(
137137
}
138138
}
139139

140+
/// 允许父类转为子类
140141
fn cast_type_check(
141142
semantic_model: &SemanticModel,
142143
origin_type: &LuaType,
@@ -197,8 +198,13 @@ fn cast_type_check(
197198
} else if origin_type.is_number() && target_type.is_number() {
198199
return Ok(());
199200
}
200-
201-
semantic_model.type_check_detail(target_type, origin_type)
201+
match semantic_model.type_check_detail(target_type, origin_type) {
202+
Ok(_) => Ok(()),
203+
Err(_) => match semantic_model.type_check_detail(origin_type, target_type) {
204+
Ok(_) => Ok(()),
205+
Err(reason) => Err(reason),
206+
},
207+
}
202208
}
203209
}
204210
}

0 commit comments

Comments
 (0)