C# 3.0 Limitation: Type Inference & Lambda Expressions
-
I saw an interesting point raised here: http://www.atrevido.net/blog/2007/08/02/C+Frustration.aspx[^] The C# 3 spec does not permit assigning a labmda expression to type infered value. So the following statement is invalid:
var Add = (int a, int b) => a + b;
The keyword
var
will give error CS0815, "Cannot assign 'lambda expression' to an implicitly typed local". If the type is changed fromvar
toFunc<int, int, int>
, the error goes away. The type of this lambda expression is not ambiguous, so the error must simply be a limitation in the type inference. Does anyone know if Microsoft has plans to fix this issue? If the type is known and expressible as a variable, then I see no good reason why this variable should behave differently than any other type-infered generic variable. I ran into this problem while using VS2008 beta 1, so if it works in beta 2, please let me know. -sharoz -
I saw an interesting point raised here: http://www.atrevido.net/blog/2007/08/02/C+Frustration.aspx[^] The C# 3 spec does not permit assigning a labmda expression to type infered value. So the following statement is invalid:
var Add = (int a, int b) => a + b;
The keyword
var
will give error CS0815, "Cannot assign 'lambda expression' to an implicitly typed local". If the type is changed fromvar
toFunc<int, int, int>
, the error goes away. The type of this lambda expression is not ambiguous, so the error must simply be a limitation in the type inference. Does anyone know if Microsoft has plans to fix this issue? If the type is known and expressible as a variable, then I see no good reason why this variable should behave differently than any other type-infered generic variable. I ran into this problem while using VS2008 beta 1, so if it works in beta 2, please let me know. -sharozHave you looked to see if this isssue has been raised on http://connect.microsoft.com[^]? Thats were bugs and suggestions are reported back to MS and where they give answers to those bugs and suggestions. If theres nothing there already about this you might want to submit some feedback and they *might* change it. If theres already feedback about it then you can show your support for it ... the more support for an issue, the more likely they are to do something about it.
-
Have you looked to see if this isssue has been raised on http://connect.microsoft.com[^]? Thats were bugs and suggestions are reported back to MS and where they give answers to those bugs and suggestions. If theres nothing there already about this you might want to submit some feedback and they *might* change it. If theres already feedback about it then you can show your support for it ... the more support for an issue, the more likely they are to do something about it.
-
I couldn't find any report for this problem, so I created one. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=294156[^] Thanks for the advice. -sharoz
And they've already replied :) Thanks for your feedback. We have reproduced this bug on Vista and OrcasBeta2VSTS, and we are sending this bug to the appropriate group within the Visual Studio Product Team for triage and resolution. Thank you, Visual Studio Product Team. Posted by Microsoft on 20/08/2007 at 02:24 of course this doesn't mean they'll defiantly do something about it ... but atleast they are looking at it :)