PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET Template parameter deduction and with overloaded methods.

Reply

Template parameter deduction and with overloaded methods.

 
Thread Tools Rate Thread
Old 21-12-2005, 01:53 PM   #1
Andreas Mueller
Guest
 
Posts: n/a
Default Template parameter deduction and with overloaded methods.


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

----
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net
  Reply With Quote
Old 22-12-2005, 07:03 PM   #2
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: Template parameter deduction and with overloaded methods.

Andreas,

"Andreas Mueller" <me@privacy.net> schrieb:
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

  Reply With Quote
Old 22-12-2005, 07:45 PM   #3
Andreas Mueller
Guest
 
Posts: n/a
Default Re: Template parameter deduction and with overloaded methods.

Herfried K. Wagner [MVP] wrote:

> Andreas,
>
> "Andreas Mueller" <me@privacy.net> schrieb:
>
>> 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.
>

That's what I thought.
Logged it, DID FDBK42807
CU, Andy

--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net
  Reply With Quote
Old 22-12-2005, 07:59 PM   #4
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: Template parameter deduction and with overloaded methods.

"Andreas Mueller" <me@privacy.net> schrieb:
> Logged it, DID FDBK42807


It seems that you have forgotten to upload the attachment.

<URL:http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=07751a75-a700-45b1-af3b-8751afcc7779>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

  Reply With Quote
Old 22-12-2005, 08:34 PM   #5
Andreas Mueller
Guest
 
Posts: n/a
Default Re: Template parameter deduction and with overloaded methods.

Herfried K. Wagner [MVP] wrote:

> "Andreas Mueller" <me@privacy.net> schrieb:
>
>> Logged it, DID FDBK42807

>
>
> It seems that you have forgotten to upload the attachment.
>
> <URL:http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=07751a75-a700-45b1-af3b-8751afcc7779>
>
>

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

--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net
  Reply With Quote
Old 22-12-2005, 08:57 PM   #6
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: Template parameter deduction and with overloaded methods.

Andreas,

"Andreas Mueller" <me@privacy.net> schrieb:
>>> Logged it, DID FDBK42807

>>
>> It seems that you have forgotten to upload the attachment.
>>
>> <URL:http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=07751a75-a700-45b1-af3b-8751afcc7779>

> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off