Roslyn: Intellisense displays tuple elements as fields when they are actually constructor arguments

Created on 1 Apr 2017  路  7Comments  路  Source: dotnet/roslyn

Version Used:
Visual C# 2017 00369-60000-00001-AA863
Steps to Reproduce:

  1. Create a C# project in Visual Studio 2017
  2. Add the following class
    ```C#
    sealed class NullTolerantComparer : System.Collections.Generic.EqualityComparer
    {
    public NullTolerantComparer(Func equals, Func getHashCode) =>
    (equals, getHashCode) = (equals, getHashCode);

    public override bool Equals(T x, T y) => ReferenceEquals(x, null)
    ? ReferenceEquals(y, null)
    : equals(x, y);

    public override int GetHashCode(T obj) => ReferenceEquals(null, obj) ? 0 : getHashCode(obj);

    private readonly Func equals;
    private readonly Func getHashCode;
    }
    ```

  3. Observe the hover tips shown in the screenshots below
    image _Note: mouse is hovering at text cursor location_
    image _Note: mouse is hovering at text cursor location_

Expected Behavior:
Intellisense indicates that the tuple elements actually refer to the constructor arguments, not the class fields.
CS1717 is raised.
Actual Behavior:
Intellisense incorrectly displays the tuple elements as fields when they are in fact parameters.
No warning is raised.

Area-Compilers Bug Resolution-Duplicate

Most helpful comment

From discussion with IDE team, this is part of a broader issue. When hovering over a tuple element, there are two possible views: (1) you're pointing at the expression for the element, or (2) you're pointing to a field of a tuple.

This has impact on Find All References and Rename.
This problem also already exists on anonymous types (if you hover over x in var t = new { x };).
I filled two issues:
https://github.com/dotnet/roslyn/issues/20115
https://github.com/dotnet/roslyn/issues/20116

I'll close the present issue in favor of those. Thanks for reporting this @aluanhaddad !

All 7 comments

This looks like it is related to #16870

Moving to compiler and tagging @jcouv

Thanks @aluanhaddad for the detailed bug report.

There are two problems:

  1. the semantic information returned by the compiler seems incorrect (so the popup is confusing)
  2. there is no warning for self-assignment (that is indeed already tracked by #16870).

Simplified example:
C# public class C<T> { public C(bool x, int y) { (x, y) = (x, y); } }

image

Note that "Go To Definition" works properly (goes to the method parameters).

@jcouv thanks for looking into this.

When I looked at your nicely simplified example, and then back at my original, I realized that this may be an erroneous bug report on my part.

The fields I am seeing do not correspond to the members of my class which incidentally have the same names but rather to the public fields of System.ValueTuple<T1, T2>.

Here is an even further simplified example
C# static class C { static void M(bool x, int y) { (x, y) = (x, y); } }
Initially an error message is displayed due to the missing package and the tupled value is intuitively indicated as an argument by intellisense

image

Upon installing the missing package I am now show fields.

image

So this does not seem to be a bug at all, I am sorry for filing it.

That said, it is perhaps an indication of a usability issue around tuples, especially as concerns tooling.
This relates to the discussion in https://github.com/dotnet/csharplang/issues/370

Along the same lines, with the inferred tuple names feature, the QuickInfo tooltip seems weird too. In the screenshot below, I would expect that hovering over a would give me information about local a, rather than the tuple literal containing it.

image

I probably won't have time to investigate in dev15.3 timeframe given number of more annoying/breaking issues. Moving to next iteration.

From discussion with IDE team, this is part of a broader issue. When hovering over a tuple element, there are two possible views: (1) you're pointing at the expression for the element, or (2) you're pointing to a field of a tuple.

This has impact on Find All References and Rename.
This problem also already exists on anonymous types (if you hover over x in var t = new { x };).
I filled two issues:
https://github.com/dotnet/roslyn/issues/20115
https://github.com/dotnet/roslyn/issues/20116

I'll close the present issue in favor of those. Thanks for reporting this @aluanhaddad !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nlwolf picture nlwolf  路  3Comments

codingonHP picture codingonHP  路  3Comments

OndrejPetrzilka picture OndrejPetrzilka  路  3Comments

marler8997 picture marler8997  路  3Comments

AdamSpeight2008 picture AdamSpeight2008  路  3Comments