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
The following test (which currently would fail) illustrates that we fail to infer a good target type for a lambda expression argument when there is exactly one method in the method group.
[Fact][WorkItem(11901,"https://github.com/dotnet/roslyn/issues/11901")]publicvoidTestLambdaWithError15(){// These tests ensure we attempt to perform type inference and bind a lambda expression// argument even when there are too many or too few arguments to an invocation, in the// case when there is exactly one method in the method group.varsource=@"using System;class Program{ static void Main(string[] args) { Thing<string> t = null; t.X1(x => x, 1); // too many args t.X2(x => x); // too few args t.M2(string.Empty, x => x, 1); // too many args t.M3(string.Empty, x => x); // too few args }}public class Thing<T>{ public void M2<T>(T x, Func<T, T> func) {} public void M3<T>(T x, Func<T, T> func, T y) {}}public static class XThing{ public static Thing<T> X1<T>(this Thing<T> self, Func<T, T> func) => null; public static Thing<T> X2<T>(this Thing<T> self, Func<T, T> func, int i) => null;}";varcompilation= CreateCompilationWithMscorlibAndSystemCore(source);vartree= compilation.SyntaxTrees[0];varsm= compilation.GetSemanticModel(tree);foreach(var lambda in tree.GetRoot().DescendantNodes().OfType<LambdaExpressionSyntax>()){varreference= lambda.Body.DescendantNodesAndSelf().OfType<IdentifierNameSyntax>().First();
Assert.Equal("x", reference.ToString());vartypeInfo= sm.GetTypeInfo(reference);
Assert.Equal(TypeKind.Class, typeInfo.Type.TypeKind);
Assert.Equal("String", typeInfo.Type.Name);
Assert.NotEmpty(typeInfo.Type.GetMembers("Replace"));}}}
The text was updated successfully, but these errors were encountered:
gafter
changed the title
Type inference and lambda binding failure when one method in the group
Type inference and lambda binding failure when one method in the group and wrong number of arguments
Jun 9, 2016
We attempt to bind lambda args against every applicable delegate
type that could be a matching parameter, and then select the
"best" for error recovery.
This also has the effect of removing unbound lambdas from the
bound trees, replacing them with the "best" binding for error
recovery. This makes the semantic model insensitive to any further
trial bindings (i.e. mutation of the unbound lambda cache).
Fixes#12063, #11979, #11901
Remove vestigal "extensionMethodsOfSameViabilityAreAvailable"
thereby reducing coupling between internal compiler APIs.
See also #7740#5128, where the vestigal APIs were introduced.
The following test (which currently would fail) illustrates that we fail to infer a good target type for a lambda expression argument when there is exactly one method in the method group.
The text was updated successfully, but these errors were encountered: