summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstakx <stakx@eml.cc>2018-05-08 16:39:17 +0200
committerAtsushi Kanamori <AtsushiKan@users.noreply.github.com>2018-05-08 07:39:17 -0700
commit878a3dbab6369579d55a182f8fcbbdb4128abb66 (patch)
treeb32ec6a5f30c83f6f81ef97bab7b3a04a40e6447
parent2d95e13070d6864943b1df5a0a8dea14df70c0f9 (diff)
downloadcoreclr-878a3dbab6369579d55a182f8fcbbdb4128abb66.tar.gz
coreclr-878a3dbab6369579d55a182f8fcbbdb4128abb66.tar.bz2
coreclr-878a3dbab6369579d55a182f8fcbbdb4128abb66.zip
Fix failing System.Reflection.Emit tests (#17915)
Commit fceac03e82 removed a test from `TypeBuilder.SetConstantValue` that is too strict when called from `ParameterBuilder`, but that both `FieldBuilder` and `EnumBuilder` require. Add the same test back, but in `FieldBuilder.SetConstant`.
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs
index 2c4850921c..78a1ed5bb5 100644
--- a/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs
+++ b/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs
@@ -178,6 +178,13 @@ namespace System.Reflection.Emit
{
m_typeBuilder.ThrowIfCreated();
+ if (defaultValue == null && m_fieldType.IsValueType)
+ {
+ // nullable types can hold null value.
+ if (!(m_fieldType.IsGenericType && m_fieldType.GetGenericTypeDefinition() == typeof(Nullable<>)))
+ throw new ArgumentException(SR.Argument_ConstantNull);
+ }
+
TypeBuilder.SetConstantValue(m_typeBuilder.GetModuleBuilder(), GetToken().Token, m_fieldType, defaultValue);
}