-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle synthesized delegates without refKinds #58802
Merged
davidwengier
merged 5 commits into
dotnet:main
from
davidwengier:EnCMoreSynthesizedDelegates
Jan 13, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
862cb0b
Handle synthesized delegates without refKinds
davidwengier 40ffc9e
Update src/Compilers/CSharp/Portable/Symbols/Synthesized/GeneratedNam…
davidwengier c50ef71
PR Feedback
davidwengier 10126ac
Cleanup
davidwengier d5bba30
More tests
davidwengier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/Compilers/CSharp/Test/Emit/Emit/GeneratedNamesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.CodeAnalysis.CSharp.Symbols; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Emit | ||
{ | ||
public class GeneratedNamesTests | ||
{ | ||
[Theory] | ||
[InlineData("<>A", true, 0, 0)] | ||
[InlineData("<>A{00010000}`8", true, 0, 8)] | ||
[InlineData("<>A{00010000}#2`8", true, 2, 8)] | ||
[InlineData("<>A{00010000,00000000}`16", true, 0, 16)] | ||
[InlineData("<>A{00010000,00000000}#4`16", true, 4, 16)] | ||
[InlineData("<>A`5", true, 0, 5)] | ||
[InlineData("<>A`18", true, 0, 18)] | ||
[InlineData("<>F`1", false, 0, 0)] | ||
[InlineData("<>F`6", false, 0, 5)] | ||
[InlineData("<>F`19", false, 0, 18)] | ||
[InlineData("<>F#3`19", false, 3, 18)] | ||
public void TryParseSynthesizedDelegateName_Success(string name, bool returnsVoid, int generation, int parameterCount) | ||
{ | ||
Assert.True(GeneratedNames.TryParseSynthesizedDelegateName(name, out var actualByRefs, out var actualReturnsVoid, out var actualGeneration, out var actualParameterCount)); | ||
|
||
Assert.Equal(returnsVoid, actualReturnsVoid); | ||
Assert.Equal(generation, actualGeneration); | ||
Assert.Equal(parameterCount, actualParameterCount); | ||
|
||
|
||
// We need to strip arity in order to validate round-tripping | ||
name = MetadataHelpers.InferTypeArityAndUnmangleMetadataName(name, out _); | ||
Assert.Equal(name, GeneratedNames.MakeSynthesizedDelegateName(actualByRefs, actualReturnsVoid, actualGeneration)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate blank lines above. |
||
|
||
[Theory] | ||
[InlineData("<>D")] | ||
[InlineData("<>A{")] | ||
[InlineData("<>A00}")] | ||
[InlineData("<>ABCDEF")] | ||
[InlineData("<>A{Z}")] | ||
[InlineData("<>A#F")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider testing
|
||
[InlineData("<>A{}")] | ||
[InlineData("<>A{,}")] | ||
[InlineData("<>A#")] | ||
[InlineData("<>A{0,}")] | ||
[InlineData("<>A{,1}")] | ||
public void TryParseSynthesizedDelegateName_Failure(string name) | ||
{ | ||
Assert.False(GeneratedNames.TryParseSynthesizedDelegateName(name, out _, out _, out _, out _)); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider testing
"<>F{01}#3`1"
"<>F{0,1}`1"
"<>A{0,}"
"<>A{,1}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, you're saying these should be successfully parsed? Currently two of them fail to because
RefKindVector.TryParse
doesn't like them, and the other two fail on roundtripping becauseRefKindVector.TryParse
andRefKindVector.ToRefKindString
aren't really round trippable (Parse will parse something that ToRefKindString will assert on).I'm happy to fix all of that, just wanted to confirm, and confirm its not overstepping this PR.