473,811 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.n et
Dec 21 '05 #1
5 2040
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.micros oft.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/>

Dec 22 '05 #2
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.micros oft.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.n et
Dec 22 '05 #3
"Andreas Mueller" <me@privacy.net > schrieb:
Logged it, DID FDBK42807


It seems that you have forgotten to upload the attachment.

<URL:http://lab.msdn.micros oft.com/productfeedback/viewfeedback.as px?feedbackid=0 7751a75-a700-45b1-af3b-8751afcc7779>

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

Dec 22 '05 #4
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.micros oft.com/productfeedback/viewfeedback.as px?feedbackid=0 7751a75-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.n et
Dec 22 '05 #5
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.micros oft.com/productfeedback/viewfeedback.as px?feedbackid=0 7751a75-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/>

Dec 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2222
by: Chris Johnson | last post by:
Greetings all: I come across an interesting question (to me anyway) and I do not know the answer. Code/Questions follow: #include <iostream> #if 0 // uncommenting *should* make call ambigous because of // odering deduction of the function signature,
5
7113
by: Arkadiy Vertleyb | last post by:
Hi all, I am having a problem trying to overload a function template, based on a typedef, such as: template<class T> struct A {}; template<class T>
3
1937
by: BigMan | last post by:
Here is a piece of code: #include <memory> using namespace std; template< typename SomeType > void f(auto_ptr_ref< SomeType >) { }
3
2039
by: CoolPint | last post by:
After upgrading to gcc 3.4.2 from gcc 3.2.3, I got compiler errors that I could not figure out. After reading other postings, I learned that my coding was not compliant to the standard in the first place and I did fix many of them, especially with the proper use of the keyword "typename". But I have one problem I have no idea how to fix. I created below a simpler coding which demonstrates my problem: The coding below used to compile...
4
2582
by: Mat DeLong | last post by:
I have never been stuck on programming something before to the point I give up... this is a first. I am programming what should be something very easy in C++... using Templates. Here is the code, and the error I get: -------------- namespace LIST { template <typename T> struct Link; template <typename T> class List;
4
2568
by: Neelesh | last post by:
Hi all, I had some confusion about deduction of non-type template parameters for function templates : template <class T, int i> void foo (T, int p = i) ; void bar() { foo<int, 10>(40,40); // OK, T = int, i = 10 foo(40,40); // ERROR, T = int but i cannot be deduced.
2
2377
by: coolpint | last post by:
Can anyone kindly provide an explanation as to why the compiler does not "see" the function template in the contrieved code below? I think the argument deduction fails but can't figure out exactly what the problem is. Is it related to the fact that a nested class is involved? #include <iostream> using std::cout;
0
1248
by: Fei Liu | last post by:
Hello, We all know that a template function can automatically deduce its parameter type and instantiate, e.g. template <tpyename T> void func(T a); func(0.f); This will cause func<floatto be instantiated. The user does not have
3
3585
by: Fei Liu | last post by:
Hello, We all know that a template function can automatically deduce its parameter type and instantiate, e.g. template <tpyename T> void func(T a); func(0.f); This will cause func<floatto be instantiated. The user does not have
0
9724
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10394
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.