@@ -126,26 +126,6 @@ pub fn multi_param_tpl_pattern_match_multi_return(
126126 Ok ( ( ) )
127127}
128128
129- fn get_str_tpl_infer_type ( name : & str ) -> LuaType {
130- match name {
131- "unknown" => LuaType :: Unknown ,
132- "never" => LuaType :: Never ,
133- "nil" | "void" => LuaType :: Nil ,
134- "any" => LuaType :: Any ,
135- "userdata" => LuaType :: Userdata ,
136- "thread" => LuaType :: Thread ,
137- "boolean" | "bool" => LuaType :: Boolean ,
138- "string" => LuaType :: String ,
139- "integer" | "int" => LuaType :: Integer ,
140- "number" => LuaType :: Number ,
141- "io" => LuaType :: Io ,
142- "self" => LuaType :: SelfInfer ,
143- "global" => LuaType :: Global ,
144- "function" => LuaType :: Function ,
145- _ => LuaType :: Ref ( LuaTypeDeclId :: global ( & name) ) ,
146- }
147- }
148-
149129pub fn tpl_pattern_match (
150130 context : & mut TplContext ,
151131 pattern : & LuaType ,
@@ -169,11 +149,37 @@ pub fn tpl_pattern_match(
169149 let prefix = str_tpl. get_prefix ( ) ;
170150 let suffix = str_tpl. get_suffix ( ) ;
171151 let type_name = SmolStr :: new ( format ! ( "{}{}{}" , prefix, s, suffix) ) ;
172- context. substitutor . infer_type (
173- str_tpl. get_tpl_id ( ) ,
174- get_str_tpl_infer_type ( & type_name) ,
175- true ,
176- ) ;
152+ let file_id = context. cache . get_file_id ( ) ;
153+ let inferred_type = match type_name. as_str ( ) {
154+ "unknown" => LuaType :: Unknown ,
155+ "never" => LuaType :: Never ,
156+ "nil" | "void" => LuaType :: Nil ,
157+ "any" => LuaType :: Any ,
158+ "userdata" => LuaType :: Userdata ,
159+ "thread" => LuaType :: Thread ,
160+ "boolean" | "bool" => LuaType :: Boolean ,
161+ "string" => LuaType :: String ,
162+ "integer" | "int" => LuaType :: Integer ,
163+ "number" => LuaType :: Number ,
164+ "io" => LuaType :: Io ,
165+ "self" => LuaType :: SelfInfer ,
166+ "global" => LuaType :: Global ,
167+ "function" => LuaType :: Function ,
168+ _ => context
169+ . db
170+ . get_type_index ( )
171+ . find_type_decl (
172+ file_id,
173+ & type_name,
174+ context. db . resolve_workspace_id ( file_id) ,
175+ )
176+ . map ( |decl| LuaType :: Ref ( decl. get_id ( ) ) )
177+ . unwrap_or ( LuaType :: Ref ( LuaTypeDeclId :: global ( & type_name) ) ) ,
178+ } ;
179+
180+ context
181+ . substitutor
182+ . infer_type ( str_tpl. get_tpl_id ( ) , inferred_type, true ) ;
177183 }
178184 }
179185 LuaType :: Array ( array_type) => {
0 commit comments