From 58e13682bc18e7cd12a445de043d2600fe9631f9 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Sat, 26 Dec 2015 11:33:28 -0800 Subject: [PATCH] Couple of code fixes Corrects a couple of items noted in #7677 --- .../CSharp/Portable/Binder/InMethodBinder.cs | 7 ------ .../Binder/WithLambdaParametersBinder.cs | 7 ------ .../Test/CommandLine/CommandLineTests.cs | 10 ++++++++ .../Semantic/Semantics/SemanticErrorTests.cs | 14 +++++------ .../Compilation/GetSemanticInfoTests.cs | 2 +- .../Symbols/Metadata/PE/LoadingAttributes.cs | 24 ------------------- .../DiagnosticLocalizationTests.cs | 22 +++++++++++++++++ .../Core/CommandLine/CompilerServerLogger.cs | 2 +- .../Diagnostic/LocalizableResourceString.cs | 2 +- src/Compilers/Extension/CompilerPackage.cs | 12 +++++----- .../XmlTagCompletionCommandHandler.cs | 2 +- .../AbstractSyntaxTriviaService.Result.cs | 2 -- ...sOperationListener.DiagnosticAsyncToken.cs | 2 +- .../Utilities/Shared/Assert/EqualityUtil.cs | 12 +++++++++- .../Utilities/Shared/Assert/EqualityUtil`1.cs | 22 +++++++++++------ .../Diagnostics/DiagnosticDescription.cs | 2 +- .../Utilities/AbstractSpeculationAnalyzer.cs | 15 ++++++++---- 17 files changed, 87 insertions(+), 72 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs b/src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs index 1fa4160b3c0..a1f08373c99 100644 --- a/src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs @@ -274,13 +274,6 @@ internal static bool ReportConflictWithParameter(Symbol parameter, Symbol newSym return false; } - if (newSymbolKind == SymbolKind.Parameter || newSymbolKind == SymbolKind.Local) - { - // CS0412: 'X': a parameter or local variable cannot have the same name as a method type parameter - diagnostics.Add(ErrorCode.ERR_LocalSameNameAsTypeParam, newLocation, name); - return true; - } - if (newSymbolKind == SymbolKind.RangeVariable) { // The range variable '{0}' cannot have the same name as a method type parameter diff --git a/src/Compilers/CSharp/Portable/Binder/WithLambdaParametersBinder.cs b/src/Compilers/CSharp/Portable/Binder/WithLambdaParametersBinder.cs index 024b68e06c5..45e977c8c00 100644 --- a/src/Compilers/CSharp/Portable/Binder/WithLambdaParametersBinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/WithLambdaParametersBinder.cs @@ -135,13 +135,6 @@ private bool ReportConflictWithParameter(ParameterSymbol parameter, Symbol newSy return true; } - if (newSymbolKind == SymbolKind.Parameter || newSymbolKind == SymbolKind.Local) - { - // A local or parameter named '{0}' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter - diagnostics.Add(ErrorCode.ERR_LocalIllegallyOverrides, newLocation, name); - return true; - } - if (newSymbolKind == SymbolKind.RangeVariable) { // The range variable '{0}' conflicts with a previous declaration of '{0}' diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index 7b0eb5d01d4..3fb672540de 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -1328,6 +1328,7 @@ public void Debug() public void Pdb() { var parsedArgs = DefaultParse(new[] { "/pdb:something", "a.cs" }, _baseDirectory); + Assert.Equal(Path.Combine(_baseDirectory, "something.pdb"), parsedArgs.PdbPath); // No pdb parsedArgs = DefaultParse(new[] { @"/debug", "a.cs" }, _baseDirectory); @@ -7191,9 +7192,11 @@ public void NoWarnAndWarnAsError_AnalyzerDriverWarnings() // TEST: Verify that compiler warning CS8032 can be suppressed via /warn:0. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warn:0" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that compiler warning CS8032 can be individually suppressed via /nowarn:. output = VerifyOutput(dir, file, additionalFlags: new[] { "/nowarn:CS8032" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that compiler warning CS8032 can be promoted to an error via /warnaserror. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror" }, expectedErrorCount: 1); @@ -7226,6 +7229,7 @@ public void NoWarnAndWarnAsError_HiddenDiagnostic() // TEST: Verify that /warn:0 has no impact on custom hidden diagnostic Hidden01. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warn:0" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that /nowarn: has no impact on custom hidden diagnostic Hidden01. output = VerifyOutput(dir, file, additionalFlags: new[] { "/nowarn:Hidden01" }, expectedWarningCount: 1); @@ -7233,6 +7237,7 @@ public void NoWarnAndWarnAsError_HiddenDiagnostic() // TEST: Verify that /warnaserror+ has no impact on custom hidden diagnostic Hidden01. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror+", "/nowarn:8032" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that /warnaserror- has no impact on custom hidden diagnostic Hidden01. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror-" }, expectedWarningCount: 1); @@ -7265,9 +7270,11 @@ public void NoWarnAndWarnAsError_HiddenDiagnostic() // TEST: Verify that /warn:0 has no impact on custom hidden diagnostic Hidden01. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warn:0", "/warnaserror:Hidden01" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that /warn:0 has no impact on custom hidden diagnostic Hidden01. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror:Hidden01", "/warn:0" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that last /warnaserror[+/-]: flag on command line wins. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror+:Hidden01", "/warnaserror-:Hidden01" }, expectedWarningCount: 1); @@ -7293,6 +7300,7 @@ public void NoWarnAndWarnAsError_HiddenDiagnostic() // TEST: Verify that last one wins between /warnaserror[+/-]: and /warnaserror[+/-]. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror+:Hidden01", "/warnaserror+", "/nowarn:8032" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that last one wins between /warnaserror[+/-]: and /warnaserror[+/-]. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror+:Hidden01", "/warnaserror-" }, expectedWarningCount: 1); @@ -7300,6 +7308,7 @@ public void NoWarnAndWarnAsError_HiddenDiagnostic() // TEST: Verify that last one wins between /warnaserror[+/-] and /warnaserror[+/-]:. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror+", "/warnaserror-:Hidden01", "/nowarn:8032" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that last one wins between /warnaserror[+/-]: and /warnaserror[+/-]. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror-:Hidden01", "/warnaserror-" }, expectedWarningCount: 1); @@ -7471,6 +7480,7 @@ static void Main() // TEST: Verify that compiler warning CS0168 as well as custom warning diagnostic Warning01 can be suppressed via /warn:0. output = VerifyOutput(dir, file, additionalFlags: new[] { "/warn:0" }); + Assert.True(string.IsNullOrEmpty(output)); // TEST: Verify that compiler warning CS0168 as well as custom warning diagnostic Warning01 can be individually suppressed via /nowarn:. output = VerifyOutput(dir, file, additionalFlags: new[] { "/nowarn:0168,Warning01,58000" }, expectedWarningCount: 1); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index 67c30a97378..f402059d911 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -10480,19 +10480,19 @@ public void CS0543ERR_EnumeratorOverflow04() @"enum A {0} enum B : byte {1} enum C : byte {2} -enum D : sbyte {2}", +enum D : sbyte {3}", CreateEnumValues(300, "E"), CreateEnumValues(256, "E"), CreateEnumValues(300, "E"), CreateEnumValues(300, "E", sbyte.MinValue)); - + CreateCompilationWithMscorlib(source).VerifyDiagnostics( - // (4,676): error CS0543: 'D.E128': the enumerator value is too large to fit in its type - // enum D : sbyte { E0, E1, E2, E3, , E297, E298, E299, } - Diagnostic(ErrorCode.ERR_EnumeratorOverflow, "E128").WithArguments("D.E128").WithLocation(4, 676), // (3,1443): error CS0543: 'C.E256': the enumerator value is too large to fit in its type - // enum C : byte { E0, E1, E2, E3, , E297, E298, E299, } - Diagnostic(ErrorCode.ERR_EnumeratorOverflow, "E256").WithArguments("C.E256").WithLocation(3, 1443)); + // enum C : byte { E0, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, E18, E19, E20, E21, E22, E23, E24, E25, E26, E27, E28, E29, E30, E31, E32, E33, E34, E35, E36, E37, E38, E39, E40, E41, E42, E43, E44, E45, E46, E47, E48, E49, E50, E51, E52, E53, E54, E55, E56, E57, E58, E59, E60, E61, E62, E63, E64, E65, E66, E67, E68, E69, E70, E71, E72, E73, E74, E75, E76, E77, E78, E79, E80, E81, E82, E83, E84, E85, E86, E87, E88, E89, E90, E91, E92, E93, E94, E95, E96, E97, E98, E99, E100, E101, E102, E103, E104, E105, E106, E107, E108, E109, E110, E111, E112, E113, E114, E115, E116, E117, E118, E119, E120, E121, E122, E123, E124, E125, E126, E127, E128, E129, E130, E131, E132, E133, E134, E135, E136, E137, E138, E139, E140, E141, E142, E143, E144, E145, E146, E147, E148, E149, E150, E151, E152, E153, E154, E155, E156, E157, E158, E159, E160, E161, E162, E163, E164, E165, E166, E167, E168, E169, E170, E171, E172, E173, E174, E175, E176, E177, E178, E179, E180, E181, E182, E183, E184, E185, E186, E187, E188, E189, E190, E191, E192, E193, E194, E195, E196, E197, E198, E199, E200, E201, E202, E203, E204, E205, E206, E207, E208, E209, E210, E211, E212, E213, E214, E215, E216, E217, E218, E219, E220, E221, E222, E223, E224, E225, E226, E227, E228, E229, E230, E231, E232, E233, E234, E235, E236, E237, E238, E239, E240, E241, E242, E243, E244, E245, E246, E247, E248, E249, E250, E251, E252, E253, E254, E255, E256, E257, E258, E259, E260, E261, E262, E263, E264, E265, E266, E267, E268, E269, E270, E271, E272, E273, E274, E275, E276, E277, E278, E279, E280, E281, E282, E283, E284, E285, E286, E287, E288, E289, E290, E291, E292, E293, E294, E295, E296, E297, E298, E299, } + Diagnostic(ErrorCode.ERR_EnumeratorOverflow, "E256").WithArguments("C.E256").WithLocation(3, 1443), + // (4,1451): error CS0543: 'D.E256': the enumerator value is too large to fit in its type + // enum D : sbyte { E0 = -128, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, E18, E19, E20, E21, E22, E23, E24, E25, E26, E27, E28, E29, E30, E31, E32, E33, E34, E35, E36, E37, E38, E39, E40, E41, E42, E43, E44, E45, E46, E47, E48, E49, E50, E51, E52, E53, E54, E55, E56, E57, E58, E59, E60, E61, E62, E63, E64, E65, E66, E67, E68, E69, E70, E71, E72, E73, E74, E75, E76, E77, E78, E79, E80, E81, E82, E83, E84, E85, E86, E87, E88, E89, E90, E91, E92, E93, E94, E95, E96, E97, E98, E99, E100, E101, E102, E103, E104, E105, E106, E107, E108, E109, E110, E111, E112, E113, E114, E115, E116, E117, E118, E119, E120, E121, E122, E123, E124, E125, E126, E127, E128, E129, E130, E131, E132, E133, E134, E135, E136, E137, E138, E139, E140, E141, E142, E143, E144, E145, E146, E147, E148, E149, E150, E151, E152, E153, E154, E155, E156, E157, E158, E159, E160, E161, E162, E163, E164, E165, E166, E167, E168, E169, E170, E171, E172, E173, E174, E175, E176, E177, E178, E179, E180, E181, E182, E183, E184, E185, E186, E187, E188, E189, E190, E191, E192, E193, E194, E195, E196, E197, E198, E199, E200, E201, E202, E203, E204, E205, E206, E207, E208, E209, E210, E211, E212, E213, E214, E215, E216, E217, E218, E219, E220, E221, E222, E223, E224, E225, E226, E227, E228, E229, E230, E231, E232, E233, E234, E235, E236, E237, E238, E239, E240, E241, E242, E243, E244, E245, E246, E247, E248, E249, E250, E251, E252, E253, E254, E255, E256, E257, E258, E259, E260, E261, E262, E263, E264, E265, E266, E267, E268, E269, E270, E271, E272, E273, E274, E275, E276, E277, E278, E279, E280, E281, E282, E283, E284, E285, E286, E287, E288, E289, E290, E291, E292, E293, E294, E295, E296, E297, E298, E299, } + Diagnostic(ErrorCode.ERR_EnumeratorOverflow, "E256").WithArguments("D.E256").WithLocation(4, 1451)); } // Create string "{ E0, E1, ..., En }" diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs index 0112dea914e..703fd415dcd 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/GetSemanticInfoTests.cs @@ -2273,8 +2273,8 @@ public static void Main(string[] args) } else { - thread1.Start(); thread2.Start(); + thread1.Start(); } comp.VerifyDiagnostics(); diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs index 45cd8b5b96e..2f3719ce9e1 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/LoadingAttributes.cs @@ -536,30 +536,6 @@ public void TestDumpAllAttributesTesLib() }; CheckAttributes(assemblies[0], assemblyArgs); - - DumpAttributes(assemblies[0].Modules[0]); - } - - private void DumpAttributes(Symbol s) - { - int i = 0; - foreach (var sa in s.GetAttributes()) - { - int j = 0; - foreach (var pa in sa.CommonConstructorArguments) - { - Console.WriteLine("{0} {1} {2}", pa.ToString()); - j += 1; - } - - j = 0; - foreach (var na in sa.CommonNamedArguments) - { - Console.WriteLine("{0} {1} {2} = {3}", na.Key, na.Value.ToString()); - j += 1; - } - i += 1; - } } private void CheckAttributes(Symbol s, AttributeArgs[] expected) diff --git a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/DiagnosticLocalizationTests.cs b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/DiagnosticLocalizationTests.cs index 69b902e7fbf..8d206595386 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/DiagnosticLocalizationTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/DiagnosticLocalizationTests.cs @@ -231,6 +231,28 @@ public override object GetObject(string name, bool ignoreCase) } } + [Fact] + public void LocalizableResourceStringEquality() + { + var resourceManager = GetTestResourceManagerInstance(); + var unit = EqualityUnit + .Create(new LocalizableResourceString(@"ResourceWithArguments", resourceManager, typeof(CustomResourceManager), "arg")) + .WithEqualValues( + new LocalizableResourceString(@"ResourceWithArguments", resourceManager, typeof(CustomResourceManager), "arg")) + .WithNotEqualValues( + new LocalizableResourceString(@"ResourceWithArguments", resourceManager, typeof(CustomResourceManager), "otherarg"), + new LocalizableResourceString(@"Resource1", resourceManager, typeof(CustomResourceManager))); + EqualityUtil.RunAll(unit, checkIEquatable: false); + + + var str = new LocalizableResourceString(@"ResourceWithArguments", resourceManager, typeof(CustomResourceManager), "arg"); + var threw = false; + str.OnException += (sender, e) => { threw = true; }; + Assert.False(str.Equals(42)); + Assert.False(str.Equals(42)); + Assert.False(threw); + } + [Fact, WorkItem(887)] public void TestDescriptorIsExceptionSafe() { diff --git a/src/Compilers/Core/CommandLine/CompilerServerLogger.cs b/src/Compilers/Core/CommandLine/CompilerServerLogger.cs index 711262739b1..faf9adcccb7 100644 --- a/src/Compilers/Core/CommandLine/CompilerServerLogger.cs +++ b/src/Compilers/Core/CommandLine/CompilerServerLogger.cs @@ -46,7 +46,7 @@ static CompilerServerLogger() // Otherwise, assume that the environment variable specifies the name of the log file. if (Directory.Exists(loggingFileName)) { - loggingFileName = Path.Combine(loggingFileName, string.Format("server.{1}.{2}.log", loggingFileName, GetCurrentProcessId(), Environment.TickCount)); + loggingFileName = Path.Combine(loggingFileName, $"server.{loggingFileName}.{GetCurrentProcessId()}.log"); } // Open allowing sharing. We allow multiple processes to log to the same file, so we use share mode to allow that. diff --git a/src/Compilers/Core/Portable/Diagnostic/LocalizableResourceString.cs b/src/Compilers/Core/Portable/Diagnostic/LocalizableResourceString.cs index 4301932e8c4..3cf523c03c3 100644 --- a/src/Compilers/Core/Portable/Diagnostic/LocalizableResourceString.cs +++ b/src/Compilers/Core/Portable/Diagnostic/LocalizableResourceString.cs @@ -118,7 +118,7 @@ protected override string GetText(IFormatProvider formatProvider) protected override bool AreEqual(object other) { var otherResourceString = other as LocalizableResourceString; - return other != null && + return otherResourceString != null && _nameOfLocalizableResource == otherResourceString._nameOfLocalizableResource && _resourceManager == otherResourceString._resourceManager && _resourceSource == otherResourceString._resourceSource && diff --git a/src/Compilers/Extension/CompilerPackage.cs b/src/Compilers/Extension/CompilerPackage.cs index a9415d7560b..2d28ce7f739 100644 --- a/src/Compilers/Extension/CompilerPackage.cs +++ b/src/Compilers/Extension/CompilerPackage.cs @@ -11,11 +11,6 @@ namespace Roslyn.Compilers.Extension [ProvideAutoLoad(UIContextGuids.SolutionExists)] public sealed class CompilerPackage : Package { - private const string WriteFileExceptionMessage = -@"{1} - -To reload the Roslyn compiler package, close Visual Studio and any MSBuild processes, then restart Visual Studio."; - protected override void Initialize() { base.Initialize(); @@ -100,9 +95,14 @@ private void WriteMSBuildFiles(string packagePath, string hiveName) } catch (Exception e) { + var msg = +$@"{e.Message} + +To reload the Roslyn compiler package, close Visual Studio and any MSBuild processes, then restart Visual Studio."; + VsShellUtilities.ShowMessageBox( this, - string.Format(WriteFileExceptionMessage, e.Message), + msg, null, OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, diff --git a/src/EditorFeatures/CSharp/DocumentationComments/XmlTagCompletionCommandHandler.cs b/src/EditorFeatures/CSharp/DocumentationComments/XmlTagCompletionCommandHandler.cs index bb2877e4344..0fce867159e 100644 --- a/src/EditorFeatures/CSharp/DocumentationComments/XmlTagCompletionCommandHandler.cs +++ b/src/EditorFeatures/CSharp/DocumentationComments/XmlTagCompletionCommandHandler.cs @@ -120,7 +120,7 @@ private bool HasMatchingEndTag(XmlElementStartTagSyntax parentStartTag) } var parentElement = parentStartTag.Parent as XmlElementSyntax; - if (parentStartTag == null) + if (parentElement == null) { return false; } diff --git a/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs b/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs index 047d8b8ed6b..6bb5897b23b 100644 --- a/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs +++ b/src/Features/Core/Portable/ExtractMethod/AbstractSyntaxTriviaService.Result.cs @@ -113,13 +113,11 @@ private int GetFirstEndOfLineIndex(List list) // check variable assumption. ordering of two pairs can't be changed Contract.ThrowIfFalse( - (tokens[TriviaLocation.BeforeBeginningOfSpan].RawKind == 0 && tokens[TriviaLocation.AfterEndOfSpan].RawKind == 0) || (tokens[TriviaLocation.BeforeBeginningOfSpan].RawKind == 0 /* && don't care */) || (/* don't care && */ tokens[TriviaLocation.AfterEndOfSpan].RawKind == 0) || (tokens[TriviaLocation.BeforeBeginningOfSpan].Span.End <= tokens[TriviaLocation.AfterEndOfSpan].SpanStart)); Contract.ThrowIfFalse( - (tokens[TriviaLocation.AfterBeginningOfSpan].RawKind == 0 && tokens[TriviaLocation.BeforeEndOfSpan].RawKind == 0) || (tokens[TriviaLocation.AfterBeginningOfSpan].RawKind == 0 /* && don't care */) || (/* don't care && */ tokens[TriviaLocation.BeforeEndOfSpan].RawKind == 0) || (tokens[TriviaLocation.AfterBeginningOfSpan] == tokens[TriviaLocation.BeforeEndOfSpan]) || diff --git a/src/Features/Core/Portable/Shared/TestHooks/AsynchronousOperationListener.DiagnosticAsyncToken.cs b/src/Features/Core/Portable/Shared/TestHooks/AsynchronousOperationListener.DiagnosticAsyncToken.cs index a25ed417655..c7a202d5c56 100644 --- a/src/Features/Core/Portable/Shared/TestHooks/AsynchronousOperationListener.DiagnosticAsyncToken.cs +++ b/src/Features/Core/Portable/Shared/TestHooks/AsynchronousOperationListener.DiagnosticAsyncToken.cs @@ -29,7 +29,7 @@ protected internal sealed class DiagnosticAsyncToken : AsyncToken int lineNumber) : base(listener) { - Name = Name; + Name = name; Tag = tag; FilePath = filePath; LineNumber = lineNumber; diff --git a/src/Test/Utilities/Shared/Assert/EqualityUtil.cs b/src/Test/Utilities/Shared/Assert/EqualityUtil.cs index 34b54dd844b..c9442c173a1 100644 --- a/src/Test/Utilities/Shared/Assert/EqualityUtil.cs +++ b/src/Test/Utilities/Shared/Assert/EqualityUtil.cs @@ -15,10 +15,20 @@ public static class EqualityUtil util.RunAll(); } + public static void RunAll(EqualityUnit unit, bool checkIEquatable = true) + { + RunAll(checkIEquatable, new[] { unit }); + } + public static void RunAll(params EqualityUnit[] values) + { + RunAll(checkIEquatable: true, values: values); + } + + public static void RunAll(bool checkIEquatable, params EqualityUnit[] values) { var util = new EqualityUtil(values); - util.RunAll(); + util.RunAll(checkIEquatable); } } } diff --git a/src/Test/Utilities/Shared/Assert/EqualityUtil`1.cs b/src/Test/Utilities/Shared/Assert/EqualityUtil`1.cs index 7b78ab2c1ae..b3107f59cec 100644 --- a/src/Test/Utilities/Shared/Assert/EqualityUtil`1.cs +++ b/src/Test/Utilities/Shared/Assert/EqualityUtil`1.cs @@ -29,7 +29,7 @@ public sealed class EqualityUtil _compareWithInequalityOperator = compInequality; } - public void RunAll() + public void RunAll(bool checkIEquatable = true) { if (_compareWithEqualityOperator != null) { @@ -43,13 +43,21 @@ public void RunAll() InequalityOperator2(); } - ImplementsIEquatable(); + if (checkIEquatable) + { + ImplementsIEquatable(); + } + ObjectEquals1(); ObjectEquals2(); ObjectEquals3(); GetHashCode1(); - EquatableEquals1(); - EquatableEquals2(); + + if (checkIEquatable) + { + EquatableEquals1(); + EquatableEquals2(); + } } private void EqualityOperator1() @@ -130,8 +138,8 @@ private void ObjectEquals1() var unitValue = unit.Value; foreach (var value in unit.EqualValues) { - Assert.Equal(value, unitValue); - Assert.Equal(unitValue, value); + Assert.True(value.Equals(unitValue)); + Assert.True(unitValue.Equals(value)); } } } @@ -161,7 +169,7 @@ private void ObjectEquals3() var allValues = _equalityUnits.SelectMany(x => x.AllValues); foreach (var value in allValues) { - Assert.NotEqual((object)42, value); + Assert.False(value.Equals((object)42)); } } diff --git a/src/Test/Utilities/Shared/Diagnostics/DiagnosticDescription.cs b/src/Test/Utilities/Shared/Diagnostics/DiagnosticDescription.cs index a358ace0104..f81fe3003f1 100644 --- a/src/Test/Utilities/Shared/Diagnostics/DiagnosticDescription.cs +++ b/src/Test/Utilities/Shared/Diagnostics/DiagnosticDescription.cs @@ -198,7 +198,7 @@ public override bool Equals(object obj) { var d = obj as DiagnosticDescription; - if (obj == null) + if (d == null) return false; if (!_code.Equals(d._code)) diff --git a/src/Workspaces/Core/Portable/Utilities/AbstractSpeculationAnalyzer.cs b/src/Workspaces/Core/Portable/Utilities/AbstractSpeculationAnalyzer.cs index 14925a1ae1f..abffd28598d 100644 --- a/src/Workspaces/Core/Portable/Utilities/AbstractSpeculationAnalyzer.cs +++ b/src/Workspaces/Core/Portable/Utilities/AbstractSpeculationAnalyzer.cs @@ -379,11 +379,16 @@ private static bool SymbolsAreCompatibleCore(ISymbol symbol, ISymbol newSymbol, { var type = methodSymbol.ContainingType; var newType = newMethodSymbol.ContainingType; - if ((type != null && type.IsEnumType() && - type.EnumUnderlyingType != null && type.EnumUnderlyingType.SpecialType == newType.SpecialType) || - (newType != null && newType.IsEnumType() && - newType.EnumUnderlyingType != null && newType.EnumUnderlyingType.SpecialType == type.SpecialType)) - { + if ((type != null && newType != null) && + ( + type.IsEnumType() && + type.EnumUnderlyingType != null && + type.EnumUnderlyingType.SpecialType == newType.SpecialType) || + ( + newType.IsEnumType() && + newType.EnumUnderlyingType != null && + newType.EnumUnderlyingType.SpecialType == type.SpecialType)) + { return true; } } -- GitLab