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

Questionable behavior in "Code inspections" #6195

Open
alterreg0 opened this issue Jan 26, 2024 · 2 comments
Open

Questionable behavior in "Code inspections" #6195

alterreg0 opened this issue Jan 26, 2024 · 2 comments
Labels
bug Identifies work items for known bugs

Comments

@alterreg0
Copy link

alterreg0 commented Jan 26, 2024

Rubberduck version information
Version 2.5.9.6316
OS: Microsoft Windows NT 10.0.22621.0, x64
Host Product: Microsoft Office x64
Host Version: 16.0.17126.20132
Host Executable: EXCEL.EXE

Description

Hello.
Firstly, thanks for the great tool - improved vba project explorer is what I had been thinking about for years - but never had enough time to develop)

I was using mostly project explorer only, but few days ago installed new version - and decided to explore other functionality.
During tesing "Code inspections" was detected some behavior, which seems questionable.
Found 2 typical situations:
(1) assigning to instance of class X value, which declared type is interface, implemented by X
(2) passing variable to method, which returns result in passed variable

Screenshots attached below
As a user - I have absolutely no problem with described behavior - so informing just in case this could be useful for developers.
Regards

(1)
image

image

same:
image

(2)
image

image

image

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

Thanks for the report, I hope you get to discover the rest of the features! 🥰

The MSO CommandBar issue is a weird one, it seems we already have all the necessary information to correctly identify the implemented interfaces there; surely something must be weird with the way they're made that somehow confuses our resolver into failing to identify the interface, because it's the same code for all COM libraries!

As for ByRef returns, that's a known and deliberate limitation of the inspection, although we could certainly make an exception for library functions since the motivation is about the performance penalty incurred by tracking whether an argument passed to a ByRef parameter is actually assigned in the called procedure or not (which would be a rabbit hole); I think it's reasonable to treat out parameters as an assignment to the argument expression, assuming that expression resolves to a known identifier.

@thefasquelle
Copy link

FWIW there is the same issue with the MSXML2 lib

image
image

Public Sub AddFileToVSProjUsingXmlObject(ByVal Name As String)
    Dim file As MSXML2.IXMLDOMDocument2
    Set file = New MSXML2.DOMDocument60
    'To the variable 'file' of declared type 'msxm16.dll:MSXML2.lXMLDOMDocument2' a value is set assigned with the incompatible declared type 'msxm16.dll:MSXML2.DOMDocument60'.
    
    ' read file from disk
    With New Scripting.FileSystemObject
        file.Load .GetFolder(ActiveWorkbook.path).SubFolders("DSP").Files("TestU.vcxproj").path
    End With
    
    ' set namespace for XPath query
    file.setProperty "SelectionNamespaces", "xmlns:msb='" & file.DocumentElement.NamespaceURI & "'"
    
    ' get ClCompile ItemGroup
    Dim itemGroup As IXMLDOMElement
    Set itemGroup = file.SelectSingleNode("//msb:ItemGroup[msb:ClCompile]")
    ' To the variable 'itemGroup' of declared type 'msxm16.dll:MSXML2-lXMLDOMElement' a value is set assigned with the incompatible declared type 'msxm16.dll:MSXML2-lXMLDOMNode'
    
    ' clone the last node. Do not clone its children (if any)
    Dim newNode As MSXML2.IXMLDOMElement
    Set newNode = itemGroup.ChildNodes(itemGroup.ChildNodes.Length - 1).CloneNode(False)
    ' To the variable 'newNode' of declared type 'msxm16. dll:MSXML2.lXMLDOMElement' a value is set assigned with the incompatible declared type Vmsxm16.dll:MSXML2.lXMLDOMNode'.
    
    ' update new node and append it to IemGroup
    newNode.Attributes.getNamedItem("Include").NodeValue = "..\TESTS\TestUAuto_" & Name & ".c"
    itemGroup.appendChild newNode
    ' To the variable 'newChild' of declared type 'msxm16.dll:MSXML2. IXMLDOMNode' a value is set assigned with the incompatible declared type 'newNode'.
    
    ' TODO do the same with ClInclude part
    
    file.Save ActiveWorkbook.path & "\TestA.vcxproj"
End Sub

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
Projects
None yet
Development

No branches or pull requests

3 participants