Skip to content

Commit

Permalink
[release/9.0] Fix RunClassConstructor trim warning for Nullable<T> (#…
Browse files Browse the repository at this point in the history
…107039)

* Clean up RunClassConstructor test

- Fix test name
- Run it in ILC tests
- Check warnings in analyzer tests

* Fix RunClassConstructor intrinsic for Nullable<T>

---------

Co-authored-by: Jeff Schwartz <[email protected]>
  • Loading branch information
sbomer and jeffschwMSFT authored Sep 4, 2024
1 parent ea363cc commit af1b39a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void Reflection (string t)
case "ParametersUsedViaReflection":
case "UnsafeAccessor":
case "TypeUsedViaReflection":
case "RunClassConstructor":
Run (t);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ ValueWithDynamicallyAccessedMembers valueWithDynamicallyAccessedMembers
} else if (typeHandleValue is RuntimeTypeHandleForValueWithDynamicallyAccessedMembers damAnnotatedHandle
&& (damAnnotatedHandle.UnderlyingTypeValue.DynamicallyAccessedMemberTypes & DynamicallyAccessedMemberTypes.NonPublicConstructors) != 0) {
// No action needed, NonPublicConstructors keeps the static constructor on the type
} else if (typeHandleValue is RuntimeTypeHandleForNullableSystemTypeValue) {
// No action needed, RunClassConstructor does not run the class constructor of the underlying type of Nullable<T>
} else {
_diagnosticContext.AddDiagnostic (DiagnosticId.UnrecognizedTypeInRuntimeHelpersRunClassConstructor, calledMethod.GetDisplayName ());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ public Task PropertiesUsedViaReflection ()
return RunTest ();
}

[Fact]
public Task RunClassConstructor ()
{
return RunTest ();
}

[Fact]
public Task RuntimeReflectionExtensionsCalls ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ public Task ParametersUsedViaReflection ()
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task RunClassConstructorUsedViaReflection ()
{
return RunTest (allowMissingWarnings: true);
}

[Fact]
public Task TypeHierarchyLibraryModeSuppressions ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Mono.Linker.Tests.Cases.Reflection
{
[SetupCSharpCompilerToUse ("csc")]
[ExpectedNoWarnings]
public class RunClassConstructorUsedViaReflection
public class RunClassConstructor
{
public static void Main ()
{
Expand All @@ -21,6 +21,7 @@ public static void Main ()
TestPublicConstructorDataFlowType ();
TestIfElseUsingRuntimeTypeHandle (1);
TestIfElseUsingType (1);
TestNullableValueType ();
}

[Kept]
Expand Down Expand Up @@ -125,6 +126,12 @@ static void TestIfElseUsingType (int i)
RuntimeHelpers.RunClassConstructor (myType.TypeHandle);
}

[Kept]
static void TestNullableValueType ()
{
RuntimeHelpers.RunClassConstructor (typeof (int?).TypeHandle);
}

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

0 comments on commit af1b39a

Please sign in to comment.