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

Add null check in MatchLegacySwitchOnStringWithDict #3422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ds5678
Copy link
Contributor

@ds5678 ds5678 commented Mar 10, 2025

Updated the condition for nullValueCaseBlock to ensure it is not null and not equal to defaultBlock.

Problem

Resolves #3421

Solution

  • Any comments on the approach taken, its consistency with surrounding code, etc.
  • Which part of this PR is most in need of attention/improvement?
  • At least one test covering the code changed
    • Is a test necessary for this? If so, I'm not sure what the best way to write that test is.

Updated the condition for `nullValueCaseBlock` to ensure it is not null and not equal to `defaultBlock`.
@ds5678 ds5678 changed the title Fix null check in MatchLegacySwitchOnStringWithDict Add null check in MatchLegacySwitchOnStringWithDict Mar 10, 2025
@siegfriedpammer
Copy link
Member

Thank you very much for looking into this problem and providing a fix!

I think a test case would be nice, but is not strictly necessary. Judging from the .NET Framework version, this is code generated by the C# 2.0 compiler and I think you could only add an IL pretty test, similar to the test in your last PR.

The fix is very simple and fixing an obvious flaw, if you look at the code that handles C# 1.0 switch on string (using Hashtable), you can see that a check for Leave instructions (where the defaultBlock would be null) is present there, but not in the C# 2.0 case.

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

Successfully merging this pull request may close these issues.

Bug: null target for null switch case in legacy switch on string with dictionary
2 participants