...
In general the tool favors strong typing, but it backs off to object if it means introducing something that would break the build. There are several possible causes of weak typing:
- Explicit use of weak typing using one variable for multiple types; typing typically a variable declared As Variant, As Object, As Form, As Control used for for multiple types; also occurs for a variable used as a scalar and an Array
- using the VB6
CallByName
function, - using
IF
orSelect
based onTypeName
orTypeOf
function - using
As Any
- use of variant for dynamic arrays
- Weakly typed symbols in a COM API description
- Errors in the code that do not show up in VB6 for some reason
- Unintended typing variations that are glossed over by VB6 but block unambiguous type inference
- Timing issues wherein the type of a symbol is known too late in the translation process to assist with recognizing code that references the symbol
- Depending on a type from a COM API that is not explicitly referenced in the VBP (i.e.
CreateObject)
- Depending on a type based on a variable expression (i.e.
CreateObject
)
Having said that, gmStudio provides an extensive set of upgrade configuration tools rules and techniques that teams may use to improve type inference:
- Pre-Edits to change weak declarations to strong ones
Refactor/Fixtype
commands to set the type of specific symbols based on fully-qualified identifier- Explicitly referencing a COM description that was not referenced by the VBP (i.e. helps with
CreateObject
) Registry type="FixType"
to set the type of a class of symbols based on their name- Modifying COM descriptions to set the types of various symbols
- Activating the Generic Collections upgrade feature
- Adding gmSL routines that help the tool recognize, interpret, and rework specific weak-typing scenarios
- Setting a symbol to
type="dynamic"
. But be warned, that does not really solve type inference issues, it merely simplifies late call syntax - Selects that alter type inference behavior at a global level
There are a few more advanced techniques to allow for symbols that are used with multiple-types and even to introduce interfaces or generics where type object or variant was used before.