473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Errors in C# 2.0 specification?

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/downlo...cationver2.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?
Nov 17 '05 #1
11 1714

"Smarty" <Sm****@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
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/downlo...cationver2.doc
in section "20.1.8 Overloading in generic classes" anyone can read:
...

You refer to an old draft of the specs, you posted the question on another
thread but you picked the wrong answer and downloaded an old draft of the
specification.
Also note this NG is for released products only, You should post v2.0 beta
questions/issues to the whidbey forums http://forums.microsoft.com/msdn/ and
if you think you found a bug (product, docs etc...) you should file an issue
to http://lab.msdn.microsoft.com/produc...k/default.aspx.

Willy.

Nov 17 '05 #2
> 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.

Sorry, but if one situation comes up where it is not valid, the overload
cannot be valid. This is correct.
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.
Incorrect again. You made a mistake in reading this. Consider G2<I1<int>,
int> again, notice that you result in
void F6(I1<int>,I1<int>) for void F6(U u, I1<V> v)
and
void F6(I1<int>,I1<int>) for for void F6(I1<V>, U u);

as U is I1<int> and V is int

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.


Actually, the language doesn't permit that in any circumstance, so its not
valid on its face. ref and out generate identical method signatures at the
CLR level, with ref or out one being marked by an attribute.
Nov 17 '05 #3

"Willy Denoyette [MVP]" wrote:

You refer to an old draft of the specs, you posted the question on another
thread but you picked the wrong answer and downloaded an old draft of the
specification.
Also note this NG is for released products only, You should post v2.0 beta
questions/issues to the whidbey forums http://forums.microsoft.com/msdn/ and
if you think you found a bug (product, docs etc...) you should file an issue
to http://lab.msdn.microsoft.com/produc...k/default.aspx.

Willy.

OK, thanks. I will try this approach.
Nov 17 '05 #4
"Daniel O'Connell [C# MVP]" wrote:
Sorry, but if one situation comes up where it is not valid, the overload
cannot be valid. This is correct.
H-m-m... May be. But think it should be marked plain - "not valid in
exactly(and only) one situation..."
Incorrect again. You made a mistake in reading this. Consider G2<I1<int>,
int> again, notice that you result in
void F6(I1<int>,I1<int>) for void F6(U u, I1<V> v)
and
void F6(I1<int>,I1<int>) for for void F6(I1<V>, U u);
Yes, this is entirely my fault. I check this code against G2<int, int>, but
comments say G2<I1<int>, int>. So this fragment really correct.
Actually, the language doesn't permit that in any circumstance, so its not
valid on its face. ref and out generate identical method signatures at the
CLR level, with ref or out one being marked by an attribute.


Let's say simple - ref/out ARE PART of a method's signature or they are NOT?
Small snippet:

using System;

class Test
{
class G2<U, V>
{
public void F8(ref U u) { Console.WriteLine("F8 with ref"); }
public void F8(out V v) { Console.WriteLine("F8 with out"); v =
default(V); }
}

class App
{
static void Main()
{
G2<int, int> g2a = new G2<int, int>();
int i = 7;
g2a.F8(ref i);
g2a.F8(out i);
}
}
}

Nov 17 '05 #5

"Smarty" <Sm****@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
"Daniel O'Connell [C# MVP]" wrote:
Sorry, but if one situation comes up where it is not valid, the overload
cannot be valid. This is correct.


H-m-m... May be. But think it should be marked plain - "not valid in
exactly(and only) one situation..."
Incorrect again. You made a mistake in reading this. Consider G2<I1<int>,
int> again, notice that you result in
void F6(I1<int>,I1<int>) for void F6(U u, I1<V> v)
and
void F6(I1<int>,I1<int>) for for void F6(I1<V>, U u);


Yes, this is entirely my fault. I check this code against G2<int, int>,
but
comments say G2<I1<int>, int>. So this fragment really correct.
Actually, the language doesn't permit that in any circumstance, so its not
valid on its face. ref and out generate identical method signatures at the
CLR level, with ref or out one being marked by an attribute.


Let's say simple - ref/out ARE PART of a method's signature or they are
NOT?
Small snippet:

using System;

class Test
{
class G2<U, V>
{
public void F8(ref U u) { Console.WriteLine("F8 with ref"); }
public void F8(out V v) { Console.WriteLine("F8 with out"); v =
default(V); }
}

class App
{
static void Main()
{
G2<int, int> g2a = new G2<int, int>();
int i = 7;
g2a.F8(ref i);
g2a.F8(out i);
}
}
}


The latest and final draft has corrected this,

void F8(ref U u) {...}
void F8(out V v) {....}

are valid overloads.
Willy.

Nov 17 '05 #6

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Om****************@tk2msftngp13.phx.gbl...

"Smarty" <Sm****@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
"Daniel O'Connell [C# MVP]" wrote:
Sorry, but if one situation comes up where it is not valid, the overload
cannot be valid. This is correct.


H-m-m... May be. But think it should be marked plain - "not valid in
exactly(and only) one situation..."
Incorrect again. You made a mistake in reading this. Consider G2<I1<int>,
int> again, notice that you result in
void F6(I1<int>,I1<int>) for void F6(U u, I1<V> v)
and
void F6(I1<int>,I1<int>) for for void F6(I1<V>, U u);


Yes, this is entirely my fault. I check this code against G2<int, int>,
but
comments say G2<I1<int>, int>. So this fragment really correct.
Actually, the language doesn't permit that in any circumstance, so its
not
valid on its face. ref and out generate identical method signatures at
the
CLR level, with ref or out one being marked by an attribute.


Let's say simple - ref/out ARE PART of a method's signature or they are
NOT?
Small snippet:

using System;

class Test
{
class G2<U, V>
{
public void F8(ref U u) { Console.WriteLine("F8 with ref"); }
public void F8(out V v) { Console.WriteLine("F8 with out"); v =
default(V); }
}

class App
{
static void Main()
{
G2<int, int> g2a = new G2<int, int>();
int i = 7;
g2a.F8(ref i);
g2a.F8(out i);
}
}
}


The latest and final draft has corrected this,

void F8(ref U u) {...}
void F8(out V v) {....}

are valid overloads.


That is troubling, it really is. The compiler has, to this point, disallowed

F8 (ref int x)
F8 (out int x)

why would it be allowed in this case if V and U are not constrained to be
mutually exclusive in some way? Did the spec change to allow overloading by
ref and out in all methods(I don't think this would even work cleanly)?

While I suppose it is possible to achieve techincally with generics, it
still seems to be quite inconsistent.
Nov 17 '05 #7

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:ej****************@TK2MSFTNGP09.phx.gbl...

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Om****************@tk2msftngp13.phx.gbl...

"Smarty" <Sm****@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
"Daniel O'Connell [C# MVP]" wrote:

Sorry, but if one situation comes up where it is not valid, the overload
cannot be valid. This is correct.

H-m-m... May be. But think it should be marked plain - "not valid in
exactly(and only) one situation..."

Incorrect again. You made a mistake in reading this. Consider
G2<I1<int>,
int> again, notice that you result in
void F6(I1<int>,I1<int>) for void F6(U u, I1<V> v)
and
void F6(I1<int>,I1<int>) for for void F6(I1<V>, U u);

Yes, this is entirely my fault. I check this code against G2<int, int>,
but
comments say G2<I1<int>, int>. So this fragment really correct.

Actually, the language doesn't permit that in any circumstance, so its
not
valid on its face. ref and out generate identical method signatures at
the
CLR level, with ref or out one being marked by an attribute.

Let's say simple - ref/out ARE PART of a method's signature or they are
NOT?
Small snippet:

using System;

class Test
{
class G2<U, V>
{
public void F8(ref U u) { Console.WriteLine("F8 with ref"); }
public void F8(out V v) { Console.WriteLine("F8 with out"); v =
default(V); }
}

class App
{
static void Main()
{
G2<int, int> g2a = new G2<int, int>();
int i = 7;
g2a.F8(ref i);
g2a.F8(out i);
}
}
}


The latest and final draft has corrected this,

void F8(ref U u) {...}
void F8(out V v) {....}

are valid overloads.


That is troubling, it really is. The compiler has, to this point,
disallowed

F8 (ref int x)
F8 (out int x)

why would it be allowed in this case if V and U are not constrained to be
mutually exclusive in some way? Did the spec change to allow overloading
by ref and out in all methods(I don't think this would even work cleanly)?

While I suppose it is possible to achieve techincally with generics, it
still seems to be quite inconsistent.


You are right, it is inconsistent, and IMO it's wrong. It looks like the
inference process (wrongly) considers ref/out as part of the signature and
picks the best method and as such by-passing overload resolution which would
throw an "ambiguity" error.

Do you file a bug on Ladybug, or shall I?

Willy.


Nov 17 '05 #8
"Willy Denoyette [MVP]" wrote:


The latest and final draft has corrected this,

void F8(ref U u) {...}
void F8(out V v) {....}

are valid overloads.
Willy.


Yes, you are totally right. But when I wrote my very first question I had
"May,2004" version only. Now this moment resolved, at last. Thanks for your
participation!

Nov 17 '05 #9
"Willy Denoyette [MVP]" wrote:
That is troubling, it really is. The compiler has, to this point,
disallowed

F8 (ref int x)
F8 (out int x)

why would it be allowed in this case if V and U are not constrained to be
mutually exclusive in some way? Did the spec change to allow overloading
by ref and out in all methods(I don't think this would even work cleanly)?

While I suppose it is possible to achieve techincally with generics, it
still seems to be quite inconsistent.


You are right, it is inconsistent, and IMO it's wrong. It looks like the
inference process (wrongly) considers ref/out as part of the signature and
picks the best method and as such by-passing overload resolution which would
throw an "ambiguity" error.

Do you file a bug on Ladybug, or shall I?

Willy.


I think there is no contradiction with specification(latest version) which
say:
While signatures _as declared_(i.e. F8 (ref/out int x) case) must be unique,
it is possible that _substitution of type arguments_(i.e. G2<U, V> case)
results in _identical_(!) signatures. The tie-breaking rules of overload
resolution will pick the most specific one.

The game going by the rules.
Nov 17 '05 #10

"Smarty" <Sm****@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
"Willy Denoyette [MVP]" wrote:
> That is troubling, it really is. The compiler has, to this point,
> disallowed
>
> F8 (ref int x)
> F8 (out int x)
>
> why would it be allowed in this case if V and U are not constrained to
> be
> mutually exclusive in some way? Did the spec change to allow
> overloading
> by ref and out in all methods(I don't think this would even work
> cleanly)?
>
> While I suppose it is possible to achieve techincally with generics, it
> still seems to be quite inconsistent.
>
>


You are right, it is inconsistent, and IMO it's wrong. It looks like the
inference process (wrongly) considers ref/out as part of the signature
and
picks the best method and as such by-passing overload resolution which
would
throw an "ambiguity" error.

Do you file a bug on Ladybug, or shall I?

Willy.


I think there is no contradiction with specification(latest version) which
say:
While signatures _as declared_(i.e. F8 (ref/out int x) case) must be
unique,
it is possible that _substitution of type arguments_(i.e. G2<U, V> case)
results in _identical_(!) signatures. The tie-breaking rules of overload
resolution will pick the most specific one.

The game going by the rules.


That's right, I was reading through the new specs today and it's also
confirmed by Rick Byers (MSFT), the specs and the compiler are conform the
changes made after Beta1.
Case closed :-)

Willy.

Nov 17 '05 #11
>> I think there is no contradiction with specification(latest version)
which
say:
While signatures _as declared_(i.e. F8 (ref/out int x) case) must be
unique,
it is possible that _substitution of type arguments_(i.e. G2<U, V> case)
results in _identical_(!) signatures. The tie-breaking rules of overload
resolution will pick the most specific one.

The game going by the rules.
That's right, I was reading through the new specs today and it's also
confirmed by Rick Byers (MSFT), the specs and the compiler are conform the
changes made after Beta1.
Case closed :-)


Glad there is an answer atleast, ;). I still think its troublingly
inconsistent, but not that big of a deal. Willy.

Nov 17 '05 #12

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

Similar topics

0
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to...
0
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to...
0
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to...
14
by: Brandon | last post by:
I am an amateur working on a first site, I have settled on using FP 2002 for now. My current page is up and live, but I have two errors that I cant seem to get rid of ... Line 29, column 6:...
0
by: Jerry | last post by:
In MS Access 2000, I'm trying to export a table from a Macro and I get an error that reads "Cannot update. Database or object is read-only". I'm using an export specification that I know is...
17
by: Rick Brandt | last post by:
We are using a JS popup calendar in our pages and find that we get various JS errors whenever we call the code from an HTML page that includes a DOCTYPE. The specific type doesn't seem to matter. ...
7
seligerasmus
by: seligerasmus | last post by:
Greetings! My scenario is such - I'm wrapping a Java web service around a set of RPG programs that live on one of my company's i-Series (AS/400) midrange computers. To faciltate the connectivity...
4
by: Dan | last post by:
Hi All, I've got a problem with my C++ application that calls a Java class that I've built with GCJ, I can't run it because I get errors: multiple definition of `atexit' first defined here...
8
by: bradyounie | last post by:
I have a C++ COM project that was created with Visual C++ 6. I have just converted the project to Visual Studio 2005 and have been trying to build it. I get the following compile errors: warning...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.