Rubberduck: Inspection result for use of untyped Mid function for Mid statement

Created on 3 Jul 2017  路  5Comments  路  Source: rubberduck-vba/Rubberduck

Mid statements trigger the inspection for the use of the untyped Mid function.

Public Sub Test()
    Mid(foo,3,1) = bar
End Sub

Moreover, the quickfix _fixes_ the issue.

Public Sub Test()
    Mid$(foo,3,1) = bar
End Sub
difficulty-02-ducky enhancement feature-inspections

Most helpful comment

After consulting the specification, I have to say that the issue is smaller then I thought. There is actually a Mid$ statement, which does exactly the same as the Mid statement. (The same is true for the MidB and MidB$' statements.)

So, it is only that the inspection result is redundant and the inspection result text slightly wrong in this situation. The quickfix does no harm.

All 5 comments

It boils down to an overzealous inspection that does not exclude the LHS when finding inspections, right? The solution in this case is to adjust the Where-Clause in UntypedFunctionUsageInspection to correctly exclude left-hand sides

@Vogel612 that would do. In theory a statement doesn't need to be on either side though; so the inspection should trigger for RHS only.

I don't think the quickfix needs any modification; it just does as it's told. No inspection result, no quickfix.

After consulting the specification, I have to say that the issue is smaller then I thought. There is actually a Mid$ statement, which does exactly the same as the Mid statement. (The same is true for the MidB and MidB$' statements.)

So, it is only that the inspection result is redundant and the inspection result text slightly wrong in this situation. The quickfix does no harm.

Should we modify the description and replace "function" with "statement"?

@retailcoder No, I think we should not change the description because this inspection deals with all usages of untyped aliased functions, in particular also with the Mid _function_.

Since the Mid statement and the Mid$ do _exactly_ the same thing, there is no need to report the usage of a Mid statement. Moreover, it is a statement and not a function; the inspections should not apply in this case.

Either the inspection is listening for the MID token and does not verify that it is looking at a reference to the Mid function or the resolver does not correctly reolve this, i.e. it thinks that MID in a Mid statement is a function call.

Was this page helpful?
0 / 5 - 0 ratings