This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Repository navigation
Throw ArgumentException for invalid uses of global members in Expressions. - #15318
Merged
Merged
Conversation
Using a global method with AndAlso or OrElse throws a NullReferenceException. Change this to throw the same ArgumentException thrown if the method is not declared on a type with op_True and op_False methods, since it isn't, so that is logically applicable. Contributes to #12943
Using a global method with New throws a NullReferenceException. Change this catch return false instead of throwing in TypeUtils.AreEquivalent and TypeUtils.IsValidInstanceType, as clearly the correct return value, resulting in ArgumentException being thrown instead. Contributes to #12943
Using a global method with Expression.Bind, Expression.ListBind or Expression.MemberBind throws a NullReferenceException. Change this by having global methods simply fail the test to check they are property accessors, since they aren't, resulting in ArgumentException. Contributes to #12943
nil4
reviewed
Jan 19, 2017
| <value>'{0}' is not a member of type '{1}'</value> | ||
| </data> | ||
| <data name="NotAMemberOfAnyType" xml:space="preserve"> | ||
| <value>'{0}' is not a member of any </value> |
Using a global method with Expression.Bind, or Expression.MemberBind returns a binding that will throw NullReferenceException on any attempt to use it. Change this to throw ArgumentException with the message: … is not a member of any type Contributes to #12943
VSadov
reviewed
Jan 26, 2017
| public static bool AreEquivalent(Type t1, Type t2) | ||
| { | ||
| return t1.IsEquivalentTo(t2); | ||
| return t1 != null && t1.IsEquivalentTo(t2); |
Member
There was a problem hiding this comment.
Type implements "==" operator. We just want a null check.
Would it be better to do something like: return t1?.IsEquivalentTo(t2) ?? false
VSadov
reviewed
Jan 26, 2017
| { | ||
| return true; | ||
| } | ||
| if (targetType == null) |
Member
There was a problem hiding this comment.
it ((object)targetType == null) - just to make it cheaper by not using the "==" operator on Type
VSadov
reviewed
Jan 26, 2017
| MethodInfo opTrue = TypeUtils.GetBooleanOperator(method.DeclaringType, "op_True"); | ||
| MethodInfo opFalse = TypeUtils.GetBooleanOperator(method.DeclaringType, "op_False"); | ||
| Type declaringType = method.DeclaringType; | ||
| if (declaringType == null) |
Member
There was a problem hiding this comment.
same thing about Type and "=="
Actually, It seems MethodInfo also has "==" implemented.
Perhaps it is worth going through and turn trivial null checks with Type/MemberInfo and the like into object equality or ?. operators. As a separate change of course.
Member
|
LGTM |
This was referenced Jul 10, 2019
akoeplinger
pushed a commit
to mono/mono
that referenced
this pull request
Jul 19, 2019
…ss (#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 dotnet/corefx#15318). Mono returns `"<Module>"` in this case and doesn't throw so the test fails. Fixes #14917 .
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
Throw ArgumentException for invalid uses of global members in Expressions. Commit migrated from dotnet/corefx@74041f7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several methods of
Expressionwill throwNullReferenceExceptionif called with aMethodInfoorFieldInfofor a global method or field. These exceptions are all thrown from validation of the (null)DeclaringType, so fix these validation methods to throw the same exception they would throw for a non-null but inappropriateDeclaringType.Using a global field with a
MemberBindingdoes not throw, but any attempt to use that binding will similarly throwNullReferenceException. Change to throw anArgumentExceptionimmediately.Fixes #12943