diff options
author | stakx <stakx@eml.cc> | 2018-05-07 16:15:49 +0200 |
---|---|---|
committer | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2018-05-07 07:15:49 -0700 |
commit | fceac03e8202fb07dc1bb3b4f3ec3cf0921e12de (patch) | |
tree | f7c908d56fbfa1f34df16674853c1f8f8048b9bc /src/mscorlib | |
parent | a8c1c328068518444775e7bb9211f07523c2f21b (diff) | |
download | coreclr-fceac03e8202fb07dc1bb3b4f3ec3cf0921e12de.tar.gz coreclr-fceac03e8202fb07dc1bb3b4f3ec3cf0921e12de.tar.bz2 coreclr-fceac03e8202fb07dc1bb3b4f3ec3cf0921e12de.zip |
Reflection.Emit: Allow `ParameterBuilder.SetConstant(null)` for value-typed parameters (#17887)
* Add test for dotnet/corefx#26184
The Roslyn C# compiler encodes an optional, value-typed parameter's
default value of `default(TValueType)` as a null reference constant in
metadata. Add a test that verifies that reflection can do the same
using `ParameterBuilder.SetConstant(null)`.
* Always allow ParameterBuilder.SetConstant(null)
* Remove test project as requested in review
These tests move to CoreFX. See dotnet/corefx#29532.
Diffstat (limited to 'src/mscorlib')
-rw-r--r-- | src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs index 00d64f6872..f517decc1d 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs @@ -398,12 +398,9 @@ namespace System.Reflection.Emit } else { - if (destType.IsValueType) - { - // nullable types can hold null value. - if (!(destType.IsGenericType && destType.GetGenericTypeDefinition() == typeof(Nullable<>))) - throw new ArgumentException(SR.Argument_ConstantNull); - } + // A null default value in metadata is permissible even for non-nullable value types. + // (See ECMA-335 II.15.4.1.4 "The .param directive" and II.22.9 "Constant" for details.) + // This is how the Roslyn compilers generally encode `default(TValueType)` default values. SetConstantValue(module.GetNativeHandle(), tk, (int)CorElementType.Class, null); } |