Skip to content

Commit 548aef4

Browse files
authored
Partial events and constructors: more tests (#77280)
1 parent b349c65 commit 548aef4

File tree

2 files changed

+435
-6
lines changed

2 files changed

+435
-6
lines changed

src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_WellKnownAttributes.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11311,6 +11311,45 @@ void local1()
1131111311
Assert.True(verifier.HasLocalsInit("C.<add_EventNoAttribute>g__local1|4_0"));
1131211312
}
1131311313

11314+
[Theory]
11315+
[InlineData("[SkipLocalsInit]", "")]
11316+
[InlineData("", "[SkipLocalsInit]")]
11317+
public void SkipLocalsInit_PartialEventAccessor_ContainsLocalFunction(string defAttrs, string implAttrs)
11318+
{
11319+
// SkipLocalsInit applied to either part affects the event and nested functions
11320+
var source = $$"""
11321+
using System;
11322+
using System.Runtime.CompilerServices;
11323+
11324+
public partial class C
11325+
{
11326+
{{defAttrs}}
11327+
partial event Action EventWithAttribute;
11328+
11329+
{{implAttrs}}
11330+
partial event Action EventWithAttribute
11331+
{
11332+
add
11333+
{
11334+
int w = 1;
11335+
w = w + w + w + w;
11336+
11337+
void local1()
11338+
{
11339+
int x = 1;
11340+
x = x + x + x + x;
11341+
}
11342+
}
11343+
remove { }
11344+
}
11345+
}
11346+
""";
11347+
11348+
var verifier = CompileAndVerifyWithSkipLocalsInit(source);
11349+
Assert.False(verifier.HasLocalsInit("C.EventWithAttribute.add"));
11350+
Assert.False(verifier.HasLocalsInit("C.<add_EventWithAttribute>g__local1|0_0"));
11351+
}
11352+
1131411353
[Fact]
1131511354
public void SkipLocalsInit_Class_ContainsLocalFunction()
1131611355
{

0 commit comments

Comments
 (0)