@@ -12871,17 +12871,17 @@ static class E
12871
12871
}
12872
12872
}
12873
12873
""";
12874
- // Tracked by https://github.com/dotnet/roslyn/issues/76130 : handle conversion on receiver
12875
12874
try
12876
12875
{
12876
+ // Tracked by https://github.com/dotnet/roslyn/issues/76130 : assertion in NullableWalker
12877
12877
var comp = CreateCompilation(src);
12878
12878
CompileAndVerify(comp, expectedOutput: "42").VerifyDiagnostics();
12879
12879
}
12880
12880
catch (InvalidOperationException)
12881
12881
{
12882
12882
return;
12883
12883
}
12884
- Assert.False(true );
12884
+ Assert.True(false );
12885
12885
}
12886
12886
12887
12887
[Fact]
@@ -20926,17 +20926,8 @@ static class E
20926
20926
}
20927
20927
}
20928
20928
""";
20929
- // Tracked by https://github.com/dotnet/roslyn/issues/76130 : handle conversion on receiver
20930
- try
20931
- {
20932
- var comp = CreateCompilation(text, options: TestOptions.UnsafeReleaseExe);
20933
- CompileAndVerify(comp, expectedOutput: "pin 2", verify: Verification.Skipped).VerifyDiagnostics();
20934
- }
20935
- catch (InvalidOperationException)
20936
- {
20937
- return;
20938
- }
20939
- Assert.False(true);
20929
+ var comp = CreateCompilation(text, options: TestOptions.UnsafeReleaseExe);
20930
+ CompileAndVerify(comp, expectedOutput: "pin 2", verify: Verification.Skipped).VerifyDiagnostics();
20940
20931
}
20941
20932
20942
20933
[Fact]
@@ -22136,7 +22127,6 @@ public void ExtensionMemberLookup_Patterns()
22136
22127
{
22137
22128
var src = """
22138
22129
var c = new C();
22139
-
22140
22130
_ = c is { Property: 42 };
22141
22131
22142
22132
class C { }
@@ -22166,7 +22156,6 @@ public void ExtensionMemberLookup_Patterns_Conversion()
22166
22156
{
22167
22157
var src = """
22168
22158
var c = new C();
22169
-
22170
22159
_ = c is { Property: 42 };
22171
22160
22172
22161
class C { }
@@ -22182,17 +22171,8 @@ public int Property
22182
22171
}
22183
22172
}
22184
22173
""";
22185
- // Tracked by https://github.com/dotnet/roslyn/issues/76130 : handle conversion on receiver
22186
- try
22187
- {
22188
- var comp = CreateCompilation(src);
22189
- CompileAndVerify(comp, expectedOutput: "property").VerifyDiagnostics();
22190
- }
22191
- catch (InvalidOperationException)
22192
- {
22193
- return;
22194
- }
22195
- Assert.False(true);
22174
+ var comp = CreateCompilation(src);
22175
+ CompileAndVerify(comp, expectedOutput: "property").VerifyDiagnostics();
22196
22176
}
22197
22177
22198
22178
[Fact]
@@ -22230,6 +22210,66 @@ static class E2
22230
22210
Assert.Equal("System.Int32 E2.<>E__0.Property2 { get; }", model.GetSymbolInfo(expressionColon.Expression).Symbol.ToTestDisplayString());
22231
22211
}
22232
22212
22213
+ [Fact]
22214
+ public void ExtensionMemberLookup_Patterns_ExtendedPropertyPattern_Conversion()
22215
+ {
22216
+ var src = """
22217
+ var c = new C();
22218
+
22219
+ _ = c is { Property.Property2: 43 };
22220
+
22221
+ class C { }
22222
+
22223
+ static class E1
22224
+ {
22225
+ extension(object o)
22226
+ {
22227
+ public int Property { get { System.Console.Write("property "); return 42; } }
22228
+ }
22229
+ }
22230
+
22231
+ static class E2
22232
+ {
22233
+ extension(int i)
22234
+ {
22235
+ public int Property2 { get { System.Console.Write("property2"); return 43; } }
22236
+ }
22237
+ }
22238
+ """;
22239
+ var comp = CreateCompilation(src);
22240
+ CompileAndVerify(comp, expectedOutput: "property property2").VerifyDiagnostics();
22241
+ }
22242
+
22243
+ [Fact]
22244
+ public void ExtensionMemberLookup_Patterns_ExtendedPropertyPattern_Conversion_02()
22245
+ {
22246
+ var src = """
22247
+ var c = new C();
22248
+
22249
+ _ = c is { Property.Property2: 43 };
22250
+
22251
+ class C { }
22252
+
22253
+ static class E1
22254
+ {
22255
+ extension(C c)
22256
+ {
22257
+ public C Property { get { System.Console.Write("property "); return c; } }
22258
+ }
22259
+ }
22260
+
22261
+ static class E2
22262
+ {
22263
+ extension(object o)
22264
+ {
22265
+ public int Property2 { get { System.Console.Write("property2"); return 43; } }
22266
+ }
22267
+ }
22268
+ """;
22269
+ var comp = CreateCompilation(src);
22270
+ CompileAndVerify(comp, expectedOutput: "property property2").VerifyDiagnostics();
22271
+ }
22272
+
22233
22273
[Fact]
22234
22274
public void ExtensionMemberLookup_Patterns_ListPattern_NoInstanceLength()
22235
22275
{
@@ -22269,9 +22309,7 @@ public int Length
22269
22309
public void ExtensionMemberLookup_ObjectInitializer()
22270
22310
{
22271
22311
var src = """
22272
- /*<bind>*/
22273
22312
_ = new C() { Property = 42 };
22274
- /*</bind>*/
22275
22313
22276
22314
class C { }
22277
22315
@@ -22297,9 +22335,7 @@ static class E
22297
22335
public void ExtensionMemberLookup_ObjectInitializer_Conversion()
22298
22336
{
22299
22337
var src = """
22300
- /*<bind>*/
22301
22338
_ = new C() { Property = 42 };
22302
- /*</bind>*/
22303
22339
22304
22340
class C { }
22305
22341
@@ -22312,17 +22348,8 @@ static class E
22312
22348
}
22313
22349
""";
22314
22350
22315
- // Tracked by https://github.com/dotnet/roslyn/issues/76130 : handle conversion on receiver
22316
- try
22317
- {
22318
- var comp = CreateCompilation(src);
22319
- CompileAndVerify(comp, expectedOutput: "property").VerifyDiagnostics();
22320
- }
22321
- catch (InvalidOperationException)
22322
- {
22323
- return;
22324
- }
22325
- Assert.False(true);
22351
+ var comp = CreateCompilation(src);
22352
+ CompileAndVerify(comp, expectedOutput: "property").VerifyDiagnostics();
22326
22353
}
22327
22354
22328
22355
[Fact]
@@ -38561,15 +38588,17 @@ public class MyCollection : IEnumerable<object>
38561
38588
IEnumerator IEnumerable.GetEnumerator() => throw null!;
38562
38589
}
38563
38590
""";
38591
+ // Tracked by https://github.com/dotnet/roslyn/issues/78452 : assertion hit during nullability analysis
38564
38592
try
38565
38593
{
38566
- // Assertion tracked by https://github.com/dotnet/roslyn/issues/78452
38567
38594
comp = CreateCompilation(src);
38568
38595
comp.VerifyEmitDiagnostics();
38569
38596
}
38570
38597
catch (InvalidOperationException)
38571
38598
{
38599
+ return;
38572
38600
}
38601
+ Assert.True(false);
38573
38602
}
38574
38603
38575
38604
[Fact]
@@ -38649,17 +38678,11 @@ public object Property { set { } }
38649
38678
}
38650
38679
""";
38651
38680
38652
- // Tracked by https://github.com/dotnet/roslyn/issues/76130 : handle conversion on receiver
38653
- try
38654
- {
38655
- var comp = CreateCompilation(src);
38656
- comp.VerifyEmitDiagnostics();
38657
- }
38658
- catch (InvalidOperationException)
38659
- {
38660
- return;
38661
- }
38662
- Assert.False(true);
38681
+ var comp = CreateCompilation(src);
38682
+ comp.VerifyEmitDiagnostics(
38683
+ // (4,31): warning CS8601: Possible null reference assignment.
38684
+ // _ = new S() with { Property = oNull };
38685
+ Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "oNull").WithLocation(4, 31));
38663
38686
}
38664
38687
38665
38688
[Fact]
@@ -38685,17 +38708,11 @@ public int Property { set { } }
38685
38708
}
38686
38709
""";
38687
38710
38688
- // Tracked by https://github.com/dotnet/roslyn/issues/76130 : handle conversion on receiver
38689
- try
38690
- {
38691
- var comp = CreateCompilation(src);
38692
- comp.VerifyEmitDiagnostics();
38693
- }
38694
- catch (InvalidOperationException)
38695
- {
38696
- return;
38697
- }
38698
- Assert.False(true);
38711
+ var comp = CreateCompilation(src);
38712
+ comp.VerifyEmitDiagnostics(
38713
+ // (4,5): warning CS8602: Dereference of a possibly null reference.
38714
+ // _ = cNull with { Property = 42 };
38715
+ Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "cNull").WithLocation(4, 5));
38699
38716
}
38700
38717
38701
38718
[Fact]
@@ -38712,6 +38729,37 @@ public void Nullability_With_03()
38712
38729
38713
38730
record C { }
38714
38731
38732
+ static class E
38733
+ {
38734
+ extension(object? o)
38735
+ {
38736
+ public int Property { set { } }
38737
+ }
38738
+ }
38739
+ """;
38740
+
38741
+ // Tracked by https://github.com/dotnet/roslyn/issues/76130 : unexpected nullability warning
38742
+ var comp = CreateCompilation(src);
38743
+ comp.VerifyEmitDiagnostics(
38744
+ // (4,5): warning CS8602: Dereference of a possibly null reference.
38745
+ // _ = cNull with { Property = 42 };
38746
+ Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "cNull").WithLocation(4, 5));
38747
+ }
38748
+
38749
+ [Fact]
38750
+ public void Nullability_With_04()
38751
+ {
38752
+ var src = """
38753
+ #nullable enable
38754
+
38755
+ C? cNull = null;
38756
+ _ = cNull with { Property = 42 };
38757
+
38758
+ C cNotNull = new C();
38759
+ _ = cNotNull with { Property = 42 };
38760
+
38761
+ record C { }
38762
+
38715
38763
static class E
38716
38764
{
38717
38765
extension<T>(T t)
@@ -38729,7 +38777,7 @@ public int Property { set { } }
38729
38777
}
38730
38778
38731
38779
[Fact]
38732
- public void Nullability_With_04 ()
38780
+ public void Nullability_With_05 ()
38733
38781
{
38734
38782
var src = """
38735
38783
#nullable enable
0 commit comments