7

I was reading this page, which is officially referenced in the release notes of Visual Studio 17 RC, it states the following:

For the purpose of Overloading Overriding Hiding, tuples of the same types and lengths as well as their underlying ValueTuple types are considered equivalent. All other differences are immaterial.

When overriding a member it is permitted to use tuple types with same or different field names than in the base member.

A situation where same field names are used for non-matching fields between base and derived member signatures, a warning is reported by the compiler

When giving that a shot:

public abstract class Foo
{
    public abstract void AbstractTuple((int a, string b) tuple);

    public virtual void OverrideTuple((int a, string b) tuple)
    {
        Console.WriteLine($"First= {tuple.a}  Second = {tuple.b}");
    }
}

public class Bar : Foo
{
    public override void AbstractTuple((int c, string d) tuple)
    {
        Console.WriteLine($"First= {tuple.c}  Second= {tuple.d}");
    }

    public override void OverrideTuple((int c, string d) tuple)
    {
        base.OverrideTuple(tuple);
    }
}

I get the following errors:

Error CS8139 'Bar.AbstractTuple((int c, string d))': cannot change tuple element names when overriding inherited member 'Foo.AbstractTuple((int a, string b))'

and

Error CS8139 'Bar.OverrideTuple((int c, string d))': cannot change tuple element names when overriding inherited member 'Foo.OverrideTuple((int a, string b))'

The Questions are:

  1. Is the official design Notes wrong ? Or is this a behavior that is yet to be implemented in the official C# 7.0 Release ?

  2. If this is the correct behavior, does it make sense that the tuple Field Names has to be the same in the overridden method ? Keeping in mind that two methods with same Tuples (int a, int b) and (int c, int d) are not considered overload candidates and generate an error!

  3. Do we have official C# 7.0 Features documentation somewhere ?

2
  • The behavior you observe is correct. I can't remember which LDM included that decision. But I will update the feature design in the next week or two. Stay tuned to github.com/dotnet/roslyn/blob/master/docs/features/tuples.md Commented Jan 6, 2017 at 1:52
  • FWIW, I'm seeing this error when trying to generate a fakes assembly that uses System.ValueTuple. Commented Sep 5, 2017 at 14:30

1 Answer 1

4

Is the official design Notes wrong? Or is this a behavior that is yet to be implemented in the official C# 7.0 Release?

As far as I can tell, the documentation is out of date. That document hasn't significantly changed since April 2016, while the error that you got (ERR_CantChangeTupleNamesOnOverride in Roslyn source) was introduced in August 2016 (don't be confused by the different error code, that was changed later).

If this is the correct behavior, does it make sense that the tuple Field Names has to be the same in the overridden method? Keeping in might that two methods with same Tuples (int a, int b) and (int c, int d) are not considered overload candidates and generate an error!

Yes, that seems to be the new intended behavior.

Do we have official C# 7.0 Features documentation somewhere?

Considering that C# 7.0 is still under development, documentation is an issue. An article about tuples in the official .Net documentation is currently under review, though it does not mention these issues at all.

So, the outdated document you found is probably the best source for now. I have created an issue asking for the documentation to be updated.

Sign up to request clarification or add additional context in comments.

2 Comments

Any Idea why this decision was taken ? Tried to go back to issues and check it, but doesn't seem to have the reason written down. Was there any issue ?
I can't find anything either. The PR mentions "LDM 7/15", but the design notes for that date don't talk about this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.