Skip to content

Commit

Permalink
Avoid compiler crash when `UsageBasedMetadataGenerationOptions.Comple…
Browse files Browse the repository at this point in the history
…teTypesOnly` is specified (#106445)

Fixes #106439.

This is an unsupported flag that allows generating unusable metadata for type members that would have been trimmed. This is useful when troubleshooting trimming issues for people who ignore trimming warnings because it converts random `NullReferenceException` (e.g. `GetMethod` returned null and the program didn't check for it) into "Foo.Bar wasn't generated" exceptions.

Because this isn't tested, we regressed this. The code that checks whether it's possible to generate the metadata for the member at all stopped working for uninstantiated generics. This check is needed to deal with invalid input IL.
  • Loading branch information
MichalStrehovsky authored Aug 15, 2024
1 parent 67df47e commit 7f315b1
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
{
try
{
// Make sure we're not adding a method to the dependency graph that is going to
// cause trouble down the line. This entire type would not actually load on CoreCLR anyway.
LibraryRootProvider.CheckCanGenerateMethod(method);
// Spot check by parsing signature.
// Previously we had LibraryRootProvider.CheckCanGenerateMethod(method) here, but that one
// expects fully instantiated types and methods. We operate on definitions here.
// This is not as thorough as it could be. This option is unsupported anyway.
_ = method.Signature;
}
catch (TypeSystemException)
{
Expand Down

0 comments on commit 7f315b1

Please sign in to comment.