New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inspection warning about procedure coercion calls #5165
Inspection warning about procedure coercion calls #5165
Conversation
Note that the parameterized versions are technically not procedure coercions, but indexed default member accesses.
ff6966b
to
6ca5b84
Compare
LGTM; just one suggestion - In test cases we consider only the scenario of |
Rubberduck.CodeAnalysis/Inspections/ObjectWhereProcedureIsRequiredInspection.cs
Outdated
Show resolved
Hide resolved
Rubberduck.CodeAnalysis/Inspections/ObjectWhereProcedureIsRequiredInspection.cs
Show resolved
Hide resolved
Updates are based on review comments to PR rubberduck-vba#5165.
Updates are based on review comments to PR rubberduck-vba#5165.
0e15f77
to
ba80ad9
Compare
/// Identifies places in which an object is used but a procedure is required and a default member exists on the object. | ||
/// </summary> | ||
/// <why> | ||
/// Providing an object in a place in which a procedure is required leads to a call to the objects default member. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Providing an object in a place in which a procedure is required leads to a call to the objects default member. | |
/// Providing an object where a procedure is required leads to an implicit call to the object's default member. |
/// </summary> | ||
/// <why> | ||
/// Providing an object in a place in which a procedure is required leads to a call to the objects default member. | ||
/// This behavior is not obvious and most likely an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This behavior is not obvious and most likely an error. | |
/// This behavior is not obvious, and most likely unintended. |
Based on further comments on PR rubberduck-vba#5165
The new
ObjectWhereProcedureIsRequiredInspection
warns about places in which a procedure coercion takes place, i.e. places in which an object is provided in a call statement. This leads to a call to the default member, provided it is a procedure or function or the default member cannot be bound at compile time. (Properties yield a compilation error, since they are not allowed in call statements.) This type of indirection is next to never really necessary and much more likely is caused by erroneously forgetting a member call.This PR also provides the
ExpandDefaultMemberQuickFiz
, which does the obvious thing. Note that it will always expand the full default member chain for recursive default member reolutions. Moreover, it is deactivated for any such chain that cannot fully be bound at compile time. This is the first step towards fixing issue #2504; just the corresponding inspection is missing.NOTE:
Because of the infrastructure introduced in PR #5164, this PR is based on it. Please do not merge before that PR. I will rebase this one once the other PR is merged.