Skip to content
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

Fix mapping of redeclared type parameters #3167

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/linker/Linker.Dataflow/CompilerGeneratedState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ referencedMethod.DeclaringType is var generatedType &&
// Now that we have instantiating methods fully filled out, walk the generated types and fill in the attribute
// providers
foreach (var generatedType in generatedTypeToTypeArgs.Keys) {
if (HasGenericParameters (generatedType)) {
if (generatedType.HasGenericParameters) {
MapGeneratedTypeTypeParameters (generatedType, generatedTypeToTypeArgs, _context);
// Finally, add resolved type arguments to the cache
var info = generatedTypeToTypeArgs[generatedType];
Expand All @@ -298,19 +298,6 @@ referencedMethod.DeclaringType is var generatedType &&
_cachedTypeToCompilerGeneratedMembers.Add (type, compilerGeneratedCallees);
return type;

/// <summary>
/// Check if the type itself is generic. The only difference is that
/// if the type is a nested type, the generic parameters from its
/// parent type don't count.
/// </summary>
static bool HasGenericParameters (TypeDefinition typeDef)
{
if (!typeDef.IsNested)
return typeDef.HasGenericParameters;

return typeDef.GenericParameters.Count > typeDef.DeclaringType.GenericParameters.Count;
}

/// <summary>
/// Attempts to reverse the process of the compiler's alpha renaming. So if the original code was
/// something like this:
Expand Down
17 changes: 17 additions & 0 deletions test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void Main ()
AsyncCapture ();
AsyncTypeMismatch ();
AsyncInsideClosure ();
AsyncInsideClosureNonGeneric ();
AsyncInsideClosureMismatch ();

// Closures
Expand Down Expand Up @@ -220,6 +221,22 @@ private static void AsyncInsideClosure ()
}
}

private static void AsyncInsideClosureNonGeneric ()
{
Outer<string> ();
void Outer<[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T1> ()
{
int x = 0;
Inner ().Wait ();
async Task Inner ()
{
await Task.Delay (0);
x++;
_ = typeof (T1).GetMethods ();
}
}
}

private static void AsyncInsideClosureMismatch ()
{
Outer<string> ();
Expand Down