On 11/6/2012 8:23 AM, bearophile wrote:
Supporting annotations for function arguments is probably an important sub-feature.
It would be a significant extension, and so I'd like to see a compelling use case first.
Yesterday I was discussing about the bug-prone nature of foreach loops on a struct array, and one of the solutions I've suggested was a user-defined annotation for the programmer to denote that she wants to modify just the copy: struct Foo {} Foo[10] foos; foreach (@copy f; foos) { ... } With UDA syntax: foreach ([Copy] f; foos) { ... } Or: foreach (@(Copy) f; foos) { ... } But I think there's no way to tell the compiler to give a compile-time error if such annotation is not present there (unless there's "ref").
User defined attributes cannot invent new semantics for the language. And besides, 'ref' already does what you suggest.