Repository: VKCOM/noverify
Pull request #1002 (2021-06-29 09:16:29)

linter: added `*FromAnnotation` value for `meta.PropertyFlags` and `meta.FuncFlags`
These values are needed in order to distinguish between
methods and properties that are actually in the class and
which are defined in the annotation for the class.


Patch:
diff --git a/src/linter/cache.go b/src/linter/cache.go
index 44c1f27..a0d9c11 100644
--- a/src/linter/cache.go
+++ b/src/linter/cache.go
@@ -45,7 +45,8 @@ import (
 //     47 - forced cache version invalidation due to the #921
 //     48 - renamed meta.TypesMap to types.Map; this affects gob encoding
 //     49 - for shape, names are now generated using the keys that make up this shape
-const cacheVersion = 49
+//     50 - added Flags field for meta.PropertyInfo
+const cacheVersion = 50
 
 var (
 	errWrongVersion = errors.New("Wrong cache version")
diff --git a/src/linter/phpdoc_util.go b/src/linter/phpdoc_util.go
index efe2442..a7a2daa 100644
--- a/src/linter/phpdoc_util.go
+++ b/src/linter/phpdoc_util.go
@@ -65,6 +65,7 @@ func parseClassPHPDocMethod(ctx *rootContext, result *classPhpDocParseResult, pa
 	if static {
 		funcFlags |= meta.FuncStatic
 	}
+	funcFlags |= meta.FuncFromAnnotation
 	result.methods.Set(methodName, meta.FuncInfo{
 		Typ:          newTypesMap(ctx, types),
 		Name:         methodName,
@@ -101,6 +102,7 @@ func parseClassPHPDocProperty(ctx *rootContext, result *classPhpDocParseResult,
 	result.properties[part.Var[len("$"):]] = meta.PropertyInfo{
 		Typ:         newTypesMap(ctx, types),
 		AccessLevel: meta.Public,
+		Flags:       meta.PropFromAnnotation,
 	}
 }
 
diff --git a/src/meta/metainfo.go b/src/meta/metainfo.go
index cd4bcff..0125df6 100644
--- a/src/meta/metainfo.go
+++ b/src/meta/metainfo.go
@@ -12,6 +12,15 @@ const (
 	FuncPure
 	FuncAbstract
 	FuncFinal
+	// FuncFromAnnotation is set if the function is described in the class annotation.
+	FuncFromAnnotation
+)
+
+type PropertyFlags uint8
+
+const (
+	// PropFromAnnotation is set if the property is described in the class annotation.
+	PropFromAnnotation PropertyFlags = 1 << iota
 )
 
 type PhpDocInfo struct {
@@ -66,9 +75,10 @@ type FuncInfo struct {
 	Doc          PhpDocInfo
 }
 
-func (info *FuncInfo) IsStatic() bool   { return info.Flags&FuncStatic != 0 }
-func (info *FuncInfo) IsAbstract() bool { return info.Flags&FuncAbstract != 0 }
-func (info *FuncInfo) IsPure() bool     { return info.Flags&FuncPure != 0 }
+func (info *FuncInfo) IsStatic() bool         { return info.Flags&FuncStatic != 0 }
+func (info *FuncInfo) IsAbstract() bool       { return info.Flags&FuncAbstract != 0 }
+func (info *FuncInfo) IsPure() bool           { return info.Flags&FuncPure != 0 }
+func (info *FuncInfo) IsFromAnnotation() bool { return info.Flags&FuncFromAnnotation != 0 }
 
 type OverrideType int
 
@@ -106,8 +116,11 @@ type PropertyInfo struct {
 	Pos         ElementPosition
 	Typ         types.Map
 	AccessLevel AccessLevel
+	Flags       PropertyFlags
 }
 
+func (info *PropertyInfo) IsFromAnnotation() bool { return info.Flags&PropFromAnnotation != 0 }
+
 type ConstInfo struct {
 	Pos         ElementPosition
 	Typ         types.Map


Test patch:
diff --git a/src/linter/cache_test.go b/src/linter/cache_test.go
index 7696ed5..dde7498 100644
--- a/src/linter/cache_test.go
+++ b/src/linter/cache_test.go
@@ -141,7 +141,7 @@ main();
 		//
 		// If cache encoding changes, there is a very high chance that
 		// encoded data lengh will change as well.
-		wantLen := 5348
+		wantLen := 5358
 		haveLen := buf.Len()
 		if haveLen != wantLen {
 			t.Errorf("cache len mismatch:\nhave: %d\nwant: %d", haveLen, wantLen)
@@ -150,7 +150,7 @@ main();
 		// 2. Check cache "strings" hash.
 		//
 		// It catches new fields in cached types, field renames and encoding of additional named attributes.
-		wantStrings := "da6be70c8ce8a5df3c063b9768859727f1648d516f33fd39f0c52bb91dfee858120cbca279d9a8b9664d48c543ee98b490de2ab12b4c46ab168c459f0aaab897"
+		wantStrings := "ac764c2a270fca7341a4650318480a67cb02e1fad8c9f0036c35fade2bf2f22cae76f3de8d200a1d03581565b9e86ea9c6b18108e4f48366359b916769c141f8"
 		haveStrings := collectCacheStrings(buf.String())
 		if haveStrings != wantStrings {
 			t.Errorf("cache strings mismatch:\nhave: %q\nwant: %q", haveStrings, wantStrings)