Version Used: VS 15.7 Preview 2 (Roslyn 2.8.0.62716, e205ae18)
Steps to Reproduce:
- Copy the class below into a C# source file.
- Invoke the Quick Fix menu at the marked location and select either "Generate Equals(object)…" or "Generate Equals and GetHashCode…".
- Make sure the indexer "this[int]" is selected in the list. Press OK.
class Repro
{
public int this[int index]
{
get => index;
}
$$
}
Expected Behavior: The generated methods are syntactically valid. (Although I don't know how one could use an indexer to implement Equals or GetHashCode.)
Actual Behavior: The generated code looks something like this, which is syntactically invalid:
public override bool Equals(object obj)
{
var repro = obj as Repro;
return repro != null &&
this[] == repro.this[]; // Emits four compiler errors and one warning
}
public override int GetHashCode()
{
return -529683855 + this[].GetHashCode(); // Emits one compiler error
}
Version Used: VS 15.7 Preview 2 (Roslyn 2.8.0.62716,
e205ae18)Steps to Reproduce:
Expected Behavior: The generated methods are syntactically valid. (Although I don't know how one could use an indexer to implement Equals or GetHashCode.)
Actual Behavior: The generated code looks something like this, which is syntactically invalid: