diff options
author | stakx <stakx@eml.cc> | 2018-05-08 16:39:17 +0200 |
---|---|---|
committer | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2018-05-08 07:39:17 -0700 |
commit | 878a3dbab6369579d55a182f8fcbbdb4128abb66 (patch) | |
tree | b32ec6a5f30c83f6f81ef97bab7b3a04a40e6447 | |
parent | 2d95e13070d6864943b1df5a0a8dea14df70c0f9 (diff) | |
download | coreclr-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.cs | 7 |
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); } |