Skip to content

Commit 6a84d6f

Browse files
committed
optimize str tpl check
1 parent c322b4b commit 6a84d6f

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

crates/emmylua_code_analysis/src/diagnostic/checker/generic/generic_constraint_mismatch.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,20 @@ fn check_call_expr(
101101

102102
match param_type {
103103
LuaType::StrTplRef(str_tpl_ref) => {
104-
check_str_tpl_ref(context, semantic_model, &call_expr, i, str_tpl_ref);
104+
let extend_type = get_extend_type(
105+
semantic_model,
106+
&call_expr,
107+
str_tpl_ref.get_tpl_id(),
108+
signature,
109+
);
110+
check_str_tpl_ref(
111+
context,
112+
semantic_model,
113+
&call_expr,
114+
i,
115+
str_tpl_ref,
116+
extend_type,
117+
);
105118
}
106119
LuaType::TplRef(tpl_ref) => {
107120
let extend_type = get_extend_type(
@@ -161,10 +174,12 @@ fn check_str_tpl_ref(
161174
call_expr: &LuaCallExpr,
162175
param_index: usize,
163176
str_tpl_ref: &LuaStringTplType,
177+
extend_type: Option<LuaType>,
164178
) -> Option<()> {
165179
let arg_expr = call_expr.get_args_list()?.get_args().nth(param_index)?;
166180
let arg_type = semantic_model.infer_expr(arg_expr.clone()).ok()?;
167181
let range = arg_expr.get_range();
182+
168183
match arg_type {
169184
LuaType::StringConst(str) | LuaType::DocStringConst(str) => {
170185
let full_type_name = format!(
@@ -185,6 +200,25 @@ fn check_str_tpl_ref(
185200
None,
186201
);
187202
}
203+
204+
if let Some(extend_type) = extend_type {
205+
if !extend_type.is_string() {
206+
if let Some(type_decl) = founded_type_decl {
207+
let type_id = type_decl.get_id();
208+
let ref_type = LuaType::Ref(type_id);
209+
let result = semantic_model.type_check(&extend_type, &ref_type);
210+
if result.is_err() {
211+
add_type_check_diagnostic(
212+
context,
213+
semantic_model,
214+
range,
215+
&extend_type,
216+
result,
217+
);
218+
}
219+
}
220+
}
221+
}
188222
}
189223
LuaType::String | LuaType::Any | LuaType::Unknown => {}
190224
_ => {

0 commit comments

Comments
 (0)