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
SetAssignmentWithIncompatibleObjectTypeInspection #5003
SetAssignmentWithIncompatibleObjectTypeInspection #5003
Conversation
Currently only supports variable assignments on the RHS. Also fixes a previously ignored test for the MoveCloserToUsageRefactoring.
# Conflicts: # Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.xml
...rduck.CodeAnalysis/Inspections/Concrete/SetAssignmentWithIncompatibleObjectTypeInspection.cs
Show resolved
Hide resolved
RubberduckTests/Inspections/SetAssignmentWithIncompatibleObjectTypeInspectionTests.cs
Show resolved
Hide resolved
…ypeInspection into ISetTypeResolver implementation Currently only handles simple name expressions and instance expressions. Also fixed Declaration.FullAsTypeName for enums and UDTs.
# Conflicts: # Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs # Rubberduck.Resources/Inspections/InspectionInfo.de.resx # Rubberduck.Resources/Inspections/InspectionNames.Designer.cs # Rubberduck.Resources/Inspections/InspectionNames.de.resx # Rubberduck.Resources/Inspections/InspectionResults.Designer.cs # Rubberduck.Resources/Inspections/InspectionResults.de.resx
…-object expressions null is only returned in case we cannot resolve the Set type, primarily because of member accesses on objects of type Variant and Object.
This includes a workaround requires because built-in types are currently resolved as lExpressions, more precisely as simpleNameExpressions.
Previously, everything matched by builtInTypeExpr was already consumed by lExpr. Since all built-in types are keywords, this should not cause problems in most cases. The only exception would be foreign identifiers whose name is a built-in type. (This should be very rare and is problematic anyway.) This change required patching up the resolver as well to deal with builtInTypes.
…k in (with) dictionary access expressions
…th compatible parameter list with only optional arguments
# Conflicts: # Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs # Rubberduck.Resources/Inspections/InspectionInfo.resx # Rubberduck.Resources/Inspections/InspectionNames.Designer.cs # Rubberduck.Resources/Inspections/InspectionNames.resx # Rubberduck.Resources/Inspections/InspectionResults.Designer.cs # Rubberduck.Resources/Inspections/InspectionResults.resx
Also cleans up NonReturningFunctionInspection and makes Selection honor the contract of IComparable<Selection>.
This PR is largely finished now. It introduces a The current implementation uses identifier references to determine the Set type. This has the advandage over putting the information on the contextx themselves that no further cash invalidation is required. I still plan to do some clean up in |
These reference the entire index expression and have the new flag IsArrayAccess set to true. To resolve everything correctly, the entire IndexDefaultBinding got an overhaul. Also replaces the tests of ImplicitDefaultMemberAssignmentInspection since they previously only passed because the resolution of the assignment target was wrong.
…to the inspection itself This also makes the ImplicitDefaultMemberAssignmentInspection work correctly without tweaks to the resolver..
Previously the options without explicit parentheses were preferred and matched to expressions with parentheses consuming them as part or the argument.
I basically rewrote the resolution of index expressions in the last commits to simplify things in the resolver. This includes attaching references to array accesses with a new flag I do not plan to add anything further to this PR excpt in response to review comments. |
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.
Excellent job, MDoerner! Mainly nitpicks. I also have one general comment - there are a numbers of TODO
s but the comment there does not really explain what exactly needs to be done. For example, instead of Need to improve checks
, it should explain what is missing so that maintainers who happen to go through will understand what needs doing there.
Rubberduck.CodeAnalysis/Inspections/Concrete/AssignedByValParameterInspection.cs
Show resolved
Hide resolved
RubberduckTests/Inspections/ImplicitActiveWorkbookReferenceInspectionTests.cs
Show resolved
Hide resolved
[Test] | ||
[Ignore("Broken by COM collector fix. See comment on test.")] | ||
//[Ignore("Broken by COM collector fix. See comment on test.")] |
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.
If it's working, do we really need the comment (both of them) anymore?
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.
Oh, I missed to remove the ignore line entirely. Will do that later.
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.
Very clean code as always - only a few minor suggestions, other than that LGTM.
/// <why> | ||
/// The VBA compiler does not check whether different object types are compatible. Instead there is a runtime error whenever the types are incompatible. | ||
/// </why> | ||
/// <example> |
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.
/// <example> | |
/// <example hasResult="true"> |
/// End Sub | ||
/// ]]> | ||
/// </example> | ||
/// <example> |
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.
/// <example> | |
/// <example hasResult="false"> |
*/ | ||
|
||
return ResolveRecursiveDefaultMember(defaultMember, defaultMemberClassification, argumentList, expression, recursionDepth); | ||
} |
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.
Great job with the comments there 👍
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.
They are basically copied from IndexDefaultBinding
, where autoboosh added them. I just modified them to refer to a dictionary access expression instead of an index expression.
@@ -60,6 +64,10 @@ public class IdentifierReference : IEquatable<IdentifierReference> | |||
|
|||
public bool IsSetAssignment { get; } | |||
|
|||
public bool IsDefaultMemberAccess { get; } |
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.
Brilliant 👍
//Please note that the lExpression is the (whitespace) index expression itself and not the lExpression it contains. | ||
private Declaration ResolveIndexExpressionAsArrayAccess(VBAParser.LExpressionContext actualIndexExpr, QualifiedModuleName containingModule, DeclarationFinder finder) | ||
{ | ||
// A n array access references the entire (whitespace)indexExpr. |
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.
// A n array access references the entire (whitespace)indexExpr. | |
// An array access references the entire (whitespace)indexExpr. |
@@ -386,6 +386,9 @@ | |||
<data name="ObsoleteWhileWendStatementInspection" xml:space="preserve"> | |||
<value>Use of obsolete 'While...Wend' statement</value> | |||
</data> | |||
<data name="SetAssignmentWithIncompatibleObjectTypeInspection" xml:space="preserve"> | |||
<value>Set Assignment With Incompatible Object Type</value> |
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.
<value>Set Assignment With Incompatible Object Type</value> | |
<value>Set assignment with incompatible object type</value> |
Attribute Foo.VB_UserMemId = 0 | ||
End Property | ||
Public Property Let Something(ByVal value As Long) | ||
Attribute Foo.VB_UserMemId = 0 |
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.
Not that it makes a difference, but is this legal code? IIUC only one member is allowed to have VB_UserMemId = 0
... I've always only ever put it on the Property Get
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.
I have no idea. I guess the VBE would just ignore one of them.
RubberduckTests/Inspections/ImplicitActiveWorkbookReferenceInspectionTests.cs
Show resolved
Hide resolved
…tTypeInspection Also changes the way the set assignments are obtained to increase performance when libraries are referenced.
Closes #4981
Closes #5069
Closes #5071
Closes #3937
This PR already covers the scope layed out in the first issue above, i.e. it curently supports variable assignments on the RHS. However, I think that this is not too useful yet. So, I plan to extend the scope to new expressions, index expressions and member access expressions on the RHS.