Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Add test for accessing RUC cctor directly
  • Loading branch information
vitek-karas committed Apr 3, 2023
commit e369c8e85735a51728aff8d27a610c8cc0c27abf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void Main ()
TestTypeIsBeforeFieldInit ();
TestStaticCtorOnTypeWithRequires ();
TestRunClassConstructorOnTypeWithRequires ();
TestRunClassConstructorOnConstructorWithRequires ();
typeof (StaticCtor).RequiresNonPublicConstructors ();
}

Expand Down Expand Up @@ -70,6 +71,23 @@ static void TestRunClassConstructorOnTypeWithRequires ()
RuntimeHelpers.RunClassConstructor (typeHandle);
}

class StaticCtorForRunClassConstructorWithRequires
{
[ExpectedWarning ("IL2116")]
[ExpectedWarning ("IL3004", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
[ExpectedWarning ("IL3056", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
[RequiresUnreferencedCode ("Message for --StaticCtorOnTypeWithRequires--")]
[RequiresAssemblyFiles ("Message for --StaticCtorOnTypeWithRequires--")]
[RequiresDynamicCode ("Message for --StaticCtorOnTypeWithRequires--")]
static StaticCtorForRunClassConstructorWithRequires () { }
}

static void TestRunClassConstructorOnConstructorWithRequires ()
{
// No warnings generated here - we rely on IL2116/IL3004/IL3056 in this case and avoid duplicate warnings
RuntimeHelpers.RunClassConstructor (typeof (StaticCtorForRunClassConstructorWithRequires).TypeHandle);
}

class StaticCtorTriggeredByFieldAccess
{
[ExpectedWarning ("IL2116", "StaticCtorTriggeredByFieldAccess..cctor()")]
Expand Down