S3440 misapplied to switch expressions

  • Operating system: Win 10-64
  • SonarLint plugin version:
  • Is connected mode used: No

The purpose of S3440 is to detect useless checks before assignment such as if (a != b) a = b;

I changed a code section from a switch statement to a switch expression, and S3440 appeared.

Consider this code:

var type = (previous) switch
	DataPrefixType.AlphaLower => DataPrefixType.AlphaLower,
	DataPrefixType.RomanLower => DataPrefixType.RomanLower,
	_ => DataPrefixType.AlphaOrRomanLower

The purpose is to evaluate previous to see what we should set type to. However, because the evaluation and the set are the same values, the rule is firing.

Again, when written as a switch statement, the rule does not fire.

Hey @IRC ,
You are right, this is a FP and it has been raised before.
You can track the github ticket here.

If you feel like the description and the comments do not completely cover your case, feel free to add more details there. :slight_smile:


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.