@@ -3428,6 +3428,121 @@ class C(int someParam)
34283428 Assert.Equal(@"A(""someParam"")", c.PrimaryConstructor.GetAttributes().Single().ToString());
34293429 }
34303430
3431+ [Theory]
3432+ [CombinatorialData]
3433+ [WorkItem("https://github.com/dotnet/roslyn/issues/68349")]
3434+ public void AttributesOnPrimaryConstructor_11([CombinatorialValues("class C();", "struct C();", "record C();", "record class C();", "record struct C();")] string declaration)
3435+ {
3436+ string source = @"
3437+ _ = new C();
3438+
3439+ [method: System.Obsolete(""Obsolete!!!"", error: true)]
3440+ " + declaration + @"
3441+ ";
3442+ var comp = CreateCompilation(source);
3443+ comp.VerifyDiagnostics(
3444+ // (2,5): error CS0619: 'C.C()' is obsolete: 'Obsolete!!!'
3445+ // _ = new C();
3446+ Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "new C()").WithArguments("C.C()", "Obsolete!!!").WithLocation(2, 5)
3447+ );
3448+
3449+ var c = (SourceMemberContainerTypeSymbol)comp.GetTypeByMetadataName("C");
3450+ Assert.True(c.AnyMemberHasAttributes);
3451+ }
3452+
3453+ [Theory]
3454+ [CombinatorialData]
3455+ public void AttributesOnPrimaryConstructor_12([CombinatorialValues("class", "struct", "record", "record class", "record struct")] string declaration)
3456+ {
3457+ string source = @"
3458+ _ = new C1();
3459+
3460+ partial " + declaration + @" C1();
3461+
3462+ #line 100
3463+ [method: System.Obsolete(""Obsolete!!!"", error: true)]
3464+ partial " + declaration + @" C1
3465+ #line 200
3466+ ;
3467+ ";
3468+ var comp = CreateCompilation(source);
3469+ comp.VerifyDiagnostics(
3470+ // (100,2): warning CS0657: 'method' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'type'. All attributes in this block will be ignored.
3471+ // [method: System.Obsolete("Obsolete!!!", error: true)]
3472+ Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "method").WithArguments("method", "type").WithLocation(100, 2)
3473+ );
3474+
3475+ var c1 = (SourceMemberContainerTypeSymbol)comp.GetTypeByMetadataName("C1");
3476+ Assert.False(c1.AnyMemberHasAttributes);
3477+ }
3478+
3479+ [Theory]
3480+ [CombinatorialData]
3481+ public void AttributesOnPrimaryConstructor_13([CombinatorialValues("class", "struct", "record", "record class", "record struct")] string declaration)
3482+ {
3483+ string source = @"
3484+ _ = new C1();
3485+
3486+ [method: System.Obsolete(""Obsolete!!!"", error: true)]
3487+ partial " + declaration + @" C1();
3488+
3489+ partial " + declaration + @" C1;
3490+ ";
3491+ var comp = CreateCompilation(source);
3492+ comp.VerifyDiagnostics(
3493+ // (2,5): error CS0619: 'C1.C1()' is obsolete: 'Obsolete!!!'
3494+ // _ = new C1();
3495+ Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "new C1()").WithArguments("C1.C1()", "Obsolete!!!").WithLocation(2, 5)
3496+ );
3497+
3498+ var c1 = (SourceMemberContainerTypeSymbol)comp.GetTypeByMetadataName("C1");
3499+ Assert.True(c1.AnyMemberHasAttributes);
3500+ }
3501+
3502+ [Theory]
3503+ [CombinatorialData]
3504+ [WorkItem("https://github.com/dotnet/roslyn/issues/68349")]
3505+ public void AttributesOnPrimaryConstructor_14([CombinatorialValues("class C();", "struct C();", "record C();", "record class C();", "record struct C();")] string declaration)
3506+ {
3507+ string source = @"
3508+ _ = new C();
3509+
3510+ [System.Obsolete(""Obsolete!!!"", error: true)]
3511+ " + declaration + @"
3512+ ";
3513+ var comp = CreateCompilation(source);
3514+ comp.VerifyDiagnostics(
3515+ // (2,9): error CS0619: 'C' is obsolete: 'Obsolete!!!'
3516+ // _ = new C();
3517+ Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "C").WithArguments("C", "Obsolete!!!").WithLocation(2, 9)
3518+ );
3519+
3520+ var c = (SourceMemberContainerTypeSymbol)comp.GetTypeByMetadataName("C");
3521+ Assert.False(c.AnyMemberHasAttributes);
3522+ }
3523+
3524+ [Theory]
3525+ [CombinatorialData]
3526+ [WorkItem("https://github.com/dotnet/roslyn/issues/68349")]
3527+ public void AttributesOnPrimaryConstructor_15([CombinatorialValues("class C();", "struct C();", "record C();", "record class C();", "record struct C();")] string declaration)
3528+ {
3529+ string source = @"
3530+ _ = new C();
3531+
3532+ [type: System.Obsolete(""Obsolete!!!"", error: true)]
3533+ " + declaration + @"
3534+ ";
3535+ var comp = CreateCompilation(source);
3536+ comp.VerifyDiagnostics(
3537+ // (2,9): error CS0619: 'C' is obsolete: 'Obsolete!!!'
3538+ // _ = new C();
3539+ Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "C").WithArguments("C", "Obsolete!!!").WithLocation(2, 9)
3540+ );
3541+
3542+ var c = (SourceMemberContainerTypeSymbol)comp.GetTypeByMetadataName("C");
3543+ Assert.False(c.AnyMemberHasAttributes);
3544+ }
3545+
34313546 [Fact]
34323547 public void AnalyzerActions_01_Class()
34333548 {
0 commit comments