@@ -4,8 +4,8 @@ use rowan::TextRange;
4
4
use crate :: diagnostic:: checker:: generic:: infer_type:: infer_type;
5
5
use crate :: {
6
6
humanize_type, DiagnosticCode , GenericTplId , LuaMemberOwner , LuaSemanticDeclId , LuaSignature ,
7
- LuaStringTplType , LuaType , LuaTypeDeclId , RenderLevel , SemanticDeclLevel , SemanticModel ,
8
- TypeCheckFailReason , TypeCheckResult ,
7
+ LuaStringTplType , LuaType , RenderLevel , SemanticDeclLevel , SemanticModel , TypeCheckFailReason ,
8
+ TypeCheckResult ,
9
9
} ;
10
10
11
11
use crate :: diagnostic:: checker:: Checker ;
@@ -101,20 +101,7 @@ fn check_call_expr(
101
101
102
102
match param_type {
103
103
LuaType :: StrTplRef ( 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
- & extend_type,
116
- str_tpl_ref,
117
- ) ;
104
+ check_str_tpl_ref ( context, semantic_model, & call_expr, i, str_tpl_ref) ;
118
105
}
119
106
LuaType :: TplRef ( tpl_ref) => {
120
107
let extend_type = get_extend_type (
@@ -173,43 +160,41 @@ fn check_str_tpl_ref(
173
160
semantic_model : & SemanticModel ,
174
161
call_expr : & LuaCallExpr ,
175
162
param_index : usize ,
176
- extend_type : & Option < LuaType > ,
177
163
str_tpl_ref : & LuaStringTplType ,
178
164
) -> Option < ( ) > {
179
- let extend_type = extend_type. clone ( ) ?;
180
-
181
165
let arg_expr = call_expr. get_args_list ( ) ?. get_args ( ) . nth ( param_index) ?;
182
166
let arg_type = semantic_model. infer_expr ( arg_expr. clone ( ) ) . ok ( ) ?;
183
- /* 兼容 luals 的语法:
184
- ---@generic T: string
185
- ---@param name `T`
186
- */
187
- if extend_type. is_string ( ) && arg_type. is_string ( ) {
188
- return Some ( ( ) ) ;
189
- }
167
+ let range = arg_expr. get_range ( ) ;
190
168
match arg_type {
191
- LuaType :: StringConst ( str) => {
169
+ LuaType :: StringConst ( str) | LuaType :: DocStringConst ( str ) => {
192
170
let full_type_name = format ! (
193
171
"{}{}{}" ,
194
172
str_tpl_ref. get_prefix( ) ,
195
173
str ,
196
174
str_tpl_ref. get_suffix( )
197
175
) ;
198
- let result = semantic_model. type_check (
199
- & extend_type,
200
- & LuaType :: Ref ( LuaTypeDeclId :: new ( & full_type_name) ) ,
201
- ) ;
202
- if !result. is_ok ( ) {
203
- add_type_check_diagnostic (
204
- context,
205
- semantic_model,
206
- arg_expr. get_range ( ) ,
207
- & extend_type,
208
- result,
176
+ let founded_type_decl = semantic_model
177
+ . get_db ( )
178
+ . get_type_index ( )
179
+ . find_type_decl ( semantic_model. get_file_id ( ) , & full_type_name) ;
180
+ if founded_type_decl. is_none ( ) {
181
+ context. add_diagnostic (
182
+ DiagnosticCode :: GenericConstraintMismatch ,
183
+ range,
184
+ t ! ( "the string template type does not match any type declaration" ) . to_string ( ) ,
185
+ None ,
209
186
) ;
210
187
}
211
188
}
212
- _ => { }
189
+ LuaType :: String | LuaType :: Any | LuaType :: Unknown => { }
190
+ _ => {
191
+ context. add_diagnostic (
192
+ DiagnosticCode :: GenericConstraintMismatch ,
193
+ range,
194
+ t ! ( "the string template type must be a string constant" ) . to_string ( ) ,
195
+ None ,
196
+ ) ;
197
+ }
213
198
}
214
199
Some ( ( ) )
215
200
}
0 commit comments