From 9c99cbceb46612bc2012c2457ddd29db858201dd Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Sun, 14 Feb 2021 14:21:27 +0200 Subject: [PATCH 01/11] Fix Function Pointer Display --- .../SymbolDisplayVisitor.Members.cs | 6 ++++-- .../SymbolDisplay/SymbolDisplayTests.cs | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index f1054f88d38d8..74799c35e8584 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -678,9 +678,11 @@ public override void VisitParameter(IParameterSymbol symbol) // (e.g. field types, param types, etc), which just want the name whereas parameters are // used on their own or in the context of methods. - var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType); + var isFunctionPointerParameter = symbol.ContainingSymbol is IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }; + var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType) + || isFunctionPointerParameter; var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) - && !(symbol.ContainingSymbol is IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }); + && !isFunctionPointerParameter; var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); if (includeBrackets && symbol.IsOptional) diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs index fc02ac1554f7a..6ef0ab9ccf5d6 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs @@ -7652,5 +7652,26 @@ record Person(string First, string Last); SymbolDisplayPartKind.Space, SymbolDisplayPartKind.RecordClassName); } + + [Fact()] + public void TestFunctionPointerWithoutIncludeTypesInParameterOptions() + { + var text = @" +class A { + delegate* f; +}"; + + Func findSymbol = global => + ((FieldSymbol)global.GetTypeMembers("A", 0).Single() + .GetMembers("f").Single()).Type; + + var format = new SymbolDisplayFormat(); + + TestSymbolDescription( + text, + findSymbol, + format, + "delegate*"); + } } } From a3f324d153933b2fcbd5da3c008ee5baa182e6db Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Sun, 14 Feb 2021 16:00:14 +0200 Subject: [PATCH 02/11] SignatureOnlyParameterSymbol.ContainingSymbol throws --- .../Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index 74799c35e8584..f2e9c1701fbc5 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -678,7 +678,9 @@ public override void VisitParameter(IParameterSymbol symbol) // (e.g. field types, param types, etc), which just want the name whereas parameters are // used on their own or in the context of methods. - var isFunctionPointerParameter = symbol.ContainingSymbol is IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }; + // SignatureOnlyParameterSymbol.ContainingSymbol throws. + var isFunctionPointerParameter = symbol is not Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.Symbol { UnderlyingSymbol: SignatureOnlyParameterSymbol } + && symbol.ContainingSymbol is IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }; var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType) || isFunctionPointerParameter; var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) From ad7ddea1fdb3d4db1b4d18da8de43cb88fc7cf60 Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Sun, 14 Feb 2021 17:24:47 +0200 Subject: [PATCH 03/11] Fix broken test --- .../Test/Semantic/Semantics/NullableReferenceTypesTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 73abb30737811..fdf78667a9919 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -141900,9 +141900,9 @@ static void M(delegate* ptr1, delegate* ptr2) // (7,15): warning CS8600: Converting null literal or possible null value to non-nullable type. // T t = default; Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "default").WithLocation(7, 15), - // (8,14): warning CS8604: Possible null reference argument for parameter '' in 'delegate*'. + // (8,14): warning CS8604: Possible null reference argument for parameter 'T' in 'delegate*'. // ptr1(t); - Diagnostic(ErrorCode.WRN_NullReferenceArgument, "t").WithArguments("", "delegate*").WithLocation(8, 14), + Diagnostic(ErrorCode.WRN_NullReferenceArgument, "t").WithArguments("T", "delegate*").WithLocation(8, 14), // (9,9): warning CS8602: Dereference of a possibly null reference. // ptr2().ToString(); Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "ptr2()").WithLocation(9, 9) From 04b0378bd1d653615c0f43a78f6bab3e10ef57bf Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Thu, 18 Feb 2021 17:07:02 +0200 Subject: [PATCH 04/11] Changes based on review by @alekseyts and @333fred --- .../SymbolDisplayVisitor.Members.cs | 20 ++++++--- .../Semantics/NullableReferenceTypesTests.cs | 4 +- .../SymbolDisplay/SymbolDisplayTests.cs | 44 ++++++++++++++++++- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index f2e9c1701fbc5..3497ba3127777 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -609,7 +609,14 @@ void visitFunctionPointerSignature(IMethodSymbol symbol) foreach (var param in symbol.Parameters) { - param.Accept(this.NotFirstVisitor); + AddParameterRefKindIfRequired(param.RefKind); + + AddCustomModifiersIfRequired(param.RefCustomModifiers); + + param.Type.Accept(this.NotFirstVisitor); + + AddCustomModifiersIfRequired(param.CustomModifiers, leadingSpace: true, trailingSpace: false); + AddPunctuation(SyntaxKind.CommaToken); AddSpace(); } @@ -678,13 +685,12 @@ public override void VisitParameter(IParameterSymbol symbol) // (e.g. field types, param types, etc), which just want the name whereas parameters are // used on their own or in the context of methods. - // SignatureOnlyParameterSymbol.ContainingSymbol throws. - var isFunctionPointerParameter = symbol is not Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.Symbol { UnderlyingSymbol: SignatureOnlyParameterSymbol } - && symbol.ContainingSymbol is IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }; - var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType) - || isFunctionPointerParameter; + + var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType); + var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) - && !isFunctionPointerParameter; + && symbol.Name.Length != 0; + var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); if (includeBrackets && symbol.IsOptional) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index fdf78667a9919..73abb30737811 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -141900,9 +141900,9 @@ static void M(delegate* ptr1, delegate* ptr2) // (7,15): warning CS8600: Converting null literal or possible null value to non-nullable type. // T t = default; Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "default").WithLocation(7, 15), - // (8,14): warning CS8604: Possible null reference argument for parameter 'T' in 'delegate*'. + // (8,14): warning CS8604: Possible null reference argument for parameter '' in 'delegate*'. // ptr1(t); - Diagnostic(ErrorCode.WRN_NullReferenceArgument, "t").WithArguments("T", "delegate*").WithLocation(8, 14), + Diagnostic(ErrorCode.WRN_NullReferenceArgument, "t").WithArguments("", "delegate*").WithLocation(8, 14), // (9,9): warning CS8602: Dereference of a possibly null reference. // ptr2().ToString(); Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "ptr2()").WithLocation(9, 9) diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs index 6ef0ab9ccf5d6..ec9fdd4b2be38 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs @@ -7653,7 +7653,7 @@ record Person(string First, string Last); SymbolDisplayPartKind.RecordClassName); } - [Fact()] + [Fact, WorkItem(51222, "https://github.com/dotnet/roslyn/issues/51222")] public void TestFunctionPointerWithoutIncludeTypesInParameterOptions() { var text = @" @@ -7673,5 +7673,47 @@ class A { format, "delegate*"); } + + [Fact, WorkItem(51222, "https://github.com/dotnet/roslyn/issues/51222")] + public void TestFunctionPointerWithTupleParameter() + { + var text = @" +class A { + delegate*<(int, string), void> f; +}"; + + Func findSymbol = global => + ((FieldSymbol)global.GetTypeMembers("A", 0).Single() + .GetMembers("f").Single()).Type; + + var format = new SymbolDisplayFormat(); + + TestSymbolDescription( + text, + findSymbol, + format, + "delegate*<(Int32, String), Void>"); + } + + [Fact, WorkItem(51222, "https://github.com/dotnet/roslyn/issues/51222")] + public void TestFunctionPointerWithTupleParameterWithNames() + { + var text = @" +class A { + delegate*<(int i, string s), (int i, string s)> f; +}"; + + Func findSymbol = global => + ((FieldSymbol)global.GetTypeMembers("A", 0).Single() + .GetMembers("f").Single()).Type; + + var format = new SymbolDisplayFormat(); + + TestSymbolDescription( + text, + findSymbol, + format, + "delegate*<(Int32 i, String s), (Int32 i, String s)>"); + } } } From ef0d6cc8e4ec391845cfddf5b764d21d9acba271 Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Thu, 18 Feb 2021 17:41:40 +0200 Subject: [PATCH 05/11] don't check for function pointer at all in SymbolDisplayVisitor.VisitParameter as they should be handled seperately --- .../Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index 3497ba3127777..d548ea85fe601 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -688,8 +688,7 @@ public override void VisitParameter(IParameterSymbol symbol) var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType); - var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) - && symbol.Name.Length != 0; + var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName); var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); From d31a3dc05cdc2bff8780b90ca93e4b86606ffb1b Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Thu, 11 Mar 2021 08:19:50 +0200 Subject: [PATCH 06/11] Fix broken tests, and address feedback from @AlekseyTs --- .../SymbolDisplayVisitor.Members.cs | 45 +++++++++++-------- .../SymbolDisplay/SymbolDisplayTests.cs | 42 +++++++++++++++++ 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index d548ea85fe601..8948541bfedf8 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -609,7 +609,10 @@ void visitFunctionPointerSignature(IMethodSymbol symbol) foreach (var param in symbol.Parameters) { - AddParameterRefKindIfRequired(param.RefKind); + if (format.MemberOptions.IncludesOption(SymbolDisplayMemberOptions.IncludeRef)) + { + AddParameterRefKind(param.RefKind); + } AddCustomModifiersIfRequired(param.RefCustomModifiers); @@ -685,10 +688,11 @@ public override void VisitParameter(IParameterSymbol symbol) // (e.g. field types, param types, etc), which just want the name whereas parameters are // used on their own or in the context of methods. - var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType); - var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName); + var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) + && (symbol is Symbols.PublicModel.Symbol { UnderlyingSymbol: SignatureOnlyParameterSymbol } // SignatureOnlyParameterSymbol.ContainingSymbol throws NotSupportedException + || symbol.ContainingSymbol is not IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }); var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); @@ -976,21 +980,26 @@ private void AddParameterRefKindIfRequired(RefKind refKind) { if (format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeParamsRefOut)) { - switch (refKind) - { - case RefKind.Out: - AddKeyword(SyntaxKind.OutKeyword); - AddSpace(); - break; - case RefKind.Ref: - AddKeyword(SyntaxKind.RefKeyword); - AddSpace(); - break; - case RefKind.In: - AddKeyword(SyntaxKind.InKeyword); - AddSpace(); - break; - } + AddParameterRefKind(refKind); + } + } + + private void AddParameterRefKind(RefKind refKind) + { + switch (refKind) + { + case RefKind.Out: + AddKeyword(SyntaxKind.OutKeyword); + AddSpace(); + break; + case RefKind.Ref: + AddKeyword(SyntaxKind.RefKeyword); + AddSpace(); + break; + case RefKind.In: + AddKeyword(SyntaxKind.InKeyword); + AddSpace(); + break; } } } diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs index ec9fdd4b2be38..f12fcf5308d8d 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs @@ -7715,5 +7715,47 @@ class A { format, "delegate*<(Int32 i, String s), (Int32 i, String s)>"); } + + [Fact, WorkItem(51222, "https://github.com/dotnet/roslyn/issues/51222")] + public void TestFunctionPointerWithRefParametersAndIncludeParameterRefOut() + { + var text = @" +class A { + delegate* f; +}"; + + Func findSymbol = global => + ((FieldSymbol)global.GetTypeMembers("A", 0).Single() + .GetMembers("f").Single()).Type; + + var format = new SymbolDisplayFormat(parameterOptions: SymbolDisplayParameterOptions.IncludeParamsRefOut); + + TestSymbolDescription( + text, + findSymbol, + format, + "delegate*"); + } + + [Fact, WorkItem(51222, "https://github.com/dotnet/roslyn/issues/51222")] + public void TestFunctionPointerWithRefParametersAndIncludeRef() + { + var text = @" +class A { + delegate* f; +}"; + + Func findSymbol = global => + ((FieldSymbol)global.GetTypeMembers("A", 0).Single() + .GetMembers("f").Single()).Type; + + var format = new SymbolDisplayFormat(memberOptions: SymbolDisplayMemberOptions.IncludeRef); + + TestSymbolDescription( + text, + findSymbol, + format, + "delegate*"); + } } } From cfbe45c32deddbb82a9a2b0b8ff1478dff220c11 Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Thu, 11 Mar 2021 17:24:04 +0200 Subject: [PATCH 07/11] check for empty name instead of function pointer symbol in VisitParameter --- .../SymbolDisplayVisitor.Members.cs | 35 ++++++++++--------- .../Test/Semantic/Semantics/RecordTests.cs | 14 ++++---- .../SemanticModelGetDeclaredSymbolAPITests.cs | 6 ++-- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index 8948541bfedf8..eb47f24ecc6ec 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -689,12 +689,13 @@ public override void VisitParameter(IParameterSymbol symbol) // used on their own or in the context of methods. var includeType = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeType); - - var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) - && (symbol is Symbols.PublicModel.Symbol { UnderlyingSymbol: SignatureOnlyParameterSymbol } // SignatureOnlyParameterSymbol.ContainingSymbol throws NotSupportedException - || symbol.ContainingSymbol is not IMethodSymbol { MethodKind: MethodKind.FunctionPointerSignature }); - + var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && + symbol.Name.Length != 0; var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); + var includeOption = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && + format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && + symbol.HasExplicitDefaultValue && + CanAddConstant(symbol.Type, symbol.ExplicitDefaultValue); if (includeBrackets && symbol.IsOptional) { @@ -716,26 +717,26 @@ public override void VisitParameter(IParameterSymbol symbol) AddCustomModifiersIfRequired(symbol.CustomModifiers, leadingSpace: true, trailingSpace: false); } - if (includeName && includeType) - { - AddSpace(); - } - if (includeName) { + if (includeType) + { + AddSpace(); + } var kind = symbol.IsThis ? SymbolDisplayPartKind.Keyword : SymbolDisplayPartKind.ParameterName; builder.Add(CreatePart(kind, symbol, symbol.Name)); + } - if (format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && - symbol.HasExplicitDefaultValue && - CanAddConstant(symbol.Type, symbol.ExplicitDefaultValue)) + if (includeOption) + { + if (includeName || includeType) { AddSpace(); - AddPunctuation(SyntaxKind.EqualsToken); - AddSpace(); - - AddConstantValue(symbol.Type, symbol.ExplicitDefaultValue); } + AddPunctuation(SyntaxKind.EqualsToken); + AddSpace(); + + AddConstantValue(symbol.Type, symbol.ExplicitDefaultValue); } if (includeBrackets && symbol.IsOptional) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs index b8c845e22a62b..322aacfc6e9e0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs @@ -415,11 +415,11 @@ public record A(int i,) { } AssertEx.Equal(expectedMembers, comp.GetMember("A").GetMembers().OfType().ToTestDisplayStrings()); - AssertEx.Equal(new[] { "A..ctor(System.Int32 i, ? )", "A..ctor(A original)" }, + AssertEx.Equal(new[] { "A..ctor(System.Int32 i, ?)", "A..ctor(A original)" }, comp.GetMember("A").Constructors.ToTestDisplayStrings()); var primaryCtor = comp.GetMember("A").Constructors.First(); - Assert.Equal("A..ctor(System.Int32 i, ? )", primaryCtor.ToTestDisplayString()); + Assert.Equal("A..ctor(System.Int32 i, ?)", primaryCtor.ToTestDisplayString()); Assert.IsType(primaryCtor.Parameters[1].DeclaringSyntaxReferences.Single().GetSyntax()); } @@ -451,7 +451,7 @@ public record A(int i, // A ); var primaryCtor = comp.GetMember("A").Constructors.First(); - Assert.Equal("A..ctor(System.Int32 i, ? , ? )", primaryCtor.ToTestDisplayString()); + Assert.Equal("A..ctor(System.Int32 i, ?, ?)", primaryCtor.ToTestDisplayString()); Assert.IsType(primaryCtor.Parameters[0].DeclaringSyntaxReferences.Single().GetSyntax()); Assert.IsType(primaryCtor.Parameters[1].DeclaringSyntaxReferences.Single().GetSyntax()); Assert.IsType(primaryCtor.Parameters[2].DeclaringSyntaxReferences.Single().GetSyntax()); @@ -477,7 +477,7 @@ public class C ); var ctor = comp.GetMember("C").Constructors.Single(); - Assert.Equal("C..ctor(System.Int32 i, ? )", ctor.ToTestDisplayString()); + Assert.Equal("C..ctor(System.Int32 i, ?)", ctor.ToTestDisplayString()); Assert.IsType(ctor.Parameters[1].DeclaringSyntaxReferences.Single().GetSyntax()); Assert.Equal(0, ctor.Parameters[1].Locations.Single().SourceSpan.Length); } @@ -505,7 +505,7 @@ public record A(int i, int ) { } comp.GetMember("A").GetMembers().OfType().ToTestDisplayStrings()); var ctor = comp.GetMember("A").Constructors[0]; - Assert.Equal("A..ctor(System.Int32 i, System.Int32 )", ctor.ToTestDisplayString()); + Assert.Equal("A..ctor(System.Int32 i, System.Int32)", ctor.ToTestDisplayString()); Assert.IsType(ctor.Parameters[1].DeclaringSyntaxReferences.Single().GetSyntax()); Assert.Equal(0, ctor.Parameters[1].Locations.Single().SourceSpan.Length); } @@ -538,7 +538,7 @@ public record A(int, string ) { } AssertEx.Equal(expectedMembers, comp.GetMember("A").GetMembers().OfType().ToTestDisplayStrings()); - AssertEx.Equal(new[] { "A..ctor(System.Int32 , System.String )", "A..ctor(A original)" }, + AssertEx.Equal(new[] { "A..ctor(System.Int32, System.String)", "A..ctor(A original)" }, comp.GetMember("A").Constructors.ToTestDisplayStrings()); Assert.IsType(comp.GetMember("A").Constructors[0].Parameters[1].DeclaringSyntaxReferences.Single().GetSyntax()); @@ -572,7 +572,7 @@ public record A(int, int ) { } AssertEx.Equal(expectedMembers, comp.GetMember("A").GetMembers().OfType().ToTestDisplayStrings()); - AssertEx.Equal(new[] { "A..ctor(System.Int32 , System.Int32 )", "A..ctor(A original)" }, + AssertEx.Equal(new[] { "A..ctor(System.Int32, System.Int32)", "A..ctor(A original)" }, comp.GetMember("A").Constructors.ToTestDisplayStrings()); Assert.IsType(comp.GetMember("A").Constructors[0].Parameters[1].DeclaringSyntaxReferences.Single().GetSyntax()); diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs index 9b075d9bc169d..4ecf331944c5e 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs @@ -5223,7 +5223,7 @@ static void F(int x = 2, = 3) { } var model = comp.GetSemanticModel(tree); var decls = tree.GetCompilationUnitRoot().DescendantNodes().OfType().ToArray(); var symbol1 = VerifyParameter(model, decls[0], 0, "[System.Int32 x = 2]", "System.Int32", 2); - var symbol2 = VerifyParameter(model, decls[1], 1, "[? = null]", "System.Int32", 3); + var symbol2 = VerifyParameter(model, decls[1], 1, "[? = null]", "System.Int32", 3); Assert.Same(symbol1.ContainingSymbol, symbol2.ContainingSymbol); } @@ -5244,7 +5244,7 @@ void F(int x, = 3) { } var model = comp.GetSemanticModel(tree); var decls = tree.GetCompilationUnitRoot().DescendantNodes().OfType().ToArray(); var symbol1 = VerifyParameter(model, decls[0], 0, "System.Int32 x", null, null); - var symbol2 = VerifyParameter(model, decls[1], 1, "[? = null]", "System.Int32", 3); + var symbol2 = VerifyParameter(model, decls[1], 1, "[? = null]", "System.Int32", 3); Assert.Same(symbol1.ContainingSymbol, symbol2.ContainingSymbol); } @@ -5265,7 +5265,7 @@ void F(int x = 2, = 3) { } var model = comp.GetSemanticModel(tree); var decls = tree.GetCompilationUnitRoot().DescendantNodes().OfType().ToArray(); var symbol1 = VerifyParameter(model, decls[0], 0, "[System.Int32 x = 2]", "System.Int32", 2); - var symbol2 = VerifyParameter(model, decls[1], 1, "[? = null]", "System.Int32", 3); + var symbol2 = VerifyParameter(model, decls[1], 1, "[? = null]", "System.Int32", 3); Assert.Same(symbol1.ContainingSymbol, symbol2.ContainingSymbol); } From 9799b7d7bb67e3375426f0cf4064affa399f74e1 Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Thu, 11 Mar 2021 17:44:41 +0200 Subject: [PATCH 08/11] rename variable from includeOption to includeDefaultValue --- .../Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index eb47f24ecc6ec..c75ec0e31470e 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -692,7 +692,7 @@ public override void VisitParameter(IParameterSymbol symbol) var includeName = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && symbol.Name.Length != 0; var includeBrackets = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeOptionalBrackets); - var includeOption = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && + var includeDefaultValue = format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeDefaultValue) && format.ParameterOptions.IncludesOption(SymbolDisplayParameterOptions.IncludeName) && symbol.HasExplicitDefaultValue && CanAddConstant(symbol.Type, symbol.ExplicitDefaultValue); @@ -727,7 +727,7 @@ public override void VisitParameter(IParameterSymbol symbol) builder.Add(CreatePart(kind, symbol, symbol.Name)); } - if (includeOption) + if (includeDefaultValue) { if (includeName || includeType) { From 6f6e883d0b16e8c5f8f64aa644066704e4712306 Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Mon, 15 Mar 2021 20:54:34 +0200 Subject: [PATCH 09/11] unconditionally display ref kinds for function pointers --- .../SymbolDisplayVisitor.Members.cs | 31 ++++++----- .../CodeGen/CodeGenFunctionPointersTests.cs | 54 +++++++++---------- .../Semantics/FunctionPointerTests.cs | 40 +++++++------- 3 files changed, 66 insertions(+), 59 deletions(-) diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index c75ec0e31470e..5ab17c17f5e6a 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -609,10 +609,7 @@ void visitFunctionPointerSignature(IMethodSymbol symbol) foreach (var param in symbol.Parameters) { - if (format.MemberOptions.IncludesOption(SymbolDisplayMemberOptions.IncludeRef)) - { - AddParameterRefKind(param.RefKind); - } + AddParameterRefKind(param.RefKind); AddCustomModifiersIfRequired(param.RefCustomModifiers); @@ -626,11 +623,11 @@ void visitFunctionPointerSignature(IMethodSymbol symbol) if (symbol.ReturnsByRef) { - AddRefIfRequired(); + AddRef(); } else if (symbol.ReturnsByRefReadonly) { - AddRefReadonlyIfRequired(); + AddRefReadonly(); } AddCustomModifiersIfRequired(symbol.RefCustomModifiers); @@ -950,22 +947,32 @@ private void AddRefIfRequired() { if (format.MemberOptions.IncludesOption(SymbolDisplayMemberOptions.IncludeRef)) { - AddKeyword(SyntaxKind.RefKeyword); - AddSpace(); + AddRef(); } } + private void AddRef() + { + AddKeyword(SyntaxKind.RefKeyword); + AddSpace(); + } + private void AddRefReadonlyIfRequired() { if (format.MemberOptions.IncludesOption(SymbolDisplayMemberOptions.IncludeRef)) { - AddKeyword(SyntaxKind.RefKeyword); - AddSpace(); - AddKeyword(SyntaxKind.ReadOnlyKeyword); - AddSpace(); + AddRefReadonly(); } } + private void AddRefReadonly() + { + AddKeyword(SyntaxKind.RefKeyword); + AddSpace(); + AddKeyword(SyntaxKind.ReadOnlyKeyword); + AddSpace(); + } + private void AddReadOnlyIfRequired() { // 'readonly' in this context is effectively a 'ref' modifier diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 3c1b9c3ecc1a7..dbcf340c35bda 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -258,15 +258,15 @@ void M(C c) var comp = CreateCompilationWithFunctionPointersAndIl(source, il); comp.VerifyDiagnostics( - // (6,26): error CS0570: 'delegate*' is not supported by the language + // (6,26): error CS0570: 'delegate*' is not supported by the language // ref int i1 = ref c.Field1(); - Diagnostic(ErrorCode.ERR_BindToBogus, "c.Field1()").WithArguments("delegate*").WithLocation(6, 26), + Diagnostic(ErrorCode.ERR_BindToBogus, "c.Field1()").WithArguments("delegate*").WithLocation(6, 26), // (6,28): error CS0570: 'C.Field1' is not supported by the language // ref int i1 = ref c.Field1(); Diagnostic(ErrorCode.ERR_BindToBogus, "Field1").WithArguments("C.Field1").WithLocation(6, 28), - // (7,26): error CS0570: 'delegate*' is not supported by the language + // (7,26): error CS0570: 'delegate*' is not supported by the language // ref int i2 = ref c.Field2(); - Diagnostic(ErrorCode.ERR_BindToBogus, "c.Field2()").WithArguments("delegate*").WithLocation(7, 26), + Diagnostic(ErrorCode.ERR_BindToBogus, "c.Field2()").WithArguments("delegate*").WithLocation(7, 26), // (7,28): error CS0570: 'C.Field2' is not supported by the language // ref int i2 = ref c.Field2(); Diagnostic(ErrorCode.ERR_BindToBogus, "Field2").WithArguments("C.Field2").WithLocation(7, 28), @@ -3214,18 +3214,18 @@ void M() // (26,36): error CS8758: Ref mismatch between 'C.M6()' and function pointer 'delegate*' // delegate* ptr14 = &M6; Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M6").WithArguments("C.M6()", "delegate*").WithLocation(26, 36), - // (27,40): error CS8758: Ref mismatch between 'C.M6()' and function pointer 'delegate*' + // (27,40): error CS8758: Ref mismatch between 'C.M6()' and function pointer 'delegate*' // delegate* ptr15 = &M6; - Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M6").WithArguments("C.M6()", "delegate*").WithLocation(27, 40), - // (28,40): error CS8758: Ref mismatch between 'C.M7()' and function pointer 'delegate*' + Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M6").WithArguments("C.M6()", "delegate*").WithLocation(27, 40), + // (28,40): error CS8758: Ref mismatch between 'C.M7()' and function pointer 'delegate*' // delegate* ptr16 = &M7; - Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M7").WithArguments("C.M7()", "delegate*").WithLocation(28, 40), - // (29,49): error CS8758: Ref mismatch between 'C.M5()' and function pointer 'delegate*' + Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M7").WithArguments("C.M7()", "delegate*").WithLocation(28, 40), + // (29,49): error CS8758: Ref mismatch between 'C.M5()' and function pointer 'delegate*' // delegate* ptr17 = &M5; - Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M5").WithArguments("C.M5()", "delegate*").WithLocation(29, 49), - // (30,49): error CS8758: Ref mismatch between 'C.M7()' and function pointer 'delegate*' + Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M5").WithArguments("C.M5()", "delegate*").WithLocation(29, 49), + // (30,49): error CS8758: Ref mismatch between 'C.M7()' and function pointer 'delegate*' // delegate* ptr18 = &M7; - Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M7").WithArguments("C.M7()", "delegate*").WithLocation(30, 49) + Diagnostic(ErrorCode.ERR_FuncPtrRefMismatch, "M7").WithArguments("C.M7()", "delegate*").WithLocation(30, 49) ); } @@ -5305,7 +5305,7 @@ void M(delegate* ptr1, delegate* ptr2) where T : C } }"); - verifier.VerifyIL(@"C.M(delegate*, delegate*)", @" + verifier.VerifyIL(@"C.M(delegate*, delegate*)", @" { // Code size 34 (0x22) .maxstack 1 @@ -6267,10 +6267,10 @@ protected override void M1(delegate*<{refKind2}string> ptr) {{}} comp.VerifyDiagnostics( // (9,29): error CS0115: 'Derived.M1(delegate*<{refKind2} string>)': no suitable method found to override // protected override void M1(delegate*<{refKind2} string> ptr) {} - Diagnostic(ErrorCode.ERR_OverrideNotExpected, "M1").WithArguments($"Derived.M1(delegate*)").WithLocation(9, 29), + Diagnostic(ErrorCode.ERR_OverrideNotExpected, "M1").WithArguments($"Derived.M1(delegate*<{(string.IsNullOrWhiteSpace(refKind2) ? "" : refKind2)}string>)").WithLocation(9, 29), // (10,49): error CS0508: 'Derived.M2()': return type must be 'delegate*<{refKind1} string>' to match overridden member 'Base.M2()' // protected override delegate*<{refKind2} string> M2() => throw null; - Diagnostic(ErrorCode.ERR_CantChangeReturnTypeOnOverride, "M2").WithArguments("Derived.M2()", "Base.M2()", $"delegate*").WithLocation(10, 42 + refKind2.Length) + Diagnostic(ErrorCode.ERR_CantChangeReturnTypeOnOverride, "M2").WithArguments("Derived.M2()", "Base.M2()", $"delegate*<{(string.IsNullOrWhiteSpace(refKind1) ? "" : refKind1)}string>").WithLocation(10, 42 + refKind2.Length) ); } @@ -7024,12 +7024,12 @@ static void M2(delegate* ptr1) // (18,32): warning CS8619: Nullability of reference types in value of type 'string' doesn't match target type 'string?'. // ref string? str3 = ref ptr1(ref str2); Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr1(ref str2)").WithArguments("string", "string?").WithLocation(18, 32), - // (19,51): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. + // (19,51): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. // delegate* ptr2 = ptr1; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr1").WithArguments("delegate*", "delegate*").WithLocation(19, 51), - // (20,51): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr1").WithArguments("delegate*", "delegate*").WithLocation(19, 51), + // (20,51): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. // delegate* ptr3 = ptr1; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr1").WithArguments("delegate*", "delegate*").WithLocation(20, 51) + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr1").WithArguments("delegate*", "delegate*").WithLocation(20, 51) ); } @@ -10738,7 +10738,7 @@ static ref int ReturnPtrByRef(delegate* ptr, ref int i) static ref int ReturnByRef(ref int i) => ref i; }", expectedOutput: "2"); - verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, ref int)", @" + verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, ref int)", @" { // Code size 10 (0xa) .maxstack 2 @@ -10794,9 +10794,9 @@ static ref Span ReturnPtrByRef(delegate*, ref Span> ptr) }", options: TestOptions.UnsafeReleaseExe); comp.VerifyDiagnostics( - // (10,20): error CS8347: Cannot use a result of 'delegate*, Span>' in this context because it may expose variables referenced by parameter '0' outside of their declaration scope + // (10,20): error CS8347: Cannot use a result of 'delegate*, ref Span>' in this context because it may expose variables referenced by parameter '0' outside of their declaration scope // return ref ptr(ref span); - Diagnostic(ErrorCode.ERR_EscapeCall, "ptr(ref span)").WithArguments("delegate*, System.Span>", "0").WithLocation(10, 20), + Diagnostic(ErrorCode.ERR_EscapeCall, "ptr(ref span)").WithArguments("delegate*, ref System.Span>", "0").WithLocation(10, 20), // (10,28): error CS8168: Cannot return local 'span' by reference because it is not a ref local // return ref ptr(ref span); Diagnostic(ErrorCode.ERR_RefReturnLocal, "span").WithArguments("span").WithLocation(10, 28) @@ -10824,7 +10824,7 @@ static ref Span ReturnPtrByRef(delegate*, ref Span> ptr, var verifier = CompileAndVerify(comp, expectedOutput: "2", verify: Verification.Skipped); - verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, System.Span>, ref System.Span)", @" + verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, ref System.Span>, ref System.Span)", @" { // Code size 10 (0xa) .maxstack 2 @@ -10855,9 +10855,9 @@ static ref int ReturnPtrByRef(delegate* ptr, ref int }", options: TestOptions.UnsafeReleaseExe); comp.VerifyDiagnostics( - // (8,16): error CS8333: Cannot return method 'delegate*' by writable reference because it is a readonly variable + // (8,16): error CS8333: Cannot return method 'delegate*' by writable reference because it is a readonly variable // => ref ptr(ref i); - Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "ptr(ref i)").WithArguments("method", "delegate*").WithLocation(8, 16) + Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "ptr(ref i)").WithArguments("method", "delegate*").WithLocation(8, 16) ); } @@ -10878,7 +10878,7 @@ static ref readonly int ReturnPtrByRef(delegate* ptr, ref int static ref int ReturnByRef(ref int i) => ref i; }", expectedOutput: "2"); - verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, ref int)", @" + verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, ref int)", @" { // Code size 10 (0xa) .maxstack 2 @@ -10986,7 +10986,7 @@ static ref int ReturnPtrByRef(delegate* ptr, ref int i, ref in static ref int ReturnByRef(ref int i) => ref i; }", expectedOutput: "2"); - verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, ref int, ref int)", @" + verifier.VerifyIL("$.<
$>g__ReturnPtrByRef|0_0(delegate*, ref int, ref int)", @" { // Code size 10 (0xa) .maxstack 2 diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs index 328eab86ad8a6..abacc213d795a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs @@ -962,15 +962,15 @@ void M(delegate* param1) }"); comp.VerifyDiagnostics( - // (6,47): error CS0266: Cannot implicitly convert type 'delegate*' to 'delegate*'. An explicit conversion exists (are you missing a cast?) + // (6,47): error CS0266: Cannot implicitly convert type 'delegate*' to 'delegate*'. An explicit conversion exists (are you missing a cast?) // delegate* ptr1 = param1; - Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "param1").WithArguments("delegate*", "delegate*").WithLocation(6, 47), - // (7,34): error CS0266: Cannot implicitly convert type 'delegate*' to 'delegate*'. An explicit conversion exists (are you missing a cast?) + Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "param1").WithArguments("delegate*", "delegate*").WithLocation(6, 47), + // (7,34): error CS0266: Cannot implicitly convert type 'delegate*' to 'delegate*'. An explicit conversion exists (are you missing a cast?) // delegate* ptr2 = param1; - Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "param1").WithArguments("delegate*", "delegate*").WithLocation(7, 34), - // (8,34): error CS0266: Cannot implicitly convert type 'delegate*' to 'delegate*'. An explicit conversion exists (are you missing a cast?) + Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "param1").WithArguments("delegate*", "delegate*").WithLocation(7, 34), + // (8,34): error CS0266: Cannot implicitly convert type 'delegate*' to 'delegate*'. An explicit conversion exists (are you missing a cast?) // delegate* ptr3 = param1; - Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "param1").WithArguments("delegate*", "delegate*").WithLocation(8, 34) + Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "param1").WithArguments("delegate*", "delegate*").WithLocation(8, 34) ); var tree = comp.SyntaxTrees[0]; @@ -1865,9 +1865,9 @@ public static void M(bool b) // (12,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*[]' and 'delegate* unmanaged[Cdecl][]' // _ = b ? ptr1 : ptr4; Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr1 : ptr4").WithArguments("delegate*[]", "delegate* unmanaged[Cdecl][]").WithLocation(12, 13), - // (18,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*[]' and 'delegate*[]' + // (18,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*[]' and 'delegate*[]' // _ = b ? ptr5 : ptr6; - Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr5 : ptr6").WithArguments("delegate*[]", "delegate*[]").WithLocation(18, 13), + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr5 : ptr6").WithArguments("delegate*[]", "delegate*[]").WithLocation(18, 13), // (19,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*[]' and 'delegate*[]' // _ = b ? ptr5 : ptr7; Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr5 : ptr7").WithArguments("delegate*[]", "delegate*[]").WithLocation(19, 13), @@ -1953,24 +1953,24 @@ void M(bool b) }"); comp.VerifyDiagnostics( - // (12,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' + // (12,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' // _ = b ? ptr1 : ptr3; - Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr1 : ptr3").WithArguments("delegate*", "delegate*").WithLocation(12, 13), - // (13,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr1 : ptr3").WithArguments("delegate*", "delegate*").WithLocation(12, 13), + // (13,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' // _ = b ? ptr1 : ptr4; - Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr1 : ptr4").WithArguments("delegate*", "delegate*").WithLocation(13, 13), - // (14,24): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr1 : ptr4").WithArguments("delegate*", "delegate*").WithLocation(13, 13), + // (14,24): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. // _ = b ? ptr3 : ptr4; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr4").WithArguments("delegate*", "delegate*").WithLocation(14, 24), - // (21,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr4").WithArguments("delegate*", "delegate*").WithLocation(14, 24), + // (21,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' // _ = b ? ptr5 : ptr7; - Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr5 : ptr7").WithArguments("delegate*", "delegate*").WithLocation(21, 13), - // (22,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr5 : ptr7").WithArguments("delegate*", "delegate*").WithLocation(21, 13), + // (22,13): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'delegate*' and 'delegate*' // _ = b ? ptr5 : ptr8; - Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr5 : ptr8").WithArguments("delegate*", "delegate*").WithLocation(22, 13), - // (23,24): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? ptr5 : ptr8").WithArguments("delegate*", "delegate*").WithLocation(22, 13), + // (23,24): warning CS8619: Nullability of reference types in value of type 'delegate*' doesn't match target type 'delegate*'. // _ = b ? ptr7 : ptr8; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr8").WithArguments("delegate*", "delegate*").WithLocation(23, 24) + Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "ptr8").WithArguments("delegate*", "delegate*").WithLocation(23, 24) ); var tree = comp.SyntaxTrees[0]; From e3f11f58f3f6aacadc4e9946dc8532352c243abe Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Tue, 16 Mar 2021 08:55:21 +0200 Subject: [PATCH 10/11] Fix couple of broken tests --- .../SymbolDisplay/SymbolDisplayTests.cs | 25 ++----------------- .../Symbols/FunctionPointerTypeSymbolTests.cs | 4 +-- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs index f12fcf5308d8d..33822fc183b5d 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs @@ -7717,7 +7717,7 @@ class A { } [Fact, WorkItem(51222, "https://github.com/dotnet/roslyn/issues/51222")] - public void TestFunctionPointerWithRefParametersAndIncludeParameterRefOut() + public void TestFunctionPointerWithRefParameters() { var text = @" class A { @@ -7728,28 +7728,7 @@ class A { ((FieldSymbol)global.GetTypeMembers("A", 0).Single() .GetMembers("f").Single()).Type; - var format = new SymbolDisplayFormat(parameterOptions: SymbolDisplayParameterOptions.IncludeParamsRefOut); - - TestSymbolDescription( - text, - findSymbol, - format, - "delegate*"); - } - - [Fact, WorkItem(51222, "https://github.com/dotnet/roslyn/issues/51222")] - public void TestFunctionPointerWithRefParametersAndIncludeRef() - { - var text = @" -class A { - delegate* f; -}"; - - Func findSymbol = global => - ((FieldSymbol)global.GetTypeMembers("A", 0).Single() - .GetMembers("f").Single()).Type; - - var format = new SymbolDisplayFormat(memberOptions: SymbolDisplayMemberOptions.IncludeRef); + var format = new SymbolDisplayFormat(); TestSymbolDescription( text, diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/FunctionPointerTypeSymbolTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/FunctionPointerTypeSymbolTests.cs index d31971c4e5fef..99baec09f67e5 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/FunctionPointerTypeSymbolTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/FunctionPointerTypeSymbolTests.cs @@ -1516,9 +1516,9 @@ .field public method int32 modopt([mscorlib]System.Object) & *() 'Field2' var f2 = c.GetField("Field2").Type; Assert.Equal("delegate*", f1.ToTestDisplayString()); - Assert.Equal("delegate*", f1.ToDisplayString()); + Assert.Equal("delegate*", f1.ToDisplayString()); Assert.Equal("delegate*", f2.ToTestDisplayString()); - Assert.Equal("delegate*", f2.ToDisplayString()); + Assert.Equal("delegate*", f2.ToDisplayString()); } [Fact] From cb039000c3c3dbbcac4faeb40dc86101496fb2c9 Mon Sep 17 00:00:00 2001 From: yair halberstadt Date: Wed, 17 Mar 2021 10:14:06 +0200 Subject: [PATCH 11/11] Fix tests --- .../Test/Semantic/Semantics/FunctionPointerTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs index bea6dde5e8209..2e597b7498082 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs @@ -2629,9 +2629,9 @@ static void Test1(delegate*[] func) {} // (8,5): error CS0411: The type arguments for method 'Test1(delegate*[])' cannot be inferred from the usage. Try specifying the type arguments explicitly. // Test1(ptr2); Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "Test1").WithArguments("Test1(delegate*[])").WithLocation(8, 5), - // (9,27): error CS1503: Argument 1: cannot convert from 'delegate*[]' to 'delegate*[]' + // (9,27): error CS1503: Argument 1: cannot convert from 'delegate*[]' to 'delegate*[]' // Test1(ptr2); - Diagnostic(ErrorCode.ERR_BadArgType, "ptr2").WithArguments("1", "delegate*[]", "delegate*[]").WithLocation(9, 27) + Diagnostic(ErrorCode.ERR_BadArgType, "ptr2").WithArguments("1", "delegate*[]", "delegate*[]").WithLocation(9, 27) ); } @@ -2720,9 +2720,9 @@ static void Test(delegate* func) {} // (8,5): error CS0411: The type arguments for method 'Test(delegate*)' cannot be inferred from the usage. Try specifying the type arguments explicitly. // Test(ptr2); Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "Test").WithArguments("Test(delegate*)").WithLocation(8, 5), - // (9,26): error CS1503: Argument 1: cannot convert from 'delegate*' to 'delegate*' + // (9,26): error CS1503: Argument 1: cannot convert from 'delegate*' to 'delegate*' // Test(ptr2); - Diagnostic(ErrorCode.ERR_BadArgType, "ptr2").WithArguments("1", "delegate*", "delegate*").WithLocation(9, 26) + Diagnostic(ErrorCode.ERR_BadArgType, "ptr2").WithArguments("1", "delegate*", "delegate*").WithLocation(9, 26) ); } @@ -2777,9 +2777,9 @@ static void Test(delegate*, void> func) {} // (8,5): error CS0411: The type arguments for method 'Test(delegate*, void>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. // Test(ptr2); Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "Test").WithArguments("Test(delegate*, void>)").WithLocation(8, 5), - // (9,26): error CS1503: Argument 1: cannot convert from 'delegate*, void>' to 'delegate*, void>' + // (9,26): error CS1503: Argument 1: cannot convert from 'delegate*, void>' to 'delegate*, void>' // Test(ptr2); - Diagnostic(ErrorCode.ERR_BadArgType, "ptr2").WithArguments("1", "delegate*, void>", "delegate*, void>").WithLocation(9, 26) + Diagnostic(ErrorCode.ERR_BadArgType, "ptr2").WithArguments("1", "delegate*, void>", "delegate*, void>").WithLocation(9, 26) ); }