Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues 236 & 238 #239

Merged
merged 4 commits into from
Jan 30, 2015
Merged

Issues 236 & 238 #239

merged 4 commits into from
Jan 30, 2015

Conversation

thomaslevesque
Copy link
Contributor

No description provided.

…risonsTests)

Modify analyzer to handle only the case where both operands are bool.
Update unit tests accordingly.
…etric)

Modify so that analyzer and codefix also work when the operands are
reversed.
Update unit tests to cover those cases.

if (!(right.Value is bool)) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is made unnecessary by previous check - we already know that it's a bool

@giggio giggio self-assigned this Jan 30, 2015
@giggio
Copy link
Member

giggio commented Jan 30, 2015

@thomaslevesque Your update is throwing an NullReferenceException when analyzing Corefx: https://ci.appveyor.com/project/code-cracker/code-cracker/build/1.0.0.341
Run \test\CSharp\AnalyzeCoreFx.ps1 on your local machine, it will leave a temp directory with corefx and the analyzers installed and you can investigate.

// Only handle the case where both operands of type bool; other cases involve
// too much complexity to be able to deliver an accurate diagnostic confidently.
var leftType = context.SemanticModel.GetTypeInfo(comparison.Left).Type;
var rightType = context.SemanticModel.GetTypeInfo(comparison.Right).Type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leftType or rightType are null and then it is throwing the nullref.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how it's possible... If the type is unknown, TypeInfo.Type returns a IErrorTypeSymbol, not null. But perhaps it's GetTypeInfo that returns null (EDIT: actually it's not possible, since TypeInfo is a struct)... I'll investigate

@thomaslevesque
Copy link
Contributor Author

I'm unable to reproduce the error on my machine... AnalyzeCoreFx.ps1 runs without errors, and the log contains no mention of SimplifyRedundantBooleanComparisonsAnalyzer. However I noticed this in corefx.log (several times):

Target "RunCodeAnalysis" skipped, due to false condition; ('$(RunCodeAnalysisOnThisProject)'=='true') was evaluated as (''=='true').

So it looks like the analysis doesn't even run... Any idea what could cause this?

@thomaslevesque
Copy link
Contributor Author

OK, I was using the wrong MSBuild version... got the error now

@thomaslevesque
Copy link
Contributor Author

You were right, there is a case where leftType or rightType can be null: when one of the operands is the literal null. Haven't been able to narrow down the exact scenario where this happens, but it's easy to check that it isn't null. I fixed it.

@AdamSpeight2008
Copy link

Does it correctly not report in the cases where the condition is incomplete?
if( == ) or if( a == ) or if( == b) ?

@thomaslevesque
Copy link
Contributor Author

@AdamSpeight2008, good point. It correctly ignores that case; I just added a test to make sure.

@giggio
Copy link
Member

giggio commented Jan 30, 2015

giggio added a commit that referenced this pull request Jan 30, 2015
@giggio giggio merged commit e06151d into code-cracker:master Jan 30, 2015
@thomaslevesque thomaslevesque deleted the issues-236-238 branch July 24, 2015 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants