Skip to content

Commit

Permalink
Revert "fixes rubberduck-vba#6200"
Browse files Browse the repository at this point in the history
This reverts commit 52322bf.
  • Loading branch information
retailcoder committed Jan 20, 2025
1 parent 52322bf commit 694f35f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override IEnumerable<IdentifierReference> ReferencesInModule(Qualified
private static IEnumerable<IdentifierReference> FailedLetResolutionAssignments(QualifiedModuleName module, DeclarationFinder finder)
{
return finder.FailedLetCoercions(module)
.Where(reference => reference.IsAssignment && !reference.Declaration.IsArray);
.Where(reference => reference.IsAssignment);
}

private static IEnumerable<IdentifierReference> PossiblyObjectLhsLetAssignmentsWithNonValueOnRhs(QualifiedModuleName module, DeclarationFinder finder)
Expand Down Expand Up @@ -89,12 +89,11 @@ private static IEnumerable<IdentifierReference> PossiblyObjectNonSetAssignments(
{
var assignments = finder.IdentifierReferences(module)
.Where(reference => reference.IsAssignment
&& !reference.Declaration.IsArray
&& !reference.IsSetAssignment
&& (reference.IsNonIndexedDefaultMemberAccess
|| Tokens.Variant.Equals(reference.Declaration.AsTypeName, StringComparison.InvariantCultureIgnoreCase)));
var unboundAssignments = finder.UnboundDefaultMemberAccesses(module)
.Where(reference => reference.IsAssignment && !reference.Declaration.IsArray);
.Where(reference => reference.IsAssignment);

return assignments.Concat(unboundAssignments);
}
Expand Down
30 changes: 13 additions & 17 deletions Rubberduck.Parsing/Symbols/Declaration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Antlr4.Runtime;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Annotations.Concrete;
using Rubberduck.Parsing.ComReflection;
using Rubberduck.Parsing.Grammar;
using Rubberduck.VBEditor;
Expand All @@ -9,6 +8,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Rubberduck.Parsing.Annotations.Concrete;

namespace Rubberduck.Parsing.Symbols
{
Expand Down Expand Up @@ -117,7 +117,7 @@ public Declaration(
IEnumerable<IParseTreeAnnotation> annotations = null,
Attributes attributes = null)
{
QualifiedName = qualifiedName;
QualifiedName = qualifiedName;
ParentDeclaration = parentDeclaration;
ParentScopeDeclaration = ParentDeclaration;
ParentScope = parentScope ?? string.Empty;
Expand Down Expand Up @@ -145,7 +145,7 @@ public Declaration(
ProjectName = IdentifierName;
}

IsArray = isArray || AsTypeName != null && (AsTypeNameWithoutArrayDesignator.Length == AsTypeName.Length - "()".Length);
IsArray = isArray;
AsTypeContext = asTypeContext;
TypeHint = typeHint;
}
Expand All @@ -168,8 +168,7 @@ public Declaration(ComEnumeration enumeration, Declaration parent, QualifiedModu
null,
false,
null,
new Attributes())
{ }
new Attributes()) { }

public Declaration(ComStruct structure, Declaration parent, QualifiedModuleName module)
: this(
Expand All @@ -189,8 +188,7 @@ public Declaration(ComStruct structure, Declaration parent, QualifiedModuleName
null,
false,
null,
new Attributes())
{ }
new Attributes()) { }

public Declaration(ComEnumerationMember member, Declaration parent, QualifiedModuleName module) : this(
module.QualifyMemberName(member.Name),
Expand All @@ -209,8 +207,7 @@ public Declaration(ComEnumerationMember member, Declaration parent, QualifiedMod
null,
false,
null,
new Attributes())
{ }
new Attributes()) { }

public Declaration(ComField field, Declaration parent, QualifiedModuleName module)
: this(
Expand All @@ -230,8 +227,7 @@ public Declaration(ComField field, Declaration parent, QualifiedModuleName modul
null,
false,
null,
new Attributes())
{ }
new Attributes()) { }

public static Declaration GetModuleParent(Declaration declaration)
{
Expand Down Expand Up @@ -293,8 +289,8 @@ public string DescriptionString
{
string literalDescription;

var memberAttribute = Attributes.SingleOrDefault(a =>
a.Name == Attributes.MemberAttributeName("VB_Description", IdentifierName) ||
var memberAttribute = Attributes.SingleOrDefault(a =>
a.Name == Attributes.MemberAttributeName("VB_Description", IdentifierName) ||
a.Name == Attributes.MemberAttributeName("VB_VarDescription", IdentifierName));

if (memberAttribute != null)
Expand Down Expand Up @@ -327,10 +323,10 @@ public string DescriptionString

private static string CorrectlyFormatedDescription(string literalDescription)
{
if (string.IsNullOrEmpty(literalDescription)
|| literalDescription.Length < 2
if (string.IsNullOrEmpty(literalDescription)
|| literalDescription.Length < 2
|| literalDescription[0] != '"'
|| literalDescription[literalDescription.Length - 1] != '"')
|| literalDescription[literalDescription.Length -1] != '"')
{
return literalDescription;
}
Expand All @@ -354,7 +350,7 @@ private bool IsObjectOrObjectArray
{
get
{
if (AsTypeName == Tokens.Object
if (AsTypeName == Tokens.Object
|| (AsTypeDeclaration?.DeclarationType.HasFlag(DeclarationType.ClassModule) ?? false))
{
return true;
Expand Down
10 changes: 5 additions & 5 deletions Rubberduck.Parsing/Symbols/ParameterDeclaration.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Binding;
using Rubberduck.Parsing.ComReflection;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.VBA.Extensions;
using Rubberduck.VBEditor;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

namespace Rubberduck.Parsing.Symbols
{
Expand Down Expand Up @@ -39,7 +39,7 @@ public ParameterDeclaration(QualifiedMemberName qualifiedName,
null,
null,
Selection.Home,
isArray || isParamArray,
isArray,
asTypeContext,
false)
{
Expand Down Expand Up @@ -78,7 +78,7 @@ public ParameterDeclaration(QualifiedMemberName qualifiedName,
context,
null,
selection,
isArray || isParamArray,
isArray,
asTypeContext,
isUserDefined)
{
Expand Down
44 changes: 14 additions & 30 deletions RubberduckTests/Grammar/ResolverTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Rubberduck.InternalApi.Extensions;
using Rubberduck.Parsing.Annotations.Concrete;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using RubberduckTests.Mocks;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Annotations.Concrete;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.SafeComWrappers;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
using RubberduckTests.Mocks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace RubberduckTests.Grammar
{
Expand Down Expand Up @@ -119,23 +120,6 @@ End Sub
}
}

[Category("Resolver")]
[Test]
public void ParamArrayParameter_IsArray()
{
var code = @"Option Explicit
Public Sub Test(ParamArray Values)
End Sub
";
using (var state = Resolve(code))
{
var declaration = state.AllUserDeclarations.Single(item => item.DeclarationType == DeclarationType.Parameter && item.IdentifierName == "Values") as ParameterDeclaration;
Assert.IsTrue(declaration.IsParamArray);
Assert.IsTrue(declaration.IsArray);
}
}

[Category("Resolver")]
[Test]
public void OptionalParameterDefaultConstValue_IsReferenceToDeclaredConst()
Expand Down Expand Up @@ -1033,7 +1017,7 @@ End Sub
item.DeclarationType == DeclarationType.Variable
&& item.IdentifierName == "foo");

Assert.AreEqual(1, declaration.References.Count(item =>
Assert.AreEqual(1,declaration.References.Count(item =>
item.ParentScoping.DeclarationType == DeclarationType.Procedure
&& item.ParentScoping.IdentifierName == "DoSomething"
&& item.IsAssignment));
Expand Down Expand Up @@ -2294,7 +2278,7 @@ End Sub
var printReference = printDeclaration.References.Single();

var module = state.DeclarationFinder.AllModules.Single(qmn => qmn.ComponentType == ComponentType.ClassModule);
var expectedPrintSelection = new QualifiedSelection(module, new Selection(4, 5, 4, 10));
var expectedPrintSelection = new QualifiedSelection(module, new Selection(4, 5,4, 10));
var actualPrintSelection = new QualifiedSelection(printReference.QualifiedModuleName, printReference.Selection);

Assert.AreEqual(4, referencedDeclaration.References.Count());
Expand Down Expand Up @@ -3648,7 +3632,7 @@ End Function

Assert.AreEqual(expectedReferencedDeclarationName, actualReferencedDeclarationName);
Assert.IsTrue(reference.IsIndexedDefaultMemberAccess);
Assert.AreEqual(2, reference.DefaultMemberRecursionDepth);
Assert.AreEqual(2,reference.DefaultMemberRecursionDepth);
}
}

Expand Down Expand Up @@ -3848,7 +3832,7 @@ End Function
{
var module = state.DeclarationFinder.AllModules.First(qmn => qmn.ComponentName == "Module1");
var defaultMemberAccess = state.DeclarationFinder.UnboundDefaultMemberAccesses(module).First();

var expectedReferencedSelection = new QualifiedSelection(module, selection);
var actualReferencedSelection = new QualifiedSelection(defaultMemberAccess.QualifiedModuleName, defaultMemberAccess.Selection);

Expand Down Expand Up @@ -5719,7 +5703,7 @@ End Function
.Single(param => param.IdentifierName.Equals("furtherArgs"));
var argumentReferences = parameter.ArgumentReferences;

var expectedExpressionTexts = new HashSet<string> { "4", "5", "6" };
var expectedExpressionTexts = new HashSet<string>{"4", "5", "6"};
var actualExpressionTexts = argumentReferences.Select(reference => reference.Context.GetText()).ToList();

var expectedCount = expectedExpressionTexts.Count;
Expand Down Expand Up @@ -7350,7 +7334,7 @@ End Sub
var undeclared = finder.Members(module.QualifiedModuleName)
.Where(declaration => declaration.IsUndeclared)
.ToList();

Assert.AreEqual(4, undeclared.Count);
}
}
Expand Down Expand Up @@ -7418,7 +7402,7 @@ End Sub
using (var state = Resolve(vbe.Object))
{
var finder = state.DeclarationFinder;

var classModule = finder.UserDeclarations(DeclarationType.ClassModule).Single();
var barDeclaration = finder.Members(classModule.QualifiedModuleName, DeclarationType.Function).Single();
var barReference = barDeclaration.References.Single();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Linq;
using NUnit.Framework;
using Rubberduck.CodeAnalysis.Inspections;
using Rubberduck.CodeAnalysis.Inspections.Concrete;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.SafeComWrappers;
using RubberduckTests.Mocks;
using System.Linq;

namespace RubberduckTests.Inspections
{
Expand Down Expand Up @@ -210,37 +210,6 @@ Dim target As Variant
AssertInputCodeYieldsExpectedInspectionResultCount(input, expectResultCount);
}

[Test]
[Category("Inspections")]
public void ObjectVariableNotSet_GivenObjectArray_ReturnsNoResult()
{
var expectResultCount = 0;
var input =
@"
Private myObjectArray() As Object
Public Property Get ObjectArray() As Object()
ObjectArray = myObjectArray
End Property
Public Sub Test()
Dim oArr1(0) As Object
Set oArr1(0) = New Something
myObjectArray = oArr1
Dim oArr2() As Object
oArr2 = ObjectArray
Debug.Print oArr2(0).Name
End Sub
";
AssertInputCodeYieldsExpectedInspectionResultCount(input, expectResultCount);
}

[Test]
[Category("Inspections")]
public void ObjectVariableNotSet_GivenObjectVariableNotSet_Ignored_DoesNotReturnResult()
Expand Down

0 comments on commit 694f35f

Please sign in to comment.