提交 94b4621f 编写于 作者: A AlekseyTs

Perform method group conversion validation when an instance of a delegate type...

Perform method group conversion validation when an instance of a delegate type is passed as an argument to a delegate constructor. (changeset 1248441)
上级 4aaa8154
......@@ -3697,8 +3697,12 @@ private BoundExpression BindDelegateCreationExpression(ObjectCreationExpressionS
{
Debug.Assert(!conv.IsExtensionMethod);
Debug.Assert(conv.IsValid); // i.e. if it exists, then it is valid.
// we do not place the "Invoke" method in the node, indicating that it did not appear in source.
return new BoundDelegateCreationExpression(node, argument, methodOpt: null, isExtensionMethod: false, type: type);
if (!this.MethodGroupConversionHasErrors(argument.Syntax, conv, argument, conv.IsExtensionMethod, type, diagnostics))
{
// we do not place the "Invoke" method in the node, indicating that it did not appear in source.
return new BoundDelegateCreationExpression(node, argument, methodOpt: null, isExtensionMethod: false, type: type);
}
}
}
finally
......
......@@ -9470,7 +9470,7 @@ static void M()
[WorkItem(539901, "DevDiv")]
[Fact]
public void CS0407ERR_BadRetType()
public void CS0407ERR_BadRetType_01()
{
var text = @"
public delegate int MyDelegate();
......@@ -9505,9 +9505,37 @@ public static void Main()
Diagnostic(ErrorCode.ERR_BadRetType, "G").WithArguments("C.G()", "void"));
}
[WorkItem(925899, "DevDiv")]
[Fact]
public void CS0407ERR_BadRetType_02()
{
var text = @"
using System;
class C
{
public static void Main()
{
var oo = new Func<object, object>(x => 1);
var os = new Func<object, string>(oo);
var ss = new Func<string, string>(oo);
}
}
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (10,43): error CS0407: 'object System.Func<object, object>.Invoke(object)' has the wrong return type
// var os = new Func<object, string>(oo);
Diagnostic(ErrorCode.ERR_BadRetType, "oo").WithArguments("System.Func<object, object>.Invoke(object)", "object").WithLocation(10, 43),
// (11,43): error CS0407: 'object System.Func<object, object>.Invoke(object)' has the wrong return type
// var ss = new Func<string, string>(oo);
Diagnostic(ErrorCode.ERR_BadRetType, "oo").WithArguments("System.Func<object, object>.Invoke(object)", "object").WithLocation(11, 43)
);
}
[WorkItem(539924, "DevDiv")]
[Fact]
public void CS0407ERR_BadRetType_01()
public void CS0407ERR_BadRetType_03()
{
var text = @"
delegate DerivedClass MyDerivedDelegate(DerivedClass x);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册