mrmarktwo

In chapter 20.6.5 of the language spec it states that the following statement:-

F (G < A, B >> 7);

should be interpreted as a call to F with 2 arguments. ie 1st argument is G < A,
2nd argument is B >> 7

However when you compile such a statement you get the error

error CS0019: Operator '>' cannot be applied to operands of type 'method group' and 'int'

which implies the compiler is treating the call to F as 1 argument ie G<A,B> > 7
Below is a silly example proving the point:-

public class DoATest<A> where A : class
{
class B { };

public void SomeTest()
{
// Line as in 20.6.5 of language spec
// error CS0019: Operator '>' cannot be applied to operands of type 'method group'
// and 'int'
// Of course if compiler treated this as 2 arguments we would get a different error
F (G < A, B >> 7);
}

public A G<A, B>(int b) where A : class
{
return default(A);
}

public void F(A c)
{
}
}

Any thoughts



Re: Visual C# Language Compiler Issue?

Peter Ritchie

In the spec, it assumes you've defined a variable G, not a method; as you have.




Re: Visual C# Language Compiler Issue?

mrmarktwo

I dont agree - the compiler determines whether it is 1 or 2 arguments during parsing (as stated in 20.6.5) when it has no idea what G is. The idea is that only 1 parse tree is generated in any given situation, and then deciding if it's semantically correct.








Re: Visual C# Language Compiler Issue?

Peter Ritchie

Using a variable G still causes problems. I think you've found a bug...

I believe you've referenced the C# 1.0 spec, not the C# 2.0 spec. Section 9.2.3 of the C# 2.0 references the call to F that you mention.




Re: Visual C# Language Compiler Issue?

mrmarktwo

I'm looking at C# 2.0 - yes it's section 9.2.3 in the ecma spec document but is
section 20.6.5 in the The C# Programming Language Second Edition book.
I think it's either a compiler bug or the language spec is wrong.Of course even if the compiler treated the call as having 2 arguments the code is semantically rubbish!








Re: Visual C# Language Compiler Issue?

Peter Ritchie

section 20.6.3 was pre-generics. Generics opens a whole new can of worms with regard to '<' and '>'. But, the following causes errors:
namespace TestProgam
{
using System;

class Program
{
private static void F( bool a, int b )
{
}

[STAThread]
static void Main ( string[] args )
{
int G = 1;
int B = 2;
int A = 3;
F(G<A, B>>7); // copied from ECMA 334
}
}
}
So, I've escalated it to the C# team.

If you're looking for a workaround:

bool t1 = G<A;
F(t1, B>>7);






Re: Visual C# Language Compiler Issue?

Peter Ritchie

Hi mrmarktwo. This issue has been found. It was found shortly after Visual C# 2005 shipped. A fix has been implemented in the next release of Visual Studio (Orcas). You can download the latest CTP ("January" 2007 CTP) for Orcas here: http://blogs.msdn.com/charlie/archive/2007/01/11/january-orcas-ctp-now-available.aspx




Re: Visual C# Language Compiler Issue?

mrmarktwo

OK Thanks