@@ -228,17 +228,50 @@ fn get_type_at_call_expr_by_signature_self(
228228 } ;
229229
230230 let signature_root = syntax_tree. get_chunk_node ( ) ;
231- let Some ( cast_op_type) = signature_cast. cast . to_node ( & signature_root) else {
232- return Ok ( ResultTypeOrContinue :: Continue ) ;
231+
232+ // Choose the appropriate cast based on condition_flow and whether fallback exists
233+ let result_type = match condition_flow {
234+ InferConditionFlow :: TrueCondition => {
235+ let Some ( cast_op_type) = signature_cast. cast . to_node ( & signature_root) else {
236+ return Ok ( ResultTypeOrContinue :: Continue ) ;
237+ } ;
238+ cast_type (
239+ db,
240+ signature_id. get_file_id ( ) ,
241+ cast_op_type,
242+ antecedent_type,
243+ condition_flow,
244+ ) ?
245+ }
246+ InferConditionFlow :: FalseCondition => {
247+ // Use fallback_cast if available, otherwise use the default behavior
248+ if let Some ( fallback_cast_ptr) = & signature_cast. fallback_cast {
249+ let Some ( fallback_op_type) = fallback_cast_ptr. to_node ( & signature_root) else {
250+ return Ok ( ResultTypeOrContinue :: Continue ) ;
251+ } ;
252+ cast_type (
253+ db,
254+ signature_id. get_file_id ( ) ,
255+ fallback_op_type,
256+ antecedent_type. clone ( ) ,
257+ InferConditionFlow :: TrueCondition , // Apply fallback as force cast
258+ ) ?
259+ } else {
260+ // Original behavior: remove the true type from antecedent
261+ let Some ( cast_op_type) = signature_cast. cast . to_node ( & signature_root) else {
262+ return Ok ( ResultTypeOrContinue :: Continue ) ;
263+ } ;
264+ cast_type (
265+ db,
266+ signature_id. get_file_id ( ) ,
267+ cast_op_type,
268+ antecedent_type,
269+ condition_flow,
270+ ) ?
271+ }
272+ }
233273 } ;
234274
235- let result_type = cast_type (
236- db,
237- signature_id. get_file_id ( ) ,
238- cast_op_type,
239- antecedent_type,
240- condition_flow,
241- ) ?;
242275 Ok ( ResultTypeOrContinue :: Result ( result_type) )
243276}
244277
@@ -304,17 +337,50 @@ fn get_type_at_call_expr_by_signature_param_name(
304337 } ;
305338
306339 let signature_root = syntax_tree. get_chunk_node ( ) ;
307- let Some ( cast_op_type) = signature_cast. cast . to_node ( & signature_root) else {
308- return Ok ( ResultTypeOrContinue :: Continue ) ;
340+
341+ // Choose the appropriate cast based on condition_flow and whether fallback exists
342+ let result_type = match condition_flow {
343+ InferConditionFlow :: TrueCondition => {
344+ let Some ( cast_op_type) = signature_cast. cast . to_node ( & signature_root) else {
345+ return Ok ( ResultTypeOrContinue :: Continue ) ;
346+ } ;
347+ cast_type (
348+ db,
349+ signature_id. get_file_id ( ) ,
350+ cast_op_type,
351+ antecedent_type,
352+ condition_flow,
353+ ) ?
354+ }
355+ InferConditionFlow :: FalseCondition => {
356+ // Use fallback_cast if available, otherwise use the default behavior
357+ if let Some ( fallback_cast_ptr) = & signature_cast. fallback_cast {
358+ let Some ( fallback_op_type) = fallback_cast_ptr. to_node ( & signature_root) else {
359+ return Ok ( ResultTypeOrContinue :: Continue ) ;
360+ } ;
361+ cast_type (
362+ db,
363+ signature_id. get_file_id ( ) ,
364+ fallback_op_type,
365+ antecedent_type. clone ( ) ,
366+ InferConditionFlow :: TrueCondition , // Apply fallback as force cast
367+ ) ?
368+ } else {
369+ // Original behavior: remove the true type from antecedent
370+ let Some ( cast_op_type) = signature_cast. cast . to_node ( & signature_root) else {
371+ return Ok ( ResultTypeOrContinue :: Continue ) ;
372+ } ;
373+ cast_type (
374+ db,
375+ signature_id. get_file_id ( ) ,
376+ cast_op_type,
377+ antecedent_type,
378+ condition_flow,
379+ ) ?
380+ }
381+ }
309382 } ;
310383
311- let result_type = cast_type (
312- db,
313- signature_id. get_file_id ( ) ,
314- cast_op_type,
315- antecedent_type,
316- condition_flow,
317- ) ?;
318384 Ok ( ResultTypeOrContinue :: Result ( result_type) )
319385}
320386
0 commit comments