Skip to content

Commit

Permalink
Fix analyzer tracking of nullable enums (dotnet#109430)
Browse files Browse the repository at this point in the history
Eliminates an incorrect IL2059 from the trim analyzer warning for
RuntimeHelpers.RunClassConstructor(typeof(Nullable<SomeEnum>).TypeHandle);
  • Loading branch information
sbomer authored Nov 1, 2024
1 parent ed77814 commit 3218072
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class SingleValueExtensions
new GenericParameterValue ((ITypeParameterSymbol) underlyingType)),
// typeof(Nullable<>)
TypeKind.Error => new SystemTypeValue (new TypeProxy (type)),
TypeKind.Class or TypeKind.Struct or TypeKind.Interface =>
TypeKind.Class or TypeKind.Enum or TypeKind.Interface or TypeKind.Struct =>
new NullableSystemTypeValue (new TypeProxy (type), new SystemTypeValue (new TypeProxy (underlyingType))),
_ => UnknownValue.Instance
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void Main ()
TestIfElseUsingRuntimeTypeHandle (1);
TestIfElseUsingType (1);
TestNullableValueType ();
TestNullableEnum ();
}

[Kept]
Expand Down Expand Up @@ -132,6 +133,16 @@ static void TestNullableValueType ()
RuntimeHelpers.RunClassConstructor (typeof (int?).TypeHandle);
}

[Kept]
[KeptMember ( "value__")]
enum MyEnum {}

[Kept]
static void TestNullableEnum ()
{
RuntimeHelpers.RunClassConstructor (typeof (Nullable<MyEnum>).TypeHandle);
}

[Kept]
[KeptMember (".cctor()")]
class OnlyUsedViaReflection
Expand Down

0 comments on commit 3218072

Please sign in to comment.