Skip to content

Commit 41a4f69

Browse files
committed
Merge pull request #4784 from amcasey/DiagArgEquals
Use object.Equals when comparing diag arguments
2 parents 7755b16 + 0635080 commit 41a4f69

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,25 @@ public static int Main()
20422042
Assert.Equal(1, compilation.GetDiagnostics().Length);
20432043
}
20442044

2045+
[Fact]
2046+
public void TestArgumentEquality()
2047+
{
2048+
var text = @"
2049+
using System;
2050+
2051+
public class Test
2052+
{
2053+
public static void Main()
2054+
{
2055+
(Console).WriteLine();
2056+
}
2057+
}";
2058+
var tree = Parse(text);
2059+
2060+
// (8,10): error CS0119: 'Console' is a type, which is not valid in the given context
2061+
AssertEx.Equal(CreateCompilationWithMscorlib(tree).GetDiagnostics(), CreateCompilationWithMscorlib(tree).GetDiagnostics());
2062+
}
2063+
20452064
#region Mocks
20462065
internal class CustomErrorInfo : DiagnosticInfo
20472066
{

src/Compilers/Core/Portable/Diagnostic/DiagnosticInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public override bool Equals(object obj)
437437
result = true;
438438
for (int i = 0; i < _arguments.Length; i++)
439439
{
440-
if (_arguments[i] != other._arguments[i])
440+
if (!object.Equals(_arguments[i], other._arguments[i]))
441441
{
442442
result = false;
443443
break;

0 commit comments

Comments
 (0)