Open bandleader opened 5 years ago
This not being caught at compile-time seems to be an Option-Strict-Off gotcha.
With Option Strict off, the inner literal, lacking a target type, is typed as Object()
without complaint; with Option Strict on, the code does not compile because assuming Object
for element type is disallowed.
This appears to be a more general problem of array literals failing to find a target type in many situations, such as when parenthesized or when used as an operand in an infix operator expression (method-style operator invocations behave like regular method calls).
Current behavior of similar constructs:
AddressOf
works when parenthesized, but not in infix operator invocations (possibly another bug), failing to compile with BC30491: Expression does not produce a value.
, e.g.:
Class A
Shared Sub Main()
Dim i = A.op_Addition(New A(), AddressOf Console.Writeline) ' Compiles.
Dim j = New A() + AddressOf Console.Writeline ' BC30491.
End Sub
Shared Operator +(x As A, y As Action) As Integer
End Operator
End Class
Version Used: VS2015
Code to Reproduce: (also available in fiddle)
Expected Behavior: Type inference should type the RHS of the expression {({})} as declared on the left side:
String()()
i.e. an array of an array of String.Actual Behavior: The outer array
{ ... }
on the RHS is correctly typed asString()
like on the LHS, but the inner array({})
is incorrectly typed asObject()
, which results in the error message above.(Also, this is not caught at compile-time, only at runtime, which just crashed our production app.)
Further reference: https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/arrays/how-to-initialize-an-array-variable#to-initialize-a-jagged-array-variable-by-using-array-literals