@@ -255,13 +255,12 @@ func (a *andWalker) handleTypeCheckCondition(expectedType string, args []ir.Node
255255 continue
256256 }
257257
258- // We need to traverse the variable here to check that
259- // it exists, since this variable will be added to the
260- // context later.
258+ // Traverse the variable to ensure it exists, since this variable
259+ // will be added to the context later
261260 a .b .handleVariable (variable )
262261
263- currentType := a . exprType ( variable )
264-
262+ // Get the current type of the variable from the appropriate context
263+ currentType := a . exprType ( variable ) // nolint:staticcheck
265264 if a .inNot {
266265 currentType = a .exprTypeInContext (a .trueContext , variable )
267266 } else {
@@ -270,27 +269,28 @@ func (a *andWalker) handleTypeCheckCondition(expectedType string, args []ir.Node
270269
271270 var trueType , falseType types.Map
272271
273- if expectedType == "bool" {
274- // we can have false/true/bool as type that's why we should check all situation
272+ switch expectedType {
273+ case "bool" :
274+ // For bool: consider possible literal types "bool", "true" and "false"
275275 boolUnion := types .NewMap ("bool" ).Union (types .NewMap ("true" )).Union (types .NewMap ("false" ))
276276 intersection := currentType .Intersect (boolUnion )
277277 if intersection .Empty () {
278278 // If there is no explicit bool subtype, then the positive branch becomes simply "bool"
279279 trueType = types .NewMap ("bool" )
280280 } else {
281- // Otherwise, we leave exactly those literals that were in the current type
281+ // Otherwise, keep exactly those literals that were present in the current type
282282 trueType = intersection
283283 }
284- // Negative branch - remove all bool subtypes
284+ // Negative branch: remove all bool subtypes
285285 falseType = currentType .Clone ().Erase ("bool" ).Erase ("true" ).Erase ("false" )
286- } else if expectedType == "object" {
287- // For is_object: keys that is not primitives
286+ case "object" :
287+ // For is_object: keep only keys that are not considered primitive
288288 keys := currentType .Keys ()
289289 var objectKeys []string
290290 for _ , k := range keys {
291291 switch k {
292292 case "int" , "float" , "string" , "bool" , "null" , "true" , "false" , "mixed" , "callable" , "resource" , "void" , "iterable" , "never" :
293- // skip not object
293+ // Skip primitive types
294294 continue
295295 default :
296296 objectKeys = append (objectKeys , k )
@@ -308,8 +308,8 @@ func (a *andWalker) handleTypeCheckCondition(expectedType string, args []ir.Node
308308 for _ , k := range objectKeys {
309309 falseType = falseType .Erase (k )
310310 }
311- } else {
312- // For other types, standard logic
311+ default :
312+ // Standard logic for other types
313313 trueType = types .NewMap (expectedType )
314314 falseType = currentType .Clone ().Erase (expectedType )
315315 }
0 commit comments