Skip to content

Commit c63cd38

Browse files
stephentoubjkotas
andauthored
ifdef out unsupported Enum underlying types for nativeaot (#79472)
* ifdef out unsupported Enum underlying types for nativeaot * Use dedicated ifdef Co-authored-by: Jan Kotas <[email protected]>
1 parent a788114 commit c63cd38

File tree

6 files changed

+232
-168
lines changed

6 files changed

+232
-168
lines changed

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()
189189

190190
public static bool IsPreciseGcSupported => !IsMonoRuntime;
191191

192+
public static bool IsRareEnumsSupported => !IsNativeAot;
193+
192194
public static bool IsNotIntMaxValueArrayIndexSupported => s_largeArrayIsNotSupported.Value;
193195

194196
public static bool IsAssemblyLoadingSupported => !IsNativeAot;

src/libraries/Microsoft.VisualBasic.Core/tests/ConversionsTests.cs

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,6 @@ namespace Microsoft.VisualBasic.Tests
1313
{
1414
public class ConversionsTests
1515
{
16-
private static bool? s_reflectionEmitSupported = null;
17-
18-
public static bool ReflectionEmitSupported
19-
{
20-
get
21-
{
22-
if (s_reflectionEmitSupported == null)
23-
{
24-
try
25-
{
26-
object o = FloatEnum;
27-
s_reflectionEmitSupported = true;
28-
}
29-
catch (PlatformNotSupportedException)
30-
{
31-
s_reflectionEmitSupported = false;
32-
}
33-
}
34-
35-
return s_reflectionEmitSupported.Value;
36-
}
37-
}
38-
3916
public static IEnumerable<object[]> InvalidString_TestData()
4017
{
4118
yield return new object[] { "" };
@@ -49,7 +26,7 @@ public static IEnumerable<object[]> InvalidString_TestData()
4926

5027
public static IEnumerable<object[]> InvalidBool_TestData()
5128
{
52-
if (ReflectionEmitSupported)
29+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
5330
{
5431
yield return new object[] { FloatEnum };
5532
yield return new object[] { DoubleEnum };
@@ -65,7 +42,7 @@ public static IEnumerable<object[]> InvalidNumberObject_TestData()
6542
yield return new object[] { char.MaxValue };
6643
yield return new object[] { new DateTime(10) };
6744
yield return new object[] { new object() };
68-
if (ReflectionEmitSupported)
45+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
6946
{
7047
yield return new object[] { CharEnum };
7148
}
@@ -182,7 +159,7 @@ public static IEnumerable<object[]> ToByte_Object_TestData()
182159
// bool.
183160
yield return new object[] { true, byte.MaxValue };
184161
yield return new object[] { false, byte.MinValue };
185-
if (ReflectionEmitSupported)
162+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
186163
{
187164
yield return new object[] { BoolEnum, byte.MinValue };
188165
}
@@ -363,7 +340,7 @@ public static IEnumerable<object[]> ToSByte_Object_TestData()
363340
// bool.
364341
yield return new object[] { true, (sbyte)(-1) };
365342
yield return new object[] { false, (sbyte)0 };
366-
if (ReflectionEmitSupported)
343+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
367344
{
368345
yield return new object[] { BoolEnum, (sbyte)0 };
369346
}
@@ -537,7 +514,7 @@ public static IEnumerable<object[]> ToUShort_Object_TestData()
537514
// bool.
538515
yield return new object[] { true, ushort.MaxValue };
539516
yield return new object[] { false, ushort.MinValue };
540-
if (ReflectionEmitSupported)
517+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
541518
{
542519
yield return new object[] { BoolEnum, ushort.MinValue };
543520
}
@@ -721,7 +698,7 @@ public static IEnumerable<object[]> ToShort_Object_TestData()
721698
// bool.
722699
yield return new object[] { true, (short)(-1) };
723700
yield return new object[] { false, (short)0 };
724-
if (ReflectionEmitSupported)
701+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
725702
{
726703
yield return new object[] { BoolEnum, (short)0 };
727704
}
@@ -899,7 +876,7 @@ public static IEnumerable<object[]> ToUInteger_Object_TestData()
899876
// bool.
900877
yield return new object[] { true, uint.MaxValue };
901878
yield return new object[] { false, uint.MinValue };
902-
if (ReflectionEmitSupported)
879+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
903880
{
904881
yield return new object[] { BoolEnum, uint.MinValue };
905882
}
@@ -1089,7 +1066,7 @@ public static IEnumerable<object[]> ToInteger_Object_TestData()
10891066
// bool.
10901067
yield return new object[] { true, -1 };
10911068
yield return new object[] { false, 0 };
1092-
if (ReflectionEmitSupported)
1069+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
10931070
{
10941071
yield return new object[] { BoolEnum, 0 };
10951072
}
@@ -1275,7 +1252,7 @@ public static IEnumerable<object[]> ToULong_Object_TestData()
12751252
// bool.
12761253
yield return new object[] { true, ulong.MaxValue };
12771254
yield return new object[] { false, ulong.MinValue };
1278-
if (ReflectionEmitSupported)
1255+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
12791256
{
12801257
yield return new object[] { BoolEnum, ulong.MinValue };
12811258
}
@@ -1503,7 +1480,7 @@ public static IEnumerable<object[]> ToLong_Object_TestData()
15031480
// bool.
15041481
yield return new object[] { true, (long)(-1) };
15051482
yield return new object[] { false, (long)0 };
1506-
if (ReflectionEmitSupported)
1483+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
15071484
{
15081485
yield return new object[] { BoolEnum, (long)0 };
15091486
}
@@ -1729,7 +1706,7 @@ public static IEnumerable<object[]> ToSingle_Object_TestData()
17291706
// bool.
17301707
yield return new object[] { true, (float)(-1) };
17311708
yield return new object[] { false, (float)0 };
1732-
if (ReflectionEmitSupported)
1709+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
17331710
{
17341711
yield return new object[] { BoolEnum, (float)0 };
17351712
}
@@ -1922,7 +1899,7 @@ public static IEnumerable<object[]> ToDouble_Object_TestData()
19221899
// bool.
19231900
yield return new object[] { true, (double)(-1) };
19241901
yield return new object[] { false, (double)0 };
1925-
if (ReflectionEmitSupported)
1902+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
19261903
{
19271904
yield return new object[] { BoolEnum, (double)0 };
19281905
}
@@ -2118,7 +2095,7 @@ public static IEnumerable<object[]> ToDecimal_Object_TestData()
21182095
// bool.
21192096
yield return new object[] { true, (decimal)(-1) };
21202097
yield return new object[] { false, (decimal)0 };
2121-
if (ReflectionEmitSupported)
2098+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
21222099
{
21232100
yield return new object[] { BoolEnum, (decimal)0 };
21242101
}
@@ -2344,7 +2321,7 @@ public static IEnumerable<object[]> ToBoolean_Object_TestData()
23442321
// bool.
23452322
yield return new object[] { true, true };
23462323
yield return new object[] { false, false };
2347-
if (ReflectionEmitSupported)
2324+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
23482325
{
23492326
yield return new object[] { BoolEnum, false };
23502327
}
@@ -2659,7 +2636,7 @@ public static IEnumerable<object[]> ToString_IConvertible_TestData()
26592636
// bool.
26602637
yield return new object[] { true, "True" };
26612638
yield return new object[] { false, "False" };
2662-
if (ReflectionEmitSupported)
2639+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
26632640
{
26642641
yield return new object[] { BoolEnum, "False" };
26652642
}

src/libraries/System.Linq.Expressions/tests/Cast/CastTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ public static IEnumerable<Type> EnumerableTypes()
23732373
yield return typeof(Int64Enum);
23742374
yield return typeof(UInt64Enum);
23752375

2376-
if (PlatformDetection.IsReflectionEmitSupported)
2376+
if (PlatformDetection.IsReflectionEmitSupported && PlatformDetection.IsRareEnumsSupported)
23772377
{
23782378
yield return NonCSharpTypes.CharEnumType;
23792379
yield return NonCSharpTypes.BoolEnumType;

0 commit comments

Comments
 (0)