@@ -380,6 +380,55 @@ public void Dispose()
380380 Assert . AreEqual ( false , Disposable . Ignores ( value , semanticModel , CancellationToken . None ) ) ;
381381 }
382382
383+ [ TestCase ( "new StreamReader(File.OpenRead(string.Empty))" ) ]
384+ [ TestCase ( "File.OpenRead(string.Empty).M2()" ) ]
385+ [ TestCase ( "File.OpenRead(string.Empty)?.M2()" ) ]
386+ [ TestCase ( "M2(File.OpenRead(string.Empty))" ) ]
387+ public static void ReturnedStreamWrappedInStreamReader ( string expression )
388+ {
389+ var code = @"
390+ namespace N
391+ {
392+ using System.IO;
393+
394+ public static class C
395+ {
396+ public StreamReader M1() => File.OpenRead(string.Empty).M2();
397+
398+ private static StreamReader M2(this Stream stream) => new StreamReader(stream);
399+ }
400+ }" . AssertReplace ( "File.OpenRead(string.Empty).M2()" , expression ) ;
401+ var syntaxTree = CSharpSyntaxTree . ParseText ( code ) ;
402+ var compilation = CSharpCompilation . Create ( "test" , new [ ] { syntaxTree } , MetadataReferences . FromAttributes ( ) ) ;
403+ var semanticModel = compilation . GetSemanticModel ( syntaxTree ) ;
404+ var value = syntaxTree . FindExpression ( "File.OpenRead(string.Empty)" ) ;
405+ Assert . AreEqual ( false , Disposable . Ignores ( value , semanticModel , CancellationToken . None ) ) ;
406+ }
407+
408+ [ TestCase ( "await File.OpenRead(string.Empty).ReadAsync(null, 0, 0)" ) ]
409+ [ TestCase ( "await File.OpenRead(string.Empty)?.ReadAsync(null, 0, 0)" ) ]
410+ [ TestCase ( "File.OpenRead(string.Empty).ReadAsync(null, 0, 0)" ) ]
411+ [ TestCase ( "File.OpenRead(string.Empty)?.ReadAsync(null, 0, 0)" ) ]
412+ public static void FileOpenReadReadAsync ( string expression )
413+ {
414+ var code = @"
415+ namespace N
416+ {
417+ using System.IO;
418+ using System.Threading.Tasks;
419+
420+ public class C
421+ {
422+ public async Task<int> M() => await File.OpenRead(string.Empty).ReadAsync(null, 0, 0);
423+ }
424+ }" . AssertReplace ( "await File.OpenRead(string.Empty).ReadAsync(null, 0, 0)" , expression ) ;
425+ var syntaxTree = CSharpSyntaxTree . ParseText ( code ) ;
426+ var compilation = CSharpCompilation . Create ( "test" , new [ ] { syntaxTree } , MetadataReferences . FromAttributes ( ) ) ;
427+ var semanticModel = compilation . GetSemanticModel ( syntaxTree ) ;
428+ var value = syntaxTree . FindExpression ( "File.OpenRead(string.Empty)" ) ;
429+ Assert . AreEqual ( true , Disposable . Ignores ( value , semanticModel , CancellationToken . None ) ) ;
430+ }
431+
383432 [ TestCase ( "new CompositeDisposable(File.OpenRead(fileName))" ) ]
384433 [ TestCase ( "new CompositeDisposable { File.OpenRead(fileName) }" ) ]
385434 public static void ReturnedInCompositeDisposable ( string expression )
0 commit comments