Skip to content

Commit 5e11c9a

Browse files
committed
tests: adds a negative test for break
1 parent 3271587 commit 5e11c9a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎csharp/ql/test/query-tests/Linq/MissedWhereOpportunity/MissedWhereOpportunity.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ public int M11(IEnumerable<int> elements)
162162
return 0;
163163
}
164164

165+
public void M12(IEnumerable<int> elements)
166+
{
167+
// GOOD: The filtered case exits the loop instead of continuing with filtered loop work.
168+
foreach (var element in elements)
169+
{
170+
if (element.GetHashCode() % 2 == 0)
171+
{
172+
break;
173+
}
174+
}
175+
}
176+
165177
public class NonEnumerableClass
166178
{
167179
public IEnumerator<int> GetEnumerator() => throw null;

0 commit comments

Comments
 (0)