@@ -182,10 +182,10 @@ void Consume(IEnumerable<string> q) { }
182182 Consume(items.Where(x => int.Parse(x) > 0));
183183 """ ;
184184
185- var expected = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "FormatException" )
185+ var expected = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "FormatException" )
186186 . WithSpan ( 8 , 15 , 8 , 43 ) ;
187187
188- var expected2 = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "OverflowException" )
188+ var expected2 = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "OverflowException" )
189189 . WithSpan ( 8 , 15 , 8 , 43 ) ;
190190
191191 var expected3 = Verifier . Diagnostic ( CheckedExceptionsAnalyzer . DiagnosticIdImplicitlyDeclaredException )
@@ -225,10 +225,10 @@ void Consume(IEnumerable<string> q) { }
225225 . WithArguments ( "OverflowException" )
226226 . WithSpan ( 8 , 34 , 8 , 42 ) ;
227227
228- var expected3 = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "FormatException" )
228+ var expected3 = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "FormatException" )
229229 . WithSpan ( 9 , 9 , 9 , 14 ) ;
230230
231- var expected4 = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "OverflowException" )
231+ var expected4 = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "OverflowException" )
232232 . WithSpan ( 9 , 9 , 9 , 14 ) ;
233233
234234 await Verifier . VerifyAnalyzerAsync ( test , setup : o =>
@@ -237,6 +237,75 @@ await Verifier.VerifyAnalyzerAsync(test, setup: o =>
237237 } , executable : true ) ;
238238 }
239239
240+ [ Fact ]
241+ public async Task MaterializeEnumerableAsArgument ( )
242+ {
243+ var test = /* lang=c#-test */ """
244+ #nullable enable
245+ using System;
246+ using System.Collections.Generic;
247+ using System.Linq;
248+
249+ IEnumerable<string> items = [];
250+ void Consume(IEnumerable<string> q) { }
251+ var query = items.Where(x => int.Parse(x) > 0);
252+ Consume(query.ToArray());
253+ """ ;
254+
255+ var expected = Verifier . UnhandledException ( "FormatException" )
256+ . WithSpan ( 9 , 15 , 9 , 24 ) ;
257+
258+ var expected2 = Verifier . UnhandledException ( "OverflowException" )
259+ . WithSpan ( 9 , 15 , 9 , 24 ) ;
260+
261+ var expected3 = Verifier . Diagnostic ( CheckedExceptionsAnalyzer . DiagnosticIdImplicitlyDeclaredException )
262+ . WithArguments ( "FormatException" )
263+ . WithSpan ( 8 , 34 , 8 , 42 ) ;
264+
265+ var expected4 = Verifier . Diagnostic ( CheckedExceptionsAnalyzer . DiagnosticIdImplicitlyDeclaredException )
266+ . WithArguments ( "OverflowException" )
267+ . WithSpan ( 8 , 34 , 8 , 42 ) ;
268+
269+ await Verifier . VerifyAnalyzerAsync ( test , setup : o =>
270+ {
271+ o . ExpectedDiagnostics . AddRange ( expected , expected2 , expected3 , expected4 ) ;
272+ } , executable : true ) ;
273+ }
274+
275+ [ Fact ]
276+ public async Task MaterializeEnumerableInForeach ( )
277+ {
278+ var test = /* lang=c#-test */ """
279+ #nullable enable
280+ using System;
281+ using System.Collections.Generic;
282+ using System.Linq;
283+
284+ IEnumerable<string> items = [];
285+ var query = items.Where(x => int.Parse(x) > 0);
286+ foreach(var i in query.ToArray()) {}
287+ """ ;
288+
289+ var expected = Verifier . UnhandledException ( "FormatException" )
290+ . WithSpan ( 8 , 24 , 8 , 33 ) ;
291+
292+ var expected2 = Verifier . UnhandledException ( "OverflowException" )
293+ . WithSpan ( 8 , 24 , 8 , 33 ) ;
294+
295+ var expected3 = Verifier . Diagnostic ( CheckedExceptionsAnalyzer . DiagnosticIdImplicitlyDeclaredException )
296+ . WithArguments ( "FormatException" )
297+ . WithSpan ( 7 , 34 , 7 , 42 ) ;
298+
299+ var expected4 = Verifier . Diagnostic ( CheckedExceptionsAnalyzer . DiagnosticIdImplicitlyDeclaredException )
300+ . WithArguments ( "OverflowException" )
301+ . WithSpan ( 7 , 34 , 7 , 42 ) ;
302+
303+ await Verifier . VerifyAnalyzerAsync ( test , setup : o =>
304+ {
305+ o . ExpectedDiagnostics . AddRange ( expected , expected2 , expected3 , expected4 ) ;
306+ } , executable : true ) ;
307+ }
308+
240309 [ Fact ]
241310 public async Task ReturnQuery ( )
242311 {
@@ -253,10 +322,10 @@ IEnumerable<string> Get()
253322 }
254323 """ ;
255324
256- var expected = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "FormatException" )
325+ var expected = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "FormatException" )
257326 . WithSpan ( 9 , 18 , 9 , 46 ) ;
258327
259- var expected2 = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "OverflowException" )
328+ var expected2 = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "OverflowException" )
260329 . WithSpan ( 9 , 18 , 9 , 46 ) ;
261330
262331 var expected3 = Verifier . Diagnostic ( CheckedExceptionsAnalyzer . DiagnosticIdImplicitlyDeclaredException )
@@ -298,10 +367,10 @@ IEnumerable<string> Get()
298367 . WithArguments ( "OverflowException" )
299368 . WithSpan ( 9 , 38 , 9 , 46 ) ;
300369
301- var expected3 = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "FormatException" )
370+ var expected3 = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "FormatException" )
302371 . WithSpan ( 10 , 12 , 10 , 17 ) ;
303372
304- var expected4 = Verifier . UnhandledExceptionBoundary ( "IEnumerable<string>" , "OverflowException" )
373+ var expected4 = Verifier . UnhandledExceptionEnumerableBoundary ( "IEnumerable<string>" , "OverflowException" )
305374 . WithSpan ( 10 , 12 , 10 , 17 ) ;
306375
307376 await Verifier . VerifyAnalyzerAsync ( test , setup : o =>
0 commit comments