Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ internal override bool IsIntrinsicallyHandled(IMethodSymbol calledMethod, MultiV
}
return true;
}
case IntrinsicId.Enum_GetValues:
{
foreach (var value in arguments[0].AsEnumerable())
{
if (value is not SystemTypeValue)
{
return false;
}
}

return true;
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public Task MakeGenericDataFlow()
}

[Fact]
public Task MakeGenericDataflowIntrinsics()
public Task RequiresDynamicCodeAnalyzerIntrinsics()
{
return RunTest();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,5 +549,37 @@ public void N<T>() { }
// (4,24): warning IL3050: Using member 'System.Reflection.MethodInfo.MakeGenericMethod(params Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
VerifyCS.Diagnostic(DiagnosticId.RequiresDynamicCode).WithSpan(4, 24, 4, 72).WithArguments("System.Reflection.MethodInfo.MakeGenericMethod(params Type[])", " The native code for this instantiation might not be available at runtime.", ""));
}

[Fact]
public Task EnumGetValuesWithKnownType()
{
const string src = $$"""
using System;
class C
{
public void M() => Enum.GetValues(typeof(MyEnum));
}
enum MyEnum { One, Two }
""";

return VerifyRequiresDynamicCodeAnalyzer(src);
}

[Fact]
public Task EnumGetValuesWithUnknownType()
{
const string src = $$"""
using System;
class C
{
public void M() => Enum.GetValues(GetUnknownType());
static Type GetUnknownType() => typeof(MyEnum);
}
enum MyEnum { One, Two }
""";

return VerifyRequiresDynamicCodeAnalyzer(src,
VerifyCS.Diagnostic(DiagnosticId.RequiresDynamicCode).WithSpan(4, 24, 4, 38).WithArguments("System.Enum.GetValues(Type)", " It might not be possible to create an array of the enum type at runtime. Use the GetValues<TEnum> overload or the GetValuesAsUnderlyingType method instead.", ""));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public Task NestedTypeForwarder()
return RunTest(allowMissingWarnings: true);
}

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

[Fact]
public Task SecurityAttributeScope()
{
Expand Down Expand Up @@ -207,6 +213,12 @@ public Task UsedForwarderIsRemovedWhenLink()
return RunTest(allowMissingWarnings: true);
}

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

[Fact]
public Task UsedForwarderWithAssemblyCopy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow
{
[SkipKeptItemsValidation]
[ExpectedNoWarnings]
class MakeGenericDataflowIntrinsics
class RequiresDynamicCodeAnalyzerIntrinsics
{
public static void Main()
{
MakeGenericType.Test();
MakeGenericMethod.Test();
EnumGetValues.Test();
}

class MakeGenericType
Expand Down Expand Up @@ -88,5 +89,28 @@ public static void Test()
[ExpectedWarning("IL3050", nameof(MethodInfo.MakeGenericMethod), Tool.Analyzer | Tool.NativeAot, "NativeAOT-specific warning")]
public static void TestUnknownArgument() => typeof(MakeGenericMethod).GetMethod(nameof(Gen)).MakeGenericMethod(GrabUnknownType());
}

class EnumGetValues
Comment thread
MichalStrehovsky marked this conversation as resolved.
{
enum SomeEnum
{
A,
B
}

static Type GrabUnknownType() => null;

public static void Test()
{
TestKnownType();
TestUnknownType();
}

[ExpectedNoWarnings]
public static void TestKnownType() => Enum.GetValues(typeof(SomeEnum));

[ExpectedWarning("IL3050", nameof(Enum.GetValues), Tool.Analyzer | Tool.NativeAot, "NativeAOT-specific warning")]
public static void TestUnknownType() => Enum.GetValues(GrabUnknownType());
}
}
}
Loading