Skip to content

Commit 641edc0

Browse files
committed
tweaks
1 parent 7dd4295 commit 641edc0

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6089,6 +6089,7 @@ public static async System.Threading.Tasks.Task<int> ProduceAsync(bool b, System
60896089
}
60906090
}
60916091
""";
6092+
// Note: nested hoisted local gets cleared when exiting nested scope normally
60926093
CompileAndVerify(src, expectedOutput: ExpectedOutput("value True"), targetFramework: TargetFramework.Net90, verify: Verification.Skipped).VerifyDiagnostics();
60936094
}
60946095

src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenIterators.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3114,7 +3114,7 @@ public static System.Collections.Generic.IEnumerable<int> M(bool b)
31143114
}
31153115
}
31163116
""";
3117-
// Note: nested hoisted local does not get cleared when exiting normally
3117+
// Note: nested hoisted local gets cleared when exiting normally
31183118
CompileAndVerify(src, expectedOutput: "42 value True").VerifyDiagnostics();
31193119
}
31203120

@@ -3323,5 +3323,52 @@ .maxstack 0
33233323
}
33243324
""");
33253325
}
3326+
3327+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75666")]
3328+
public void AddVariableCleanup_NestedUnmanagedWithGenericsLocal()
3329+
{
3330+
var src = """
3331+
using System.Reflection;
3332+
3333+
var enumerable = C.M(true, 42);
3334+
var enumerator = enumerable.GetEnumerator();
3335+
try
3336+
{
3337+
assert(enumerator.MoveNext());
3338+
System.Console.Write($"{enumerator.Current} ");
3339+
assert(!enumerator.MoveNext());
3340+
System.Console.Write(((S<int>)enumerator.GetType().GetField("<s>5__2", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(enumerator)).field);
3341+
}
3342+
finally
3343+
{
3344+
enumerator.Dispose();
3345+
}
3346+
3347+
void assert(bool b)
3348+
{
3349+
if (!b) throw new System.Exception();
3350+
}
3351+
3352+
public struct S<T> where T : unmanaged // UnmanagedWithGenerics
3353+
{
3354+
public T field;
3355+
}
3356+
3357+
public class C
3358+
{
3359+
public static System.Collections.Generic.IEnumerable<int> M<T>(bool b, T t) where T : unmanaged
3360+
{
3361+
while (b)
3362+
{
3363+
S<T> s = new S<T> { field = t };
3364+
yield return 42;
3365+
b = false;
3366+
System.Console.Write(s.field);
3367+
}
3368+
}
3369+
}
3370+
""";
3371+
CompileAndVerify(src, expectedOutput: "42 4242").VerifyDiagnostics();
3372+
}
33263373
}
33273374
}

0 commit comments

Comments
 (0)