@@ -4,8 +4,8 @@ use rowan::TextRange;
44use crate :: diagnostic:: checker:: generic:: infer_type:: infer_type;
55use crate :: {
66 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 ,
99} ;
1010
1111use crate :: diagnostic:: checker:: Checker ;
@@ -101,20 +101,7 @@ fn check_call_expr(
101101
102102 match param_type {
103103 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) ;
118105 }
119106 LuaType :: TplRef ( tpl_ref) => {
120107 let extend_type = get_extend_type (
@@ -173,43 +160,41 @@ fn check_str_tpl_ref(
173160 semantic_model : & SemanticModel ,
174161 call_expr : & LuaCallExpr ,
175162 param_index : usize ,
176- extend_type : & Option < LuaType > ,
177163 str_tpl_ref : & LuaStringTplType ,
178164) -> Option < ( ) > {
179- let extend_type = extend_type. clone ( ) ?;
180-
181165 let arg_expr = call_expr. get_args_list ( ) ?. get_args ( ) . nth ( param_index) ?;
182166 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 ( ) ;
190168 match arg_type {
191- LuaType :: StringConst ( str) => {
169+ LuaType :: StringConst ( str) | LuaType :: DocStringConst ( str ) => {
192170 let full_type_name = format ! (
193171 "{}{}{}" ,
194172 str_tpl_ref. get_prefix( ) ,
195173 str ,
196174 str_tpl_ref. get_suffix( )
197175 ) ;
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 ,
209186 ) ;
210187 }
211188 }
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+ }
213198 }
214199 Some ( ( ) )
215200}
0 commit comments