Skip to content

Commit

Permalink
NET-931 Repro for FP S1172: Captured parameter in switch or switch ex…
Browse files Browse the repository at this point in the history
…pression in a local function
  • Loading branch information
martin-strecker-sonarsource authored and sonartech committed Jan 7, 2025
1 parent 6931063 commit 56e87ce
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,31 @@ public static void Main()
}
}
}

namespace ReproCaptureInLocalFunction
{
internal static class Test
{
// https://community.sonarsource.com/t/132900
private static string CaptureInSwitchExression(string currentUnit) // Noncompliant FP
{
return GetLongUnit();

string GetLongUnit()
{
return currentUnit switch
{
"M" => "Meters",
_ => "Yards"
};
}
}

private static string CaptureSimple(string text) // Compliant
{
return UpperCase();

string UpperCase() => text.ToUpper();
}
}
}

0 comments on commit 56e87ce

Please sign in to comment.