@@ -9309,5 +9309,54 @@ static class Extension
9309
9309
Diagnostic ( ErrorCode . ERR_UseDefViolation , "i" ) . WithArguments ( "i" ) . WithLocation ( 4 , 42 )
9310
9310
) ;
9311
9311
}
9312
+
9313
+ [ Fact , WorkItem ( 59738 , "https://github.com/dotnet/roslyn/issues/59738" ) ]
9314
+ public void DefiniteAssignmentShouldSkipImplicitThisInStaticMethodConversion ( )
9315
+ {
9316
+ var comp = CreateCompilation ( @"
9317
+ using System;
9318
+ public struct C
9319
+ {
9320
+ private object field;
9321
+ public C(Action a)
9322
+ {
9323
+ // implicit `this` receiver should be ignored in definite assignment
9324
+ a = new(M);
9325
+ field = 1;
9326
+ }
9327
+
9328
+ public C(Action a, int ignored)
9329
+ {
9330
+ // implicit `this` receiver should be ignored in definite assignment
9331
+ a = new Action(M);
9332
+ field = 1;
9333
+ }
9334
+
9335
+ public void Method1(Action a)
9336
+ {
9337
+ // explicit `this` disallowed
9338
+ a = new Action(this.M);
9339
+ }
9340
+
9341
+ public void Method2(Action a, C c)
9342
+ {
9343
+ // instance receiver disallowed
9344
+ a = new Action(c.M);
9345
+ }
9346
+
9347
+ private static void M()
9348
+ {
9349
+ }
9350
+ }
9351
+ " ) ;
9352
+ comp . VerifyDiagnostics (
9353
+ // (23,24): error CS0176: Member 'C.M()' cannot be accessed with an instance reference; qualify it with a type name instead
9354
+ // a = new Action(this.M);
9355
+ Diagnostic ( ErrorCode . ERR_ObjectProhibited , "this.M" ) . WithArguments ( "C.M()" ) . WithLocation ( 23 , 24 ) ,
9356
+ // (29,24): error CS0176: Member 'C.M()' cannot be accessed with an instance reference; qualify it with a type name instead
9357
+ // a = new Action(c.M);
9358
+ Diagnostic ( ErrorCode . ERR_ObjectProhibited , "c.M" ) . WithArguments ( "C.M()" ) . WithLocation ( 29 , 24 )
9359
+ ) ;
9360
+ }
9312
9361
}
9313
9362
}
0 commit comments