| « More about generics | Experiences concerning software book writing » |
unexpected C#2 ambiguity
While reading the excellent book 'The C# Programming Language', I just found a somewhat unexpected point in the C#2 grammar. As illustrated by the following example, characters '<' and '>' can sometime be interpreted both as comparison operators and as beginning and ending of a types parameter list.
class C<U,V> { public static void Fct1() { int U = 6; int V = 7; int Fct2 = 9; Fct3(Fct2<U, V>(20)); // call Fct3(int) Fct3(Fct2<U, V>20); // call Fct3(bool,bool) } public static int Fct2<A, B>(int i) { return 0;} public static void Fct3(int i) { return; } public static void Fct3(bool b1, bool b2) { return; } } class Program { static void Main(string[] args) { } }
This dilemma is solved by the following rule: if the character that follows the '>' character is in the following list, then the compiler choose the type parameter list case.
( ) ] > : ; , . ?
8 comments
Comment from: Bertrand Le Roy [Visitor] · http://weblogs.asp.net/bleroy
Funny, but as is often the case with ambiguities like this, you really have to get out of your way and write bad code to actually hit it.
Who would write the second call without additional parentheses?
It's still interesting as it shows all the edge cases a compiler has to handle, even if no one in his right mind would write this kind of code.
Who would write the second call without additional parentheses?
It's still interesting as it shows all the edge cases a compiler has to handle, even if no one in his right mind would write this kind of code.
11/03/04 @ 02:42
Comment from: verge [Visitor] · http://blackjack.casinotrixx.com/blackjack-and-truck/
http://diet.chilympiad.org/surgery_weight_loss/ garyhoodlumnow
07/24/05 @ 22:58
Comment from: toyed [Visitor] · http://finance.company-si.com/3ozwizxc/
http://trading.stock-a.com/d26rjc8i/ discoveredexplicitjaw
07/29/05 @ 11:02
Comment from: street [Visitor] · http://www.denrer.com/kings/
http://www.stratpoker.com/o37ar5aym/ chokedeyeslifting
08/04/05 @ 08:53
Comment from: intention [Visitor] · http://diazepam.twinstatesnetwork.org/i4n3po/
http://ritalin.twinstatesnetwork.org/adipex/ medicaloccupyworkload
08/13/05 @ 18:06
Comment from: sown [Visitor] · http://back.hollywoodtheater.org/652029/
http://gold.hollywoodtheater.org/71580528796/ cliffsgroggilykeys
08/23/05 @ 21:49
Comment from: france [Visitor] · http://makemoney.americasparty.org/ljiys/
http://hawaii.acfair.org/c8y6uqz/ concernhorrifyingsharing
08/25/05 @ 01:47
Comment from: sadistic [Visitor] · http://www.mentorsverige.org/0072569/
http://businessinsurance.mentorsverige.org/z4hdjs1/ beckonframedrotating
08/26/05 @ 06:00
Comments are closed for this post.