Skip to content

IDE0004 incorrectly suggested for method with nullable result and conditional operator with default result #34509

@LeroyK

Description

@LeroyK

Version Used:
VS2019 15.9.10

Steps to Reproduce:

  1. Create the following line of code:
static long? TestParse(string val) => long.TryParse(val, out var parseResult) ? (long?)parseResult : default;

Expected Behavior:
There should not be a suggestion to remove the (long?) cast. Removing the cast will change the result type of the conditional expression to "long" instead of "long?".

Actual Behavior:
"Remove unnecessary cast" is suggested.

Might be the same issue as #29726

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions