473,394 Members | 1,951 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,394 software developers and data experts.

Bug in C# 2.0 compiler?

>From rsdn.ru forum http://rsdn.ru/Forum/Message.aspx?mid=2454202.

When i try to compile something like this with c# 2.0 compiler there
is a compile time error.

class Foo {
public int F(bool a, int b)
{
return 2;
}

public void runTest()
{
int a = 5;
int b = 6;
int c = 7;

int blah = F(a<b, c >2);// compilation error :)
Console.WriteLine("Blah = " + blah);
}
}

It occurs only when i use "less than"operator.
But if conclude "a<b" expression into round brackets "(a<b)" error
will not occur. Is "less then operator reloaded or this is compiller
bug?

Apr 19 '07 #1
9 1192
I understand, that comiller perceives this expression like generic
type, but is it ok or not?
Apr 19 '07 #2
ev*******@gmail.com wrote:
>From rsdn.ru forum http://rsdn.ru/Forum/Message.aspx?mid=2454202.

When i try to compile something like this with c# 2.0 compiler there
is a compile time error.

class Foo {
public int F(bool a, int b)
{
return 2;
}

public void runTest()
{
int a = 5;
int b = 6;
int c = 7;

int blah = F(a<b, c >2);// compilation error :)
Console.WriteLine("Blah = " + blah);
}
}

It occurs only when i use "less than"operator.
But if conclude "a<b" expression into round brackets "(a<b)" error
will not occur. Is "less then operator reloaded or this is compiller
bug?
It's an ambiguity in the grammar for C#. Unless there's a specific
disambiguation rule stated in the language spec that says this should be
interpreted as a non-generic, then you just have to use parentheses to
disambiguate the code.

I don't have the C# 2.0 language grammar/spec handy, but my guess is that
it's not technically a compiler bug but rather something that the language
spec leaves unspecified.

-cd
Apr 19 '07 #3
ev*******@gmail.com <ev*******@gmail.comwrote:

<snip>
It occurs only when i use "less than"operator.
But if conclude "a<b" expression into round brackets "(a<b)" error
will not occur. Is "less then operator reloaded or this is compiller
bug?
Yes, it is a compiler bug, I believe. In fact, the spec (section 9.2.3)
has your example, modulo renames etc:

<quote>
Example: The statement:
F(G<A, B>(7));
will, according to this rule, be interpreted as a call to F with one
argument, which is a call to a generic method G with two type arguments
and one regular argument. The statements
F(G<A, B>7);
F(G<A, B>>7);
will each be interpreted as a call to F with two arguments.

Your code matches the bottom statement, so should be treated as a call
to F.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 19 '07 #4
ev*******@gmail.com wrote:
>>From rsdn.ru forum http://rsdn.ru/Forum/Message.aspx?mid=2454202.

When i try to compile something like this with c# 2.0 compiler there
is a compile time error.

class Foo {
public int F(bool a, int b)
{
return 2;
}

public void runTest()
{
int a = 5;
int b = 6;
int c = 7;

int blah = F(a<b, c >2);// compilation error :)
Console.WriteLine("Blah = " + blah);
}
}

It occurs only when i use "less than"operator.
But if conclude "a<b" expression into round brackets "(a<b)" error
will not occur. Is "less then operator reloaded or this is compiller
bug?
a<b,cis a generic type - the compiler is doing exactly what it's
supposed to do (the specification does cover this, and it's clear that
this should result in a compiler error).

Alun Harford
Apr 19 '07 #5
>Is "less then operator reloaded or this is compiller bug?
Yes it's a bug. I believe it's fixed in the Orcas compiler.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 19 '07 #6
Carl Daniel [VC++ MVP]
<cp*****************************@mvps.org.nospamwr ote:
It occurs only when i use "less than"operator.
But if conclude "a<b" expression into round brackets "(a<b)" error
will not occur. Is "less then operator reloaded or this is compiller
bug?

It's an ambiguity in the grammar for C#. Unless there's a specific
disambiguation rule stated in the language spec that says this should be
interpreted as a non-generic, then you just have to use parentheses to
disambiguate the code.

I don't have the C# 2.0 language grammar/spec handy, but my guess is that
it's not technically a compiler bug but rather something that the language
spec leaves unspecified.
Fortunately, the spec *does* specify the behaviour. Unfortunately it
appears the MS compiler doesn't obey the ECMA spec. (It's possible that
the MS version of the spec, pre-ECMA, doesn't have the same rules.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 19 '07 #7
Alun Harford <de*****@alunharford.co.ukwrote:
It occurs only when i use "less than"operator.
But if conclude "a<b" expression into round brackets "(a<b)" error
will not occur. Is "less then operator reloaded or this is compiller
bug?

a<b,cis a generic type - the compiler is doing exactly what it's
supposed to do (the specification does cover this, and it's clear that
this should result in a compiler error).
It seems reasonably clear to me that it *shouldn't* result in a
compilation error. From the spec:

<quote>
The statements
F(G<A, B>7);
F(G<A, B>>7);
will each be interpreted as a call to F with two arguments.
</quote>

The "call to F with two arguments" is exactly the desired behaviour, so
the way I read the spec, the OP's code should work. Could you clarify
why you think it should produce a compilation error?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 19 '07 #8
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
>>Is "less then operator reloaded or this is compiller bug?

Yes it's a bug. I believe it's fixed in the Orcas compiler.
Mattias
Yes, this one was corrected in the Orcas compiler ( all builds of v 9.0).

Willy.

Apr 19 '07 #9
Jon Skeet [C# MVP] wrote:
Alun Harford <de*****@alunharford.co.ukwrote:
>>It occurs only when i use "less than"operator.
But if conclude "a<b" expression into round brackets "(a<b)" error
will not occur. Is "less then operator reloaded or this is compiller
bug?
a<b,cis a generic type - the compiler is doing exactly what it's
supposed to do (the specification does cover this, and it's clear that
this should result in a compiler error).

It seems reasonably clear to me that it *shouldn't* result in a
compilation error. From the spec:

<quote>
The statements
F(G<A, B>7);
F(G<A, B>>7);
will each be interpreted as a call to F with two arguments.
</quote>

The "call to F with two arguments" is exactly the desired behaviour, so
the way I read the spec, the OP's code should work. Could you clarify
why you think it should produce a compilation error?
Oops - sorry.
Yes, you're right.

Alun Harford
Apr 19 '07 #10

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

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
7
by: Tao Wang | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I saw cuj's conformance roundup, but the result is quite old. I think many people like me want to know newer c++ standard conformance test...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
6
by: toton | last post by:
Hi, Anyone have a link to comparative study of different C++ compilers and how much they conform to C++ language standard? Most of the big platforms I know have GCC which well supports C++...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.