From fa7b184e1cdc576627e5af41da559504ff060691 Mon Sep 17 00:00:00 2001 From: Richardas Kuchinskas <36065987+Hidanio@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:35:16 +0300 Subject: [PATCH] linter: fixed unboxing from null for arrays (#1215) --- src/solver/solver.go | 8 +++--- src/tests/exprtype/exprtype_test.go | 39 +++++++++++++++++++++++++++++ src/types/lazy.go | 6 ++++- src/types/map.go | 5 ++++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/solver/solver.go b/src/solver/solver.go index edb275bf7..db7a712d5 100644 --- a/src/solver/solver.go +++ b/src/solver/solver.go @@ -20,14 +20,16 @@ func mixedType() map[string]struct{} { } // resolveType resolves function calls, method calls and global variables. -// curStaticClass is current class name (if inside the class, otherwise "") +// +// curStaticClass is current class name (if inside the class, otherwise "") func resolveType(info *meta.Info, curStaticClass, typ string, visitedMap ResolverMap) (result map[string]struct{}) { r := resolver{info: info, visited: visitedMap} return r.resolveType(curStaticClass, typ) } // ResolveTypes resolves function calls, method calls and global variables. -// curStaticClass is current class name (if inside the class, otherwise "") +// +// curStaticClass is current class name (if inside the class, otherwise "") func ResolveTypes(info *meta.Info, curStaticClass string, m types.Map, visitedMap ResolverMap) map[string]struct{} { r := resolver{info: info, visited: visitedMap} return r.resolveTypes(curStaticClass, m) @@ -76,7 +78,7 @@ func (r *resolver) resolveTypeNoLateStaticBinding(class, typ string) map[string] return result } - if typ == "" || typ[0] >= types.WMax { + if types.IsAfterWMaxed(typ) { return identityType(typ) } diff --git a/src/tests/exprtype/exprtype_test.go b/src/tests/exprtype/exprtype_test.go index 6d2df4ad5..0206dee7c 100644 --- a/src/tests/exprtype/exprtype_test.go +++ b/src/tests/exprtype/exprtype_test.go @@ -2201,6 +2201,45 @@ function f() { runExprTypeTest(t, &exprTypeTestParams{code: code}) } +func TestArrayTypesWithUnpackPrimitives(t *testing.T) { + code := `= WMax +} + func FormatType(s string) (res string) { - if s == "" || s[0] >= WMax { + if IsAfterWMaxed(s) { return FormatSimpleType(s) } diff --git a/src/types/map.go b/src/types/map.go index efe2ee105..e7ba69579 100644 --- a/src/types/map.go +++ b/src/types/map.go @@ -410,6 +410,11 @@ func (m Map) LazyArrayElemType() Map { mm := make(map[string]struct{}, m.Len()) for typ := range m.m { + // TODO: https://github.com/VKCOM/noverify/issues/1227 + if IsAfterWMaxed(typ) { + break + } + if typ == "empty_array" { // If the type contains only empty_array, // then we resolve its element as mixed.