Template parameter deduction and with overloaded methods.

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
 
H

Herfried K. Wagner [MVP]

Andreas,

Andreas Mueller said:
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?

I think this is a bug, because the chapter about overload resolution in the
language specification states that two methods with the same signature
due to type parameters should choose the less generic overload.

I suggest to file a bug report at
<URL:http://lab.msdn.microsoft.com/productfeedback/>. If you do not file
the bug in the next few days I'll submit a bug report on this issue.
 
A

Andreas Mueller

Herfried said:
Andreas,




I think this is a bug, because the chapter about overload resolution in
the language specification states that two methods with the same signature
due to type parameters should choose the less generic overload.

I suggest to file a bug report at
<URL:http://lab.msdn.microsoft.com/productfeedback/>. If you do not
file the bug in the next few days I'll submit a bug report on this issue.
That's what I thought.
Logged it, DID FDBK42807
CU, Andy
 
H

Herfried K. Wagner [MVP]

Andreas,

Andreas Mueller said:
ok, should be in now. looks like I just browsed for it and didn't hit the
attach button :-(

Thanks very much. I have validated the bug and voted for it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top