Version Used:
dotnet: 6.0.100-rc.2.21505.57
Steps to Reproduce:
Compile the following code (sharplab link):
using System;
using System.Linq.Expressions;
void Test1<T>(Func<T> exp) {}
void Test2<T>(Expression<Func<T>> exp) {}
void Test3<T>(Func<Func<T>> exp) {}
void Test4<T>(Func<Expression<Func<T>>> exp) {}
Test1(() => 2); // works
Test2(() => 2); // works
Test3(() => () => 2); // works
Test4(() => () => 2); // error: CS0411
Expected Behavior:
The T generic type parameter is correctly inferred for all 4 cases.
Actual Behavior:
In Test4, the T is unable to be inferred, producing the following error:
error CS0411: The type arguments for method 'Test4(Func<Expression<Func>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Given that type inference works for Func<T>, Expression<Func<T>>, and Func<Func<T>>, I thought it might be a bug that Func<Expression<Func<T>>> doesn't work.
EDIT: As of .NET 6.0.101, the behaviour has changed and now inference fails also for Func<Func<T>>, the reason this behaviour was reverted is explained in #57713 (comment). An issue #57779 was created to consider addressing this scenario.
Version Used:
dotnet:
6.0.100-rc.2.21505.57Steps to Reproduce:
Compile the following code (sharplab link):
Expected Behavior:
The
Tgeneric type parameter is correctly inferred for all 4 cases.Actual Behavior:
In
Test4, theTis unable to be inferred, producing the following error:Given that type inference works for
Func<T>,Expression<Func<T>>, andFunc<Func<T>>, I thought it might be a bug thatFunc<Expression<Func<T>>>doesn't work.EDIT: As of .NET 6.0.101, the behaviour has changed and now inference fails also for
Func<Func<T>>, the reason this behaviour was reverted is explained in #57713 (comment). An issue #57779 was created to consider addressing this scenario.