A
Andreas Mueller
Hi All,
I have an overloaded generic method anmed "Foo":
Class Test
Class Xox(Of T)
End Class
Class Lulli(Of T)
Inherits Xox(Of T)
End Class
Overloads Shared Function Foo(Of T, Iter As Xox(Of T))(ByVal x As
Iter, ByVal tt As T) As Iter
Return x
End Function
Overloads Shared Function Foo(Of T)(ByVal l As Lulli(Of T), ByVal
tt As T) As Lulli(Of T)
Return l
End Function
Shared Sub Main()
Dim xox As New Xox(Of Integer)
Dim lulli As New Lulli(Of Integer)
Dim xx As Xox(Of Integer) = Foo(xox, 42)
' gives a BC30521 error
'Dim ll As Lulli(Of Integer) = Foo(lulli, 42)
End Sub
End Class
When I try to access the second overload, the compiler does not seem to
be able to find the correct method (BC30521). Explicitly declaring the
generic parameters solves the problem:
Dim ll As Lulli(Of Integer) = _
Foo(Of Integer, Lulli(Of Integer))(lulli, 42)
It look like the compiler can't deduct the generic arguments to find the
correct overload.
As this works from C#, I'm asking myself if this "as designed" or a bug
of the VB compiler?
TIA,
Andy
I have an overloaded generic method anmed "Foo":
Class Test
Class Xox(Of T)
End Class
Class Lulli(Of T)
Inherits Xox(Of T)
End Class
Overloads Shared Function Foo(Of T, Iter As Xox(Of T))(ByVal x As
Iter, ByVal tt As T) As Iter
Return x
End Function
Overloads Shared Function Foo(Of T)(ByVal l As Lulli(Of T), ByVal
tt As T) As Lulli(Of T)
Return l
End Function
Shared Sub Main()
Dim xox As New Xox(Of Integer)
Dim lulli As New Lulli(Of Integer)
Dim xx As Xox(Of Integer) = Foo(xox, 42)
' gives a BC30521 error
'Dim ll As Lulli(Of Integer) = Foo(lulli, 42)
End Sub
End Class
When I try to access the second overload, the compiler does not seem to
be able to find the correct method (BC30521). Explicitly declaring the
generic parameters solves the problem:
Dim ll As Lulli(Of Integer) = _
Foo(Of Integer, Lulli(Of Integer))(lulli, 42)
It look like the compiler can't deduct the generic arguments to find the
correct overload.
As this works from C#, I'm asking myself if this "as designed" or a bug
of the VB compiler?
TIA,
Andy