From ac33e3657ac0d22f3ab5c9636872260717bd3418 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Wed, 4 Dec 2019 11:31:38 -0800 Subject: [PATCH 1/2] Don't crash on self-referencing attribute in nullable --- .../Portable/FlowAnalysis/NullableWalker.cs | 2 +- .../Semantics/NullableReferenceTypesTests.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index cf034a5fe6643..bbcaaeccfeea4 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -3607,7 +3607,7 @@ private ImmutableArray VisitArguments( } } - if (method is object && (method.FlowAnalysisAnnotations & FlowAnalysisAnnotations.DoesNotReturn) == FlowAnalysisAnnotations.DoesNotReturn) + if (!IsAnalyzingAttribute && method is object && (method.FlowAnalysisAnnotations & FlowAnalysisAnnotations.DoesNotReturn) == FlowAnalysisAnnotations.DoesNotReturn) { SetUnreachable(); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index d7f1ea5dd022e..5386191d28763 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -7235,6 +7235,25 @@ class C { } ); } + [Fact, WorkItem(40136, "https://github.com/dotnet/roslyn/issues/40136")] + public void SelfReferencingAttribute() + { + var source = @" +using System; + +[AttributeUsage(AttributeTargets.All)] +[ExplicitCrossPackageInternal] +internal sealed class ExplicitCrossPackageInternalAttribute : Attribute +{ + [ExplicitCrossPackageInternal] + internal ExplicitCrossPackageInternalAttribute() + { + } +}"; + var comp = CreateNullableCompilation(source); + comp.VerifyDiagnostics(); + } + [Fact] public void NullableAndConditionalOperators() { From 93435156b112b0ae172890b64ad265a2cdaed259 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 10 Dec 2019 12:31:48 -0800 Subject: [PATCH 2/2] Cover a few more self-referencing cases --- .../Semantics/NullableReferenceTypesTests.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 5386191d28763..1d7b000e33e16 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -7242,13 +7242,19 @@ public void SelfReferencingAttribute() using System; [AttributeUsage(AttributeTargets.All)] -[ExplicitCrossPackageInternal] +[ExplicitCrossPackageInternal(ExplicitCrossPackageInternalAttribute.s)] internal sealed class ExplicitCrossPackageInternalAttribute : Attribute { - [ExplicitCrossPackageInternal] - internal ExplicitCrossPackageInternalAttribute() + internal const string s = """"; + + [ExplicitCrossPackageInternal(s)] + internal ExplicitCrossPackageInternalAttribute([ExplicitCrossPackageInternal(s)] string prop) { } + + [return: ExplicitCrossPackageInternal(s)] + [ExplicitCrossPackageInternal(s)] + internal void Method() { } }"; var comp = CreateNullableCompilation(source); comp.VerifyDiagnostics();