{"action":"created","issue":{"url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/issues/4560","repository_url":"https://api.github.com/repos/rubberduck-vba/Rubberduck","labels_url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/issues/4560/labels{/name}","comments_url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/issues/4560/comments","events_url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/issues/4560/events","html_url":"https://github.com/rubberduck-vba/Rubberduck/issues/4560","id":384706326,"node_id":"MDU6SXNzdWUzODQ3MDYzMjY=","number":4560,"title":"Code Inspections - Local variable is not declared + Forms","user":{"login":"Gener4tor","id":40824720,"node_id":"MDQ6VXNlcjQwODI0NzIw","avatar_url":"https://avatars2.githubusercontent.com/u/40824720?v=4","gravatar_id":"","url":"https://api.github.com/users/Gener4tor","html_url":"https://github.com/Gener4tor","followers_url":"https://api.github.com/users/Gener4tor/followers","following_url":"https://api.github.com/users/Gener4tor/following{/other_user}","gists_url":"https://api.github.com/users/Gener4tor/gists{/gist_id}","starred_url":"https://api.github.com/users/Gener4tor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gener4tor/subscriptions","organizations_url":"https://api.github.com/users/Gener4tor/orgs","repos_url":"https://api.github.com/users/Gener4tor/repos","events_url":"https://api.github.com/users/Gener4tor/events{/privacy}","received_events_url":"https://api.github.com/users/Gener4tor/received_events","type":"User","site_admin":false},"labels":[{"id":141909751,"node_id":"MDU6TGFiZWwxNDE5MDk3NTE=","url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/labels/duplicate","name":"duplicate","color":"c5def5","default":true},{"id":141909752,"node_id":"MDU6TGFiZWwxNDE5MDk3NTI=","url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/labels/enhancement","name":"enhancement","color":"FEFEFE","default":true},{"id":997780241,"node_id":"MDU6TGFiZWw5OTc3ODAyNDE=","url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/labels/typeinfo-processing","name":"typeinfo-processing","color":"200763","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-11-27T09:47:05Z","updated_at":"2018-11-27T13:11:47Z","closed_at":"2018-11-27T11:18:24Z","author_association":"NONE","body":"When I use a Control in a Form like this:\r\n\r\nrequest.Name = PE_NAMF\r\n\r\nthe code inspection tells me:\r\n\r\n\"Local variable 'PE_NAMF' is not declared\"\r\n\r\nand that my code will not compile. When I click \"fix\" rubberduck will create the following line:\r\n\r\n\"Dim PE_NAMF As Variant\"\r\n\r\nwhich is wrong as \"PE_NAMF\" is the name of an edit field in the form. Im not sure what exacly does this, but I suppose it introduced a bug in my program.\r\n\r\nIt seems like rubberduck does not know the Names of the controls in the form. As a quick fix form me I can simly write: \r\n\r\nrequest.Name = Me.PE_NAMF\r\n\r\nand everything is ok. But the wrong inspection-message is misleading and the \"fix\" is dangerous.\r\n\r\nP.S.: I use:\r\nVersion 2.3.0.4221\r\nOS: Microsoft Windows NT 10.0.16299.0, x64\r\nHost Product: Microsoft Office 2016 x86\r\nHost Version: 16.0.4711.1000\r\nHost Executable: MSACCESS.EXE\r\n"},"comment":{"url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/issues/comments/442052910","html_url":"https://github.com/rubberduck-vba/Rubberduck/issues/4560#issuecomment-442052910","issue_url":"https://api.github.com/repos/rubberduck-vba/Rubberduck/issues/4560","id":442052910,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MjA1MjkxMA==","user":{"login":"retailcoder","id":5751684,"node_id":"MDQ6VXNlcjU3NTE2ODQ=","avatar_url":"https://avatars2.githubusercontent.com/u/5751684?v=4","gravatar_id":"","url":"https://api.github.com/users/retailcoder","html_url":"https://github.com/retailcoder","followers_url":"https://api.github.com/users/retailcoder/followers","following_url":"https://api.github.com/users/retailcoder/following{/other_user}","gists_url":"https://api.github.com/users/retailcoder/gists{/gist_id}","starred_url":"https://api.github.com/users/retailcoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/retailcoder/subscriptions","organizations_url":"https://api.github.com/users/retailcoder/orgs","repos_url":"https://api.github.com/users/retailcoder/repos","events_url":"https://api.github.com/users/retailcoder/events{/privacy}","received_events_url":"https://api.github.com/users/retailcoder/received_events","type":"User","site_admin":false},"created_at":"2018-11-27T13:11:47Z","updated_at":"2018-11-27T13:11:47Z","author_association":"MEMBER","body":"> When rubberduck is not able to parse all the valid variables in a namespace, it should not tell me that this variable is undeclared.\r\n\r\nDocument module controls are not variables, they're objects akin to hidden module-level public fields, and they are not accessible through the VBE Extensibility API. I'm open to ideas for dismissing an inspection result when it is known that document-module controls aren't resolved, that doesn't produce false negatives for undeclared variables in the code-behind. Seems to me that *knowing the picture is incomplete* implies knowing what the complete picture should be - and if we knew that then there wouldn't be missing declarations in the first place.\r\n\r\nEarly 2.0 builds (and 1.x) didn't create \"undeclared\" variables, which made it impossible to warn about undeclared variables, which is a very common problem with VBA/VB6 code since `Option Explicit` is, well, optional. As a static code analysis tool for VBA/VB6, being able to identify variables that aren't declared is a fundamental building block, and false positives due to Rubberduck's current inability to locate controls in document modules were deemed (correctly, IMO) easy enough to spot and thus the advantage of being able to report undeclared variables in user code outweights the annoyance of wrongly reporting document module controls as undeclared variables.\r\n\r\nThe only way I can see document module controls not reported as such, is to revert the resolver logic that introduces an undeclared variable for any identifier it's unable to resolve in user code - short of being able to somehow identify document module controls, of course. This is simply not an acceptable solution.\r\n\r\nThe only real solution is to know what controls exist on a document module, and as @bclothier aluded to, this is something that has only recently become an available, with the contributions from @WaynePhillipsEA allowing Rubberduck to break the wall of the under-featured VBIDE API (which obviously was never intended or foreseen to support an IDE extension as deep and thorough as Rubberduck), and finally see the VBA/VB6 project contents through, essentially, the eyes of the VBE itself.\r\n\r\nUntil the TypeLib API is leveraged to that effect, requiring variable declaration (via VBE options) and ensuring Rubberduck's \"Option Explicit\" inspection is enabled, should be enough to dismiss \"Variable not declared\" inspection results - the inspection can safely be disabled if variable declaration is enforced by the IDE - but Rubberduck has no way of knowing this, and thus ships with the inspection enabled by default, again because the default VBE configuration allows for undeclared variables to exist.\r\n\r\nEven after the typelib API is leveraged and Rubberduck correctly identifies document module controls, please keep in mind that no static code analysis tool is ever flawless. ReSharper isn't free OSS, is built by a company that makes IDEs and decompilers, sells for a good hundred bucks *yearly*, still has false positives as of version 10.x, and openly tells its users to always use their judgement before applying a quickfix. Holding Rubberduck to a higher standard doesn't strike me as fair at all."}}
{"actor":{"display_login":"retailcoder"}}