You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;using System.Collections.Generic;classProgram{staticvoidTupleResult<T>(Func<(T, T)>x){
Console.WriteLine(typeof(T).Name);}staticvoidCollectionResult<T>(Func<T[]>x){
Console.WriteLine(typeof(T).Name);}staticvoidMain(){
TupleResult(()=>(1,2));
CollectionResult(()=>new[]{1,2});
CollectionResult(()=>[1,2]);}}
Expected Behavior:
No errors, program reports "Int32 Int32 Int32".
Actual Behavior:
Error reported for collection expression case.
(20,9): error CS0411: The type arguments for method 'Program.CollectionResult<T>(Func<T[]>)'
cannot be inferred from the usage. Try specifying the type arguments explicitly.
The current behavior is by design since output type inference from a lambda expression requires the return value has a type. Since collection expressions do not have a natural type, type inference in the example fails as expected.
If E is an anonymous function with inferred return type U and T is a delegate type or expression tree type with return type Tₓ, then a lower-bound inference is made fromUtoTₓ.
Steps to Reproduce:
Compile:
Expected Behavior:
No errors, program reports "Int32 Int32 Int32".
Actual Behavior:
Error reported for collection expression case.
Relates to test plan #66418
The text was updated successfully, but these errors were encountered: