Version Used:
Visual C# 2017 00369-60000-00001-AA863
Steps to Reproduce:
Add the following class
```C#
sealed class NullTolerantComparer
{
public NullTolerantComparer(Func
(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
private readonly Func
}
```
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.
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:
Simplified example:
C#
public class C<T>
{
public C(bool x, int y)
{
(x, y) = (x, y);
}
}
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
Upon installing the missing package I am now show fields.
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.
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 !
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
invar 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 !