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
[Fact]
public void ConstraintsAndNames()
{
var source1 = @"
using System.Collections.Generic;
public abstract class Base
{
public abstract void M<T>(T x) where T : IEnumerable<(int a, int b)>;
}
";
var source2 = @"
class Derived : Base
{
public override void M<T>(T x)
{
foreach (var y in x)
{
System.Console.WriteLine(y.a);
}
}
}";
var comp1 = CreateCompilationWithMscorlib(source1 + trivial2uple + source2);
comp1.VerifyDiagnostics();
var comp2 = CreateCompilationWithMscorlib45(source1 + trivial2uple);
comp2.VerifyDiagnostics();
// Retargeting (different version of mscorlib)
var comp3 = CreateCompilationWithMscorlib46(source2, references: new[] { new CSharpCompilationReference(comp2)});
comp3.VerifyDiagnostics();
// Metadata
var comp4 = CreateCompilationWithMscorlib45(source2, references: new[] { comp2.EmitToImageReference() });
// No errors expected !!!
comp4.VerifyDiagnostics(
// (8,40): error CS1061: '(int, int)' does not contain a definition for 'a' and no extension method 'a' accepting a first argument of type '(int, int)' could be found (are you missing a using directive or an assembly reference?)
// System.Console.WriteLine(y.a);
Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "a").WithArguments("(int, int)", "a").WithLocation(8, 40)
);
}
The text was updated successfully, but these errors were encountered:
That's unfortunate. I was under the impression, clearly mistaken, that we required constraints to be equivalent between the original and override method. I.E. would require this definition.
publicoverridevoid M<T>(Tx)where T :IEnumerable<(int,int)>
The code you wrote though is both legal and we properly infer that T in Derived must be IEnumerable<int>. It seems logical to extend this to include tuple names.
The text was updated successfully, but these errors were encountered: