// "in" parameters are effectively None for the purpose of overload resolution.
paramRefKind=RefKind.None;
returnRefKind.None;
}
// Omit ref feature for COM interop: We can pass arguments by value for ref parameters if we are calling a method/property on an instance of a COM imported type.
// We must ignore the 'ref' on the parameter while determining the applicability of argument for the given method call.
// During argument rewriting, we will replace the argument value with a temporary local and pass that local by reference.
// (15,9): error CS0411: The type arguments for method 'Program.M1<T>(in T, in T)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
// M1(null, null);
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs,"M1").WithArguments("Program.M1<T>(in T, in T)").WithLocation(15,9),
// (16,12): error CS1503: Argument 1: cannot convert from '<null>' to 'in int'
// (17,9): error CS0411: The type arguments for method 'Program.M1<T>(in T, in T)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
// M1(new object(), default(RefLike));
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs,"M1").WithArguments("Program.M1<T>(in T, in T)").WithLocation(17,9),
// (19,9): error CS0306: The type 'Program.RefLike' may not be used as a type argument
// (22,9): error CS0411: The type arguments for method 'Program.M1<T>(in T, in T)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
// M1(in y, in x);
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs,"M1").WithArguments("Program.M1<T>(in T, in T)").WithLocation(22,9),
// (23,9): error CS0411: The type arguments for method 'Program.M1<T>(in T, in T)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
// M1(in y, x);
Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs,"M1").WithArguments("Program.M1<T>(in T, in T)").WithLocation(23,9)
);
}
[Fact]
publicvoidGenericInferenceLambdaVariance()
{
varcode=@"
class Program
{
public delegate void D1<T>(in T arg1, in T arg2);
public static void M1<T>(T arg1, T arg2)
{
System.Console.WriteLine(typeof(T).ToString());
}
static void Main()
{
M1((in int arg1, in int arg2) => throw null, (in int arg1, in int arg2) => throw null);
// (13,9): error CS0411: The type arguments for method 'Program.M1<T>(T, T)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
// M1((in int arg1, in int arg2) => throw null, (in int arg1, in int arg2) => throw null);
// (14,11): error CS1061: 'string' does not contain a definition for 'PrintValue' and no extension method 'PrintValue' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
// (14,11): error CS1061: 'IComparable' does not contain a definition for 'PrintValue' and no extension method 'PrintValue' accepting a first argument of type 'IComparable' could be found (are you missing a using directive or an assembly reference?)
// (14,11): error CS1061: 'string' does not contain a definition for 'PrintValue' and no extension method 'PrintValue' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
// (14,11): error CS1061: 'int' does not contain a definition for 'PrintValue' and no extension method 'PrintValue' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
// (14,11): error CS1061: 'string' does not contain a definition for 'PrintValue' and no extension method 'PrintValue' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
// (14,11): error CS1061: 'string' does not contain a definition for 'PrintValue' and no extension method 'PrintValue' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)