nil-compare: detect typed nil conversions#299
Open
mmorel-35 wants to merge 1 commit intoAntonboom:masterfrom
Open
nil-compare: detect typed nil conversions#299mmorel-35 wants to merge 1 commit intoAntonboom:masterfrom
mmorel-35 wants to merge 1 commit intoAntonboom:masterfrom
Conversation
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
nil-comparechecker failed to recognise typed nil conversions such as(*tls.Config)(nil),[]MailserverTopic(nil),[]base.DiskFileNum(nil)as nil values, so patterns like the following went undetected:nil-compareisTypedNil(pass, expr)usingpass.TypesInfo.Types[ce.Fun].IsType()to detect anyT(nil)type-conversion expression.xorNil(now accepts*analysis.Pass) to match both untypedniland typed nil via the newisNilExprhelper.expected-actualisExpectedValueCandidatepreviously treated(T)(nil)as an expected-value candidate viaisParenExpr, causing false-positive "reverse arguments" diagnostics for comparison functions.Equal,EqualValues,Exactly,NotEqual,NotEqualValuesetc., typed nil is now excluded from the expected-value heuristic —nil-compareowns those cases.IsType/IsNotTypeare unaffected;(*T)(nil)as a type witness continues to be recognised correctly.Tests
gen_nil_compare.go: replaced the inertUnsupportedAssertionsblock withTypedNilAssertionscarrying full report/proposed-fix metadata; both left- and right-side typed nil variants are covered for all five affected functions.gen_expected_actual.go: added ignored-assertion entries confirming typed nil in comparison functions does not triggerexpected-actual.Closes #222