Open
Description
opened on Jun 26, 2015
Currently C# allow combine (using +/- operators) delegates with different compatible (covarince/contravariance) types, but .Net Delegate.Combine/Delegate.Remove doesn't allow it. So, this sample legal C# code (that will be compiled even without warnings) will result in run-time exception:
using System;
internal class Program
{
private static void Main(string[] args)
{
Func<string, object> a1 = SomeFunction;
Func<object, object> b1 = SomeFunction;
var c1 = a1 + b1;
Func<object, string> a2 = SomeFunction;
Func<object, object> b2 = SomeFunction;
var c2 = a2 - b2;
}
public static string SomeFunction(object input)
{
return string.Empty;
}
}
Metadata
Assignees
Type
Projects
Status
Requires runtime or BCL work
Activity