I'm having a go at implementing C# spec 7.16.2 "Query expression translation" in Roslyn. However, I've run into a problem in 7.16.2.5 "Select clauses".
It reads
A query expression of the form
from x in e select vis translated into
( e ) . Select ( x => v )except when v is the identifier x, the translation is simply
( e )For example
from c in customers.Where(c => c.City == "London") select cis simply translated into
customers.Where(c => c.City == "London")
My code does not produce a result matching the example, because (as per the "except when" line) I translate from x in e select x into ( e ), rather than just e. Thus my code translates the example into
( customers.Where(c => c.City == "London") )
Is the example in the spec wrong, or do I need to be doing processing to recognise whether the enclosing parentheses are necessary? If so, is this in the spec somewhere?
Similarly, 7.16.2.6 (Groupby clauses) says
A query expression of the form
from x in e group v by kis translated into
( e ) . GroupBy ( x => k , x => v )except when v is the identifier x, the translation is
( e ) . GroupBy ( x => k )The example
from c in customers group c.Name by c.Countryis translated into
customers. GroupBy(c => c.Country, c => c.Name)
where again the example result is missing the parentheses suggested by the spec.