Skip to content
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

Rubberduck wants me to assign Object() array with 'Set' keyword #6200

Open
gitqube opened this issue Jan 31, 2024 · 2 comments
Open

Rubberduck wants me to assign Object() array with 'Set' keyword #6200

gitqube opened this issue Jan 31, 2024 · 2 comments
Labels
bug Identifies work items for known bugs difficulty-03-duck Involves more challenging problems and/or developing within and revising the internals API resolver Issue is easier to resolve with knowledge of the internal resolver API and the Antlr4 parse trees.

Comments

@gitqube
Copy link

gitqube commented Jan 31, 2024

Version 2.5.9.6319
OS: Microsoft Windows NT 10.0.19045.0, x64
Host Product: Microsoft Office x64
Host Version: 16.0.17029.20140
Host Executable: EXCEL.EXE

For demonstration use this Module code:

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) = ThisWorkbook

    myObjectArray = oArr1

    Dim oArr2() As Object
    oArr2 = ObjectArray

    Debug.Print oArr2(0).Name

End Sub

Description
This code compiles and runs.
Rubberduck gives me 3 Code Inspection Errors:

  1. Return value for member 'ObjectArray' is never assigned.
    This refers to line Public Property Get ObjectArray() As Object()
  2. Object variable 'ObjectArray' is assigned without the 'Set' keyword.
    This refers to line ObjectArray = myObjectArray
  3. In a context that requires a value type, the expression 'ObjectArray' of object type 'Object()' is used that does not have a suitable default member.
    This refers to line oArr2 = ObjectArray and may be related to ByRef Array of Objects Parameters, Inspection False Positives #6094

If I use the 'Set' keyword in front of ObjectArray = myObjectArray and in front of oArr2 = ObjectArray Rubberduck is satisfied and does not report any errors. But it does not compile, of course.

@gitqube gitqube added the bug Identifies work items for known bugs label Jan 31, 2024
@retailcoder
Copy link
Member

Thanks for the report!

The inspection results are all consistent with the object array being mistakenly resolved as an object type; something somewhere is missing a check against Declaration.IsArray 🫤

@retailcoder retailcoder moved this to To triage in Rubberduck 2.x Mar 21, 2024
@Vogel612 Vogel612 added the resolver Issue is easier to resolve with knowledge of the internal resolver API and the Antlr4 parse trees. label Dec 6, 2024
@retailcoder retailcoder self-assigned this Jan 20, 2025
retailcoder added a commit to retailcoder/Rubberduck that referenced this issue Jan 20, 2025
@retailcoder retailcoder removed their assignment Jan 20, 2025
@retailcoder retailcoder moved this from To triage to Backlog in Rubberduck 2.x Jan 20, 2025
@retailcoder retailcoder added the difficulty-03-duck Involves more challenging problems and/or developing within and revising the internals API label Jan 20, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in Rubberduck 2.x Jan 20, 2025
@retailcoder
Copy link
Member

Reopening, because the linked commit was actually reverted; this isn't an easy fix!

@retailcoder retailcoder reopened this Jan 20, 2025
@github-project-automation github-project-automation bot moved this from Done to Backlog in Rubberduck 2.x Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies work items for known bugs difficulty-03-duck Involves more challenging problems and/or developing within and revising the internals API resolver Issue is easier to resolve with knowledge of the internal resolver API and the Antlr4 parse trees.
Projects
Status: Backlog
Development

No branches or pull requests

3 participants