EDIT: I insist there's no ambiguity:
In your example there's no ambiguity at all. This could never be evaluated as a List<Guid?>
. The context (the extra 10) shows the compiler how to interpret it.
var x = List<Nullable<Guid>> 10;
Would the compiler compile this?:
var x = List<Guid?> 10;
It's clear it wouldn't. So Im'm still looking for the ambiguity.
OTOH, the second expression:
var y = List<Nullable<Guid>> .Equals(10,20);
has to be evaluated as a List<Guid?>
, because you're invoking the .Equals
method. Again, this can be interpreted in any other way.
There is no paradox at all. The compiler parses it perfectly. I'm still wondering which the apradox is.
You're on a big mistake. The compiler interprets whole expressions, and uses the language grammar to understand them. It doesn't look at a fragment of code, like you're doing, without taking the rest of the expression into account.
These expressions are parsed according to C# grammar. And the grammar is clear enough to interpret the code correctly. I.e. in
var x = List<Nullable<Guid>> 10;
It's clear that 10 is a literal. If you follow up the grammar you'll find this: 10 is a *literal, so it's *primary-no-array-creation-expression, which is a *primary-expression, which is a *unary-expression, which is a *multiplicative-expression, which is an *additive-expression. If you look for an additive expression on the right side of a *>>, you find it must be a *shift-expression, so the left side of the *>> must be interpreted as an *additive-expression and so on.
If you were able to find a different way to use the grammar and get a different result for the same expression, then, I would have to agree with you, but let me disagree!
Finally:
- is very confusing for humans
- is absolutely clear and unambiguous to the compiler
Because:
- we humans identify patterns taking fragments of the whole text which are familiar to us, like
List<Nullable<Guid>>
and interpret them like we want
- compilers doesn't interptret the code like us, taking familiar fragments like
List<Nullable<Guid>>
. They take the whole expression and match it to the language grammar.
-->
and<--
operators ;) – Millepore