Skip to content

Commit 43907dc

Browse files
committed
refactoring
1 parent a94e225 commit 43907dc

3 files changed

Lines changed: 16 additions & 19 deletions

File tree

src/linter/and_walker.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/linter/block.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,11 +1271,8 @@ func (b *blockWalker) isTypeCompatible(varType types.Map, paramType types.Map) b
12711271
forcedVarType = types.NewMapFromMap(solver.ResolveTypes(b.r.metaInfo(), "", varType, solver.ResolverMap{}))
12721272
}
12731273
forcedParamType := types.NewMapFromMap(solver.ResolveTypes(b.r.metaInfo(), "", paramType, solver.ResolverMap{}))
1274-
if !forcedParamType.Intersect(forcedVarType).Empty() {
1275-
return true
1276-
}
12771274

1278-
return false
1275+
return !forcedParamType.Intersect(forcedVarType).Empty()
12791276
}
12801277

12811278
func (b *blockWalker) checkConstFetchSafety(arg ir.Node, fn meta.FuncInfo, paramIndex int, constExpr *ir.ConstFetchExpr, haveVariadic bool) {

src/types/predicates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var scalar = map[string]bool{
9393

9494
"true": true,
9595
"false": true,
96-
//"mixed": true,
96+
// "mixed": true,
9797
}
9898

9999
var aliases = map[string]string{

0 commit comments

Comments
 (0)