Skip to content

Commit

Permalink
fixed tests and updated cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Feb 14, 2025
1 parent d71a9e0 commit 34d8214
Show file tree
Hide file tree
Showing 12 changed files with 554 additions and 52 deletions.
14 changes: 7 additions & 7 deletions src/linter/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ func (b *blockWalker) checkSimpleVarNullSafety(arg ir.Node, fn meta.FuncInfo, pa
if varIsNullable && !paramAllowsNull {
b.report(arg, LevelWarning, "notNullSafety",
"not null safety call in function %s signature of variadic param %s",
fn.Name, lastParam.Name)
strings.TrimPrefix(fn.Name, "\\"), lastParam.Name)
}
return
}
Expand All @@ -1088,7 +1088,7 @@ func (b *blockWalker) checkSimpleVarNullSafety(arg ir.Node, fn meta.FuncInfo, pa
if varIsNullable && !paramAllowsNull {
b.report(arg, LevelWarning, "notNullSafety",
"not null safety call in function %s signature of param %s",
fn.Name, fn.Params[paramIndex].Name)
strings.TrimPrefix(fn.Name, "\\"), fn.Params[paramIndex].Name)
}
}

Expand All @@ -1108,7 +1108,7 @@ func (b *blockWalker) checkConstFetchNullSafety(arg ir.Node, fn meta.FuncInfo, p
if isNull && !paramAllowsNull {
b.report(arg, LevelWarning, "notNullSafety",
"null passed to non-nullable variadic parameter %s in function %s",
lastParam.Name, fn.Name)
lastParam.Name, strings.TrimPrefix(fn.Name, "\\"))
}
return
}
Expand All @@ -1118,7 +1118,7 @@ func (b *blockWalker) checkConstFetchNullSafety(arg ir.Node, fn meta.FuncInfo, p
if isNull && !paramAllowsNull {
b.report(arg, LevelWarning, "notNullSafety",
"null passed to non-nullable parameter %s in function %s",
fn.Params[paramIndex].Name, fn.Name)
fn.Params[paramIndex].Name, strings.TrimPrefix(fn.Name, "\\"))
}
}

Expand All @@ -1143,7 +1143,7 @@ func (b *blockWalker) checkArrayDimFetchNullSafety(arg ir.Node, fn meta.FuncInfo
if types.IsTypeNullable(varInfo.Type) && !paramAllowsNull {
b.report(arg, LevelWarning, "notNullSafety",
"potential null array access in variadic parameter %s of function %s",
lastParam.Name, fn.Name)
lastParam.Name, strings.TrimPrefix(fn.Name, "\\"))
}
return
}
Expand All @@ -1152,7 +1152,7 @@ func (b *blockWalker) checkArrayDimFetchNullSafety(arg ir.Node, fn meta.FuncInfo
if types.IsTypeNullable(varInfo.Type) && !paramAllowsNull {
b.report(arg, LevelWarning, "notNullSafety",
"potential null array access in parameter %s of function %s",
fn.Params[paramIndex].Name, fn.Name)
fn.Params[paramIndex].Name, strings.TrimPrefix(fn.Name, "\\"))
}
}

Expand Down Expand Up @@ -1184,7 +1184,7 @@ func (b *blockWalker) checkListExprNullSafety(arg ir.Node, fn meta.FuncInfo, par
if !types.IsTypeNullable(effectiveParam.Typ) {
b.report(arg, LevelWarning, "notNullSafety",
"potential null value in list assignment for parameter %s in function %s",
effectiveParam.Name, fn.Name)
effectiveParam.Name, strings.TrimPrefix(fn.Name, "\\"))
}
}
}
Expand Down
73 changes: 37 additions & 36 deletions src/linter/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,43 @@ import (
//
// Version log:
//
// 27 - added Static field to meta.FuncInfo
// 28 - array type parsed as mixed[]
// 29 - updated type inference for ClassConstFetch
// 30 - resolve ClassConstFetch to a wrapped type string
// 31 - fixed plus operator type inference for arrays
// 32 - replaced Static:bool with Flags:uint8 in meta.FuncInfo
// 33 - support parsing of array<k,v> and list<type>
// 34 - support parsing of ?ClassName as "ClassName|null"
// 35 - added Flags:uint8 to meta.ClassInfo
// 36 - added FuncAbstract bit to FuncFlags
// added FuncFinal bit to FuncFlags
// added ClassFinal bit to ClassFlags
// FuncInfo now stores original function name
// ClassInfo now stores original class name
// 37 - added ClassShape bit to ClassFlags
// changed meta.scopeVar bool fields representation
// 38 - replaced TypesMap.immutable:bool with flags:uint8.
// added mapPrecise flag to mark precise type maps.
// 39 - added new field Value in ConstantInfo
// 40 - changed string const value storage (no quotes)
// 41 - const-folding affected const definition values
// 42 - bool-typed consts are now stored in meta info
// 43 - define'd const values stored in cache
// 44 - rename ConstantInfo => ConstInfo
// 45 - added Mixins field to meta.ClassInfo
// 46 - changed the way of inferring the return type of functions and methods
// 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
// 50 - added Flags field for meta.PropertyInfo
// 51 - added anonymous classes
// 52 - renamed all PhpDoc and Phpdoc with PHPDoc
// 53 - added DeprecationInfo for functions and methods and support for some attributes
// 54 - forced cache version invalidation due to the #1165
// 55 - updated go version 1.16 -> 1.21
const cacheVersion = 55
// 27 - added Static field to meta.FuncInfo
// 28 - array type parsed as mixed[]
// 29 - updated type inference for ClassConstFetch
// 30 - resolve ClassConstFetch to a wrapped type string
// 31 - fixed plus operator type inference for arrays
// 32 - replaced Static:bool with Flags:uint8 in meta.FuncInfo
// 33 - support parsing of array<k,v> and list<type>
// 34 - support parsing of ?ClassName as "ClassName|null"
// 35 - added Flags:uint8 to meta.ClassInfo
// 36 - added FuncAbstract bit to FuncFlags
// added FuncFinal bit to FuncFlags
// added ClassFinal bit to ClassFlags
// FuncInfo now stores original function name
// ClassInfo now stores original class name
// 37 - added ClassShape bit to ClassFlags
// changed meta.scopeVar bool fields representation
// 38 - replaced TypesMap.immutable:bool with flags:uint8.
// added mapPrecise flag to mark precise type maps.
// 39 - added new field Value in ConstantInfo
// 40 - changed string const value storage (no quotes)
// 41 - const-folding affected const definition values
// 42 - bool-typed consts are now stored in meta info
// 43 - define'd const values stored in cache
// 44 - rename ConstantInfo => ConstInfo
// 45 - added Mixins field to meta.ClassInfo
// 46 - changed the way of inferring the return type of functions and methods
// 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
// 50 - added Flags field for meta.PropertyInfo
// 51 - added anonymous classes
// 52 - renamed all PhpDoc and Phpdoc with PHPDoc
// 53 - added DeprecationInfo for functions and methods and support for some attributes
// 54 - forced cache version invalidation due to the #1165
// 55 - updated go version 1.16 -> 1.21
// 56 - added isVariadic to meta.FuncInfo
const cacheVersion = 56

var (
errWrongVersion = errors.New("Wrong cache version")
Expand Down
4 changes: 2 additions & 2 deletions src/linter/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ main();
//
// If cache encoding changes, there is a very high chance that
// encoded data lengh will change as well.
wantLen := 5952
wantLen := 5967
haveLen := buf.Len()
if haveLen != wantLen {
t.Errorf("cache len mismatch:\nhave: %d\nwant: %d", haveLen, wantLen)
Expand All @@ -158,7 +158,7 @@ main();
// 2. Check cache "strings" hash.
//
// It catches new fields in cached types, field renames and encoding of additional named attributes.
wantStrings := "690e77c94ecdd7878de0bf6f6881d786cf1fafa4588f7905f54d700646c4952aad359008ae2dcddb1c7f29163ecee62355d525672090ac30257bc414f690006f"
wantStrings := "876ec90cb8a340db375f0f833cdb625a2a5a8560e008e111baefbad4766cc964a705c0e4f0dee76bd30a61de436986f580069c98b88b2caaed3a63a53beaae24"
haveStrings := collectCacheStrings(buf.String())
if haveStrings != wantStrings {
t.Errorf("cache strings mismatch:\nhave: %q\nwant: %q", haveStrings, wantStrings)
Expand Down
Loading

0 comments on commit 34d8214

Please sign in to comment.