Skip to content

Type inference may cause BC30455 when inferred-type variable name matches module method name #3615

@chucker

Description

@chucker

Version Used:

Microsoft Visual Studio Enterprise 2019 Preview
Version 16.2.0 Preview 2.0
VisualStudio.16.Preview/16.2.0-pre.2.0+29006.145
Microsoft .NET Framework
Version 4.8.03752

[..]

Visual Basic Tools   3.2.0-beta2-19303-01+c9689b7ad571762df662bec55472938d18705dca

Steps to Reproduce:

  1. Create a WPF app project.
  2. Open MainWindow.xaml.vb, and replace its contents with the following:
Option Strict On
Option Infer On

Class MainWindow
    Sub Foo()
        Dim dataObject As DataObject
        For Each format In dataObject.GetFormats()

        Next
    End Sub
End Class

Expected Behavior:
This code should compile as is. format should be of type System.String.

Actual Behavior:
The compiler believes format to be an invocation of the method Microsoft.VisualBasic.Strings.Format().

It gives the error:

Error | BC30455 | Argument not specified for parameter 'Expression' of 'Public Function Format(Expression As Object, [Style As String = ""]) As String'.

It also renames format to Format (note casing) for the same reason.

Workarounds:

  • A different variable name works fine. For example, given the following, the compiler correctly recognizes the type, doesn't rename the variable, and doesn't show an error:
Dim dataObject As DataObject
For Each formatName In dataObject.GetFormats()

Next
  • Likewise, an explicit type avoids this issue:
For Each format As String In dataObject.GetFormats()

Next

Additional notes:

In an existing project, this error only started occurring after I migrated the project to the Sdk style. The full runtime is used (<VBRuntime>default</VBRuntime>).

However, in a fresh project, the error appears immediately, suggesting this may be a toolchain regression.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions