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

CA1508 False positive on Nullable DateTime #4415

Closed
langdonx opened this issue Nov 6, 2020 · 0 comments · Fixed by #4358
Closed

CA1508 False positive on Nullable DateTime #4415

langdonx opened this issue Nov 6, 2020 · 0 comments · Fixed by #4358

Comments

@langdonx
Copy link

langdonx commented Nov 6, 2020

Analyzer

Diagnostic ID: CA1508: Avoid dead conditional code

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.FxCopAnalyzers

Version: v3.3.1 (Latest)

Describe the bug

It's reporting a false positive checking that DateTime? != null:

var punchIn = (DateTime?)t.GetProperty($"SchedulePunchIn{i}Time").GetValue(dbSchedule);
var punchOut = (DateTime?)t.GetProperty($"SchedulePunchOut{i}Time").GetValue(dbSchedule);

if (punchIn != null || punchOut != null) // this line here

Steps To Reproduce

Simply write the following code:

var a = (DateTime?)DateTime.UtcNow;
if (a != null) { }

Expected behavior

It shouldn't cause a warning.

Actual behavior

It causes a warning.

Additional context

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants