From e85b6eb345a25475d393a7ea0145213cfc09378c Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Sat, 20 Jul 2019 00:21:22 +0300 Subject: [PATCH] [netcore] Make System.Linq.Expressions.Tests.BindTests.GlobalField Pass (mono/mono#15658) `Expression.Bind` should throw `ArgumentException` if called with `FieldInfo` for a global field. The exception is thrown from validation of the (null) `DeclaringType` (see https://github.com/dotnet/corefx/pull/15318). Mono returns `""` in this case and doesn't throw so the test fails. Fixes mono/mono#14917 . Commit migrated from https://github.com/mono/mono/commit/e8d7f7c0045a38c41a70f6d0a21ef3ccf9a21662 --- src/mono/netcore/CoreFX.issues.rsp | 4 ---- .../src/System.Reflection/RuntimeFieldInfo.cs | 6 ++++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/mono/netcore/CoreFX.issues.rsp b/src/mono/netcore/CoreFX.issues.rsp index 3d0b066..2c74f63 100644 --- a/src/mono/netcore/CoreFX.issues.rsp +++ b/src/mono/netcore/CoreFX.issues.rsp @@ -88,10 +88,6 @@ # https://github.com/mono/mono/issues/14912 -nomethod System.Linq.Expressions.Tests.ArrayBoundsTests.NewArrayBounds* -# Expected exception to be thrown. None is -# https://github.com/mono/mono/issues/14917 --nomethod System.Linq.Expressions.Tests.BindTests.GlobalField - # Exceptions are different. # https://github.com/mono/mono/issues/14918 -nomethod System.Linq.Expressions.Tests.BindTests.ConstantField diff --git a/src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeFieldInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeFieldInfo.cs index 0dc5765..56a8271 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeFieldInfo.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeFieldInfo.cs @@ -168,7 +168,8 @@ namespace System.Reflection } public override Type DeclaringType { get { - return GetParentType (true); + Type parentType = GetParentType (true); + return parentType.Name != "" ? parentType : null; } } public override string Name { @@ -260,7 +261,8 @@ namespace System.Reflection } void CheckGeneric () { - if (DeclaringType.ContainsGenericParameters) + Type declaringType = DeclaringType; + if (declaringType != null && declaringType.ContainsGenericParameters) throw new InvalidOperationException ("Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true."); } -- 2.7.4