-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Fix ilasm/ildasm roundtrip constraint duplication issue #123309
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
df2efb2
Initial plan
Copilot cc9a205
Add regression test for ilasm/ildasm roundtrip constraint duplication
Copilot 4f3aa55
Fix test to load IL types from repro assembly
Copilot 4c16a11
Rename test to GitHub_122933 and use C# repro instead of IL
Copilot 143d7af
Apply suggestions from code review
jkotas 6aa8664
Remove unnecessary comments from TestEntryPoint method
Copilot 3ddfc60
Update src/tests/Regressions/coreclr/GitHub_122933/test122933.cs
jkotas af5e479
Dummy ilasm change
jkotas daef984
Fix ilasm constraint duplication by comparing signature bytes
Copilot 0a4864e
Apply suggestions from code review
jkotas 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
8 changes: 8 additions & 0 deletions
8
src/tests/Regressions/coreclr/GitHub_122933/Test122933.csproj
This file contains hidden or 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,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="test122933.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or 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,84 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using Xunit; | ||
|
|
||
| // Small repro for ilasm/ildasm roundtrip issue with duplicated constraints | ||
| // This demonstrates the issue where constraints get duplicated during ilasm roundtrip | ||
|
jkotas marked this conversation as resolved.
Outdated
|
||
| public interface IComp<TSelf> | ||
| : IEq<TSelf> | ||
| where TSelf : IComp<TSelf>? | ||
| { | ||
| } | ||
|
|
||
| public interface IEq<TSelf> | ||
| where TSelf : IEq<TSelf>? | ||
| { | ||
| } | ||
|
|
||
| public class Test122933 | ||
| { | ||
| [Fact] | ||
| public static int TestEntryPoint() | ||
| { | ||
| // Get the types | ||
|
jkotas marked this conversation as resolved.
Outdated
|
||
| Type ieqType = typeof(IEq<>); | ||
| Type icompType = typeof(IComp<>); | ||
|
|
||
| // Get the generic type parameter for IEq<TSelf> | ||
| Type[] ieqTypeParams = ieqType.GetGenericArguments(); | ||
| if (ieqTypeParams.Length != 1) | ||
| { | ||
| Console.WriteLine($"FAIL: IEq should have 1 generic parameter, but has {ieqTypeParams.Length}"); | ||
| return -1; | ||
| } | ||
| Type ieqTSelf = ieqTypeParams[0]; | ||
|
|
||
| // Get the constraints on IEq's TSelf parameter | ||
| Type[] ieqConstraints = ieqTSelf.GetGenericParameterConstraints(); | ||
|
|
||
| // There should be exactly one constraint: IEq<TSelf> | ||
| if (ieqConstraints.Length != 1) | ||
| { | ||
| Console.WriteLine($"FAIL: IEq<TSelf> should have 1 constraint, but has {ieqConstraints.Length}"); | ||
| return -1; | ||
| } | ||
|
|
||
| if (ieqConstraints[0].GetGenericTypeDefinition() != ieqType) | ||
| { | ||
| Console.WriteLine($"FAIL: IEq<TSelf> constraint should be IEq<>, but is {ieqConstraints[0].GetGenericTypeDefinition()}"); | ||
| return -1; | ||
| } | ||
|
|
||
| // Get the generic type parameter for IComp<TSelf> | ||
| Type[] icompTypeParams = icompType.GetGenericArguments(); | ||
| if (icompTypeParams.Length != 1) | ||
| { | ||
| Console.WriteLine($"FAIL: IComp should have 1 generic parameter, but has {icompTypeParams.Length}"); | ||
| return -1; | ||
| } | ||
| Type icompTSelf = icompTypeParams[0]; | ||
|
|
||
| // Get the constraints on IComp's TSelf parameter | ||
| Type[] icompConstraints = icompTSelf.GetGenericParameterConstraints(); | ||
|
|
||
| // There should be exactly one constraint: IComp<TSelf> | ||
| // After ilasm roundtrip, this becomes duplicated - that's the bug | ||
| if (icompConstraints.Length != 1) | ||
| { | ||
| Console.WriteLine($"FAIL: IComp<TSelf> should have 1 constraint, but has {icompConstraints.Length}"); | ||
| return -1; | ||
| } | ||
|
|
||
| if (icompConstraints[0].GetGenericTypeDefinition() != icompType) | ||
| { | ||
| Console.WriteLine($"FAIL: IComp<TSelf> constraint should be IComp<>, but is {icompConstraints[0].GetGenericTypeDefinition()}"); | ||
| return -1; | ||
| } | ||
|
|
||
| return 100; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.