Consider this declaration:
Public Const MyConstant = "foo"
Rubberduck will suggest to _explicitly_ declare the constant as a Variant. But the parse tree _knows_ the value assigned is a _string literal_ - therefore Rubberduck should have enough information to declare it as a String.
Same here:
Dim foo
foo = 123
The parse tree _knows_ the assigned value is a number. Rubberduck should declare as Long.
Dim bar
bar = #2015-05-15#
Date literal.
Long or Double (if value has decimals)StringDateSet: Object is still vague, but better than a Variant.CInt function will always return an Integer; MsgBox calls return a Long, etc.Public or Friend accessibility.Public, Friend or Global fields in other modules' _declarations section_.Otherwise, give up and leave as a Variant.
Yes Please! Gets my vote. Hell, I'll implement it myself if I have to. :+1: :+1: :+1:
With the Declarations API this is now getting more and more realistic - if a constant, variable, function or member is referenced in the right-hand side of an assignment, then the type to use on the left-hand side is known, even if it's an Object, and the scoping issue is already solved.
Literals can be picked up pretty easily.
If we say anything else remains Variant (or Object if the left-hand side is Set), then we're already in a pretty good position to infer the return type.
We can also check if it is passed as a parameter in a function call, and if so, whether the parameter has specified a type.
linking #3225
This should perhaps honor any type hints:
Const LONG_NUMBER = &H1 is implicitly an Integer
Const LONG_NUMBER = &H1& is a type-hinted long
Most helpful comment
Yes Please! Gets my vote. Hell, I'll implement it myself if I have to. :+1: :+1: :+1: