From b2715a0622a63aa438a98d5825cb985b11822305 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 13 Jan 2017 13:44:13 -0800 Subject: [PATCH] Add regression test for #16399 (#16471) * Add regression test for #16399 Closes #16399 --- .../Emit/CodeGen/CodeGenLocalFunctionTests.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs index 8e96cbc7e03..bdc75f77b8f 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs @@ -30,6 +30,58 @@ public static IMethodSymbol FindLocalFunction(this CommonTestBase.CompilationVer [CompilerTrait(CompilerFeature.LocalFunctions)] public class CodeGenLocalFunctionTests : CSharpTestBase { + [Fact] + [WorkItem(16399, "https://github.com/dotnet/roslyn/issues/16399")] + public void RecursiveGenericLocalFunctionIterator() + { + var src = @" +using System; +using System.Collections.Generic; +using System.Linq; +public static class EnumerableExtensions +{ + static void Main(string[] args) + { + GetLeaves(new List(), list => null); + + var results = GetLeaves( + new object[] { + new[] { ""a"", ""b""}, + new[] { ""c"" }, + new[] { new[] { ""d"" } } + }, node => node is string ? null : (IEnumerable)node); + + foreach (var i in results) + { + Console.WriteLine(i); + } + } + + + public static IEnumerable GetLeaves(T root, Func> getChildren) + { + return GetLeaves(root); + + IEnumerable GetLeaves(T node) + { + var children = getChildren(node); + if (children == null) + { + return new[] { node }; + } + else + { + return children.SelectMany(GetLeaves); + } + } + } +}"; + VerifyOutput(src, @"a +b +c +d"); + } + [Fact] [WorkItem(243633, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/243633")] public void CaptureGenericFieldAndParameter() -- GitLab