[netcore] Make System.Linq.Expressions.Tests.BindTests.GlobalField Pass (mono/mono...
authorMaxim Lipnin <v-maxlip@microsoft.com>
Fri, 19 Jul 2019 21:21:22 +0000 (00:21 +0300)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Fri, 19 Jul 2019 21:21:22 +0000 (23:21 +0200)
`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 `"<Module>"` 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
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeFieldInfo.cs

index 3d0b066..2c74f63 100644 (file)
 # 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
index 0dc5765..56a8271 100644 (file)
@@ -168,7 +168,8 @@ namespace System.Reflection
                }
                public override Type DeclaringType {
                        get {
-                               return GetParentType (true);
+                               Type parentType = GetParentType (true);
+                               return parentType.Name != "<Module>" ? 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.");
            }