Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element names of a tuple type are not propagating through type constraints in metadata #12267

Closed
AlekseyTs opened this issue Jun 28, 2016 · 4 comments

Comments

@AlekseyTs
Copy link
Contributor

        [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)
                );
        }
@AlekseyTs
Copy link
Contributor Author

@VSadov, @jcouv, @agocke, @jaredpar It looks like we will need to propagate tuple names through constraints too.

AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Jun 28, 2016
@jaredpar
Copy link
Member

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.

public override void M<T>(T x) 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.

@AlekseyTs
Copy link
Contributor Author

C# copies constraints to overriding methods, it doesn't allow to specify them again manually.

@jaredpar jaredpar modified the milestones: 2.0 (RC), 2.0 (RTM) Jul 18, 2016
@agocke
Copy link
Member

agocke commented Aug 9, 2016

This should be fixed by #12660

@agocke agocke closed this as completed Aug 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants