Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Only add a type forward if the nested type is visible outside of the assembly #275

Merged

Conversation

joperezr
Copy link
Member

Only add a type forward if the nested type is visible outside of the assembly. This is the fix for issue #274

@dnfclas
Copy link

dnfclas commented Sep 18, 2015

Hi @joperezr, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. Real humans will now evaluate your PR.

TTYL, DNFBOT;

@joperezr
Copy link
Member Author

cc @nguerrera @weshaggard

@@ -495,7 +495,8 @@ private void AddTypeForward(Assembly assembly, INamedTypeDefinition seedType)
// but the runtime currently throws a TypeLoadException without explicit forwarders for the nested
// types.
foreach (var nestedType in seedType.NestedTypes.OrderBy(t => t.Name.Value))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@nguerrera
Copy link

What did you think about my question about InternalsVisibleTo in the issue. I believe it's OK for GenFacades to ignore this case, but I would:

  • Test whether the following works:

Assembly A

[assembly: InternalsVisibleTo(C)]
public class X { internal class Y {} }

Assembly B, generated by GenFacades -> A

[assembly: TypeForwardedTo(typeof(X))]

Assembly C, uses A via type forward from B

class Z : X.Y { }
  • Decide if GenFacades need to support it.

I think probably not, but we should deliberate doc that here. If it does need to support it, then I think we have to keep anything with internal visibility because the InternalsVisibleTo of target could change over time.

Also, did you check what Roslyn compiler now emits in these cases? I am curious and think we should follow up with them if they still emit entries for private nested classes.

Finally, please do an IL diff of Facades in corefx generated before and after this change and make sure that nothing unexpected is getting stripped.

@joperezr
Copy link
Member Author

I also think that is a non common case, but if you think we want to support it I can do it. If not, where do you want me to document it? I haven't check yet what Roslyn compiler does nor have I done the IL diff. I'll do both tasks today and report back on the tracking issue, just wanted to start the PR first.

@nguerrera
Copy link

Actually, I just realized a better fix that would make the whole internal vs. private thing moot. Instead of enumerating the nested types of the destination, we should enumerate the nested types of the contract and forward those. We won't generally have any private nested classes in contracts.

@weshaggard
Copy link
Member

+1 to Nick's last suggestion that we should use the contract as the filter.

@dnfclas
Copy link

dnfclas commented Sep 21, 2015

@joperezr, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@joperezr joperezr force-pushed the RemoveNonVisibleExportedTypesGenFacades branch from c87ddef to c8abb93 Compare September 22, 2015 16:45
@joperezr
Copy link
Member Author

@weshaggard @nguerrera Let me know if the last commits are what you envisioned. I already tested it in the corefx build and it is passing, and also I've checked the ILs of the assemblies produced and seems like it's doing the right thing.

@joperezr
Copy link
Member Author

Ping! :)

}
}
else // Add all the nested types for ExportedTypes.
foreach (var nestedType in seedType.NestedTypes.OrderBy(t => t.Name.Value))

This comment was marked as spam.

This comment was marked as spam.

@joperezr joperezr force-pushed the RemoveNonVisibleExportedTypesGenFacades branch from e4afc4f to 208ca14 Compare October 12, 2015 18:58
@joperezr
Copy link
Member Author

I already tested my last changes with corefx repo, and everything seems to work correctly except that I'm running into the known issue dotnet/corefx#3726 The rest of the tests pass just fine.

{
Trace.TraceError(" /preferSeedType:{0}={1}", docId.Substring("T:".Length), type.ContainingUnitNamespace.Unit.Name.Value);
Trace.TraceError(" /preferSeedType:{0}={1}", docId.Substring("T:".Length), GetContainingUnitNamespaceFromType(type));

This comment was marked as spam.

This comment was marked as spam.

joperezr added a commit that referenced this pull request Oct 13, 2015
…nFacades

Only add a type forward if the nested type is visible outside of the assembly
@joperezr joperezr merged commit 4d89b43 into dotnet:master Oct 13, 2015
@joperezr joperezr deleted the RemoveNonVisibleExportedTypesGenFacades branch October 13, 2015 18:31
@joperezr
Copy link
Member Author

Forgot to squash before merging. Sorry for the trouble!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants