G
Guest
I guess there are many errors in current version of C# 2.0 specification.
Let's see one of many examples(I use C# Express beta 2, but think you can use
any C#2.0 compiler). So, in document
http://download.microsoft.com/downl...-48fe-9e5e-f87a44af3db9/specificationver2.doc
in section "20.1.8 Overloading in generic classes" anyone can read:
....
The following examples show overloads that are valid and invalid according
to this rule:
interface I1<T> {...}
interface I2<T> {...}
class G1<U>
{
long F1(U u); // Invalid overload, G<int> would have two
int F1(int i); // members with the same signature
void F2(U u1, U u2); // Valid overload, no type argument for U
void F2(int i, string s); // could be int and string simultaneously
void F3(I1<U> a); // Valid overload
void F3(I2<U> a);
void F4(U a); // Valid overload
void F4(U[] a);
}
class G2<U,V>
{
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
void F7(U u1, I1<V> v2); // Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
void F8(ref U u); // Invalid overload
void F8(out V v);
}
class C1 {...}
class C2 {...}
class G3<U,V> where U: C1 where V: C2
{
void F9(U u); // Invalid overload, constraints on U and V
void F9(V v); // are ignored when checking overloads
}
Ok, let's take class G2 and interface I1 only
interface I1<T> {...}
....
class G2<U,V>
{
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
void F7(U u1, I1<V> v2); // Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
void F8(ref U u); // Invalid overload
void F8(out V v);
}
and analyze its comments:
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
/*/
Correct, but ONLY if we create something like G2<int,int> AND(exactly AND,
just fact of creating G2<int,int> is OK) if we try call F5. If we create
G2<int, long> and call g2instance.F5((long)4, 8) all fine.
Conclusion: semi-error. In most cases this overload IS valid.
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
/*/
Incorrect, I1<int> and int are different types and they occupy different
positions in "left-to-right-order" within parameters-list.
Conclusion: Error. This is 100% valid overload.
void F7(U u1, I1<V> v2);// Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
/*/
Conclusion: Absolutely correct. This is 100% valid overload
void F8(ref U u); // Invalid overload
void F8(out V v);
/*/
Incorrect, the ref and out modifiers ARE PART of a method's signature
Conclusion: Error. This is 100% valid overload.
Grand total: 4 assertions, 3 errors!! Am I right?
Let's see one of many examples(I use C# Express beta 2, but think you can use
any C#2.0 compiler). So, in document
http://download.microsoft.com/downl...-48fe-9e5e-f87a44af3db9/specificationver2.doc
in section "20.1.8 Overloading in generic classes" anyone can read:
....
The following examples show overloads that are valid and invalid according
to this rule:
interface I1<T> {...}
interface I2<T> {...}
class G1<U>
{
long F1(U u); // Invalid overload, G<int> would have two
int F1(int i); // members with the same signature
void F2(U u1, U u2); // Valid overload, no type argument for U
void F2(int i, string s); // could be int and string simultaneously
void F3(I1<U> a); // Valid overload
void F3(I2<U> a);
void F4(U a); // Valid overload
void F4(U[] a);
}
class G2<U,V>
{
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
void F7(U u1, I1<V> v2); // Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
void F8(ref U u); // Invalid overload
void F8(out V v);
}
class C1 {...}
class C2 {...}
class G3<U,V> where U: C1 where V: C2
{
void F9(U u); // Invalid overload, constraints on U and V
void F9(V v); // are ignored when checking overloads
}
Ok, let's take class G2 and interface I1 only
interface I1<T> {...}
....
class G2<U,V>
{
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
void F7(U u1, I1<V> v2); // Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
void F8(ref U u); // Invalid overload
void F8(out V v);
}
and analyze its comments:
void F5(U u, V v); // Invalid overload, G2<int,int> would have
void F5(V v, U u); // two members with the same signature
/*/
Correct, but ONLY if we create something like G2<int,int> AND(exactly AND,
just fact of creating G2<int,int> is OK) if we try call F5. If we create
G2<int, long> and call g2instance.F5((long)4, 8) all fine.
Conclusion: semi-error. In most cases this overload IS valid.
void F6(U u, I1<V> v); // Invalid overload, G2<I1<int>,int> would
void F6(I1<V> v, U u); // have two members with the same signature
/*/
Incorrect, I1<int> and int are different types and they occupy different
positions in "left-to-right-order" within parameters-list.
Conclusion: Error. This is 100% valid overload.
void F7(U u1, I1<V> v2);// Valid overload, U cannot be V and I1<V>
void F7(V v1, U u2); // simultaneously
/*/
Conclusion: Absolutely correct. This is 100% valid overload
void F8(ref U u); // Invalid overload
void F8(out V v);
/*/
Incorrect, the ref and out modifiers ARE PART of a method's signature
Conclusion: Error. This is 100% valid overload.
Grand total: 4 assertions, 3 errors!! Am I right?