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

Incorrectly identified as implicitly Variant #3728

Closed
IvenBach opened this issue Jan 25, 2018 · 5 comments
Closed

Incorrectly identified as implicitly Variant #3728

IvenBach opened this issue Jan 25, 2018 · 5 comments
Assignees
Labels
bug Identifies work items for known bugs difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. resolver Issue is easier to resolve with knowledge of the internal resolver API and the Antlr4 parse trees.

Comments

@IvenBach
Copy link
Member

Spotted from #2760

Public Sub Temp()
    Const foo = 12, bar = 42 ' bar is not used
    MsgBox foo
End Sub

Const foo = 12, bar = 42 ' bar is not used has foo and bar both as an Integer in the Locals window. Inspection results have them coming up as ... implicitly Variant.

@Vogel612 Vogel612 added bug Identifies work items for known bugs difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. resolver Issue is easier to resolve with knowledge of the internal resolver API and the Antlr4 parse trees. labels Jan 25, 2018
@retailcoder
Copy link
Member

IOW a Const can't be an implicit Variant, and we need the resolver to infer the correct type from the assigned value.

@MDoerner
Copy link
Contributor

Infering the type could get rather complicated. In particular, it can only happen in the reference resolver. The problem is that the constant expression on the right-hand-side can contain references to other constants, possibly in different modules and possibly themselves not explicitly typed. Moreover, we will have to be able to determine the type after all implicit type conversions that might happen, e.g. due to arithmetic operators.

Basically, we will need a new compilation pass that determines the type of so far untyped constants. Moreover, we should save the information that they have been untyped so that we can show them as the results of a new NotExplicitlyTypedConstant inspection.

@Vogel612
Copy link
Member

That last one should be pretty straightforward, and we can implement a simplified version even without fixing the resolver first, since the implicit typing can be seen in the parse-tree. The Inspection could assume that all names are explicitly typed and only call out implicitly typed literals.

@Vogel612 Vogel612 added this to ToDo in Semi-automatic bug tracker via automation Jan 26, 2018
@retailcoder
Copy link
Member

This can be a difficulty-01/duckling level issue, if we postpone the resolver fix and instead simply make the implicit variant inspection ignore Const declarations.

@comintern
Copy link
Contributor

comintern commented Jul 17, 2018

For reference, from the VBA spec:

If an <untyped-name-const-item> does not include a <const-as-clause>, the declared type of
the constant is the same as the declared type of its <constant-expression> element. Otherwise,
the constant’s declared type is the declared type of the <BUILTIN-TYPE> element of the <const-asclause>.

Note this this also needs to be aware of type hints:

Public Sub Temp()
    Const foo = 12&
    Const bar = 12
    Const baz& = 12     '<--No inspection result.
    MsgBox TypeName(foo)    'Long
    MsgBox TypeName(bar)    'Integer
    MsgBox TypeName(baz)    'Long
End Sub

FWIW the type hinted constant (<typed-name-const-item>) baz& works.

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-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. resolver Issue is easier to resolve with knowledge of the internal resolver API and the Antlr4 parse trees.
Projects
Development

No branches or pull requests

5 participants