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

remove _showPosition from DiagnosticDescription #19353

Merged
merged 1 commit into from
May 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/Test/Utilities/Portable/Diagnostics/DiagnosticDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public sealed class DiagnosticDescription
private readonly string _squiggledText;
private readonly object[] _arguments;
private readonly LinePosition? _startPosition; // May not have a value only in the case that we're constructed via factories
private bool _showPosition; // show start position in ToString if comparison fails
private readonly bool _argumentOrderDoesNotMatter;
private readonly Type _errorCodeType;
private readonly bool _ignoreArgumentsWhenComparing;
Expand Down Expand Up @@ -96,7 +95,7 @@ public DiagnosticDescription(
_errorCodeType = errorCodeType ?? code.GetType();
}

public DiagnosticDescription(Diagnostic d, bool errorCodeOnly, bool showPosition = false)
public DiagnosticDescription(Diagnostic d, bool errorCodeOnly)
{
_code = d.Code;
_isWarningAsError = d.IsWarningAsError;
Expand Down Expand Up @@ -124,7 +123,6 @@ public DiagnosticDescription(Diagnostic d, bool errorCodeOnly, bool showPosition
}

_ignoreArgumentsWhenComparing = errorCodeOnly;
_showPosition = showPosition;

if (!_ignoreArgumentsWhenComparing)
{
Expand Down Expand Up @@ -219,13 +217,8 @@ public override bool Equals(object obj)
{
if (_startPosition.Value != d._startPosition.Value)
{
_showPosition = true;
d._showPosition = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ummm ... why should Equals every be changing state??? You've deleted lines that terrify me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIGHT

Copy link
Contributor Author

@TyOverby TyOverby May 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OmarTawfik can attest: when I found that this was the source of the bug, I cried tears of blood.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a hidden gem as old as our history goes ~~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us forever burn this mistake into our memories. Today will be remembered as ""In No State chANging Equals" day, or "INSANE" for short.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like good RoslynAnalyzer candidate to check if fields are set in .Equals, .GetHashCode, .ToString... methods

Copy link
Member

@mgravell mgravell May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidKarlas i could forgive it in GetHashCode and ToString as long as it is just caching a lazily computed value to prevent recalc

return false;
}

_showPosition = false;
d._showPosition = false;
}
}

Expand Down Expand Up @@ -354,7 +347,7 @@ public override string ToString()
sb.Append(")");
}

if (_startPosition != null && _showPosition)
if (_startPosition != null)
{
sb.Append(".WithLocation(");
sb.Append(_startPosition.Value.Line + 1);
Expand Down Expand Up @@ -438,7 +431,7 @@ public static string GetAssertText(DiagnosticDescription[] expected, IEnumerable
}
}

var description = new DiagnosticDescription(d, errorCodeOnly: false, showPosition: true);
var description = new DiagnosticDescription(d, errorCodeOnly: false);
var diffDescription = description;
var idx = Array.IndexOf(expected, description);
if (idx != -1)
Expand Down