C# 2.0 spec: generics and invalid overloads

H

Harold Howe

According to the C# 2.0 draft spec, the following should not compile:

class G1<U>
{
long F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

However, it compiles without error or warning for me. This also compiles
clean:

class G1<U>
{
int F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

Did the spec change on this? Is this now allowed? The version of the
spec that I downloaded was from May 2004.

FWIW, compiler version is
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727

H^2
 
T

Tom Porterfield

Harold said:
According to the C# 2.0 draft spec, the following should not compile:

class G1<U>
{
long F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

However, it compiles without error or warning for me. This also compiles
clean:

class G1<U>
{
int F1(U u) {return 0;} // Invalid overload, G<int> would have two
int F1(int i){return 1;} // members with the same signature
}

Did the spec change on this? Is this now allowed? The version of the
spec that I downloaded was from May 2004.

FWIW, compiler version is
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727

See section 20.1.8 of the currrent C# language specification 2.0 in the
March 2005 draft available from
http://download.microsoft.com/downl...e5e-f87a44af3db9/CSharp 2.0 Specification.doc.
Basically it is valid and will be resolved to the non-generic overload of
the method.
 

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

Similar Threads


Top