This is a not a compiler bug, nor indeed is this issue related to your use of generics. Both First
and Last
are functions so the compiler cannot tell whether you mean to call them, or reference them. Be explicit and let the compiler know that you mean to call the function by supplying parens.
aProc := ProcList.First();
aProc := ProcList.Last();
Yet again you have been caught out by the decision to allow the parens to be omitted when invoking procedures and functions. This design decision, whilst looking so appealing when it was made, is looking less so now that procedural types are so widely used in modern coding styles.
When you write ProcList.First
the compiler faces an ambiguity. Do you mean to call the function, or are you wishing to refer to the function as a procedural type? In many scenarios, the compiler cannot resolve the ambiguity, but that is not the case here, where the expression is found on the right hand side of an assignment operator. Faced with this ambiguity the compiler assumes that you mean to refer to the function.
It takes this choice because the other choice would be worse. At least this way you can supply the parens and explicitly indicate that you mean for the function to be called. Were the compiler to go the other way then you'd be left looking for a way to tell it that you meant to refer to the function.
As a final aside, if First
and Last
had been implemented as properties there would have been no ambiguity.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…