提交 58e13682 编写于 作者: J Jared Parsons 提交者: Jared Parsons

Couple of code fixes

Corrects a couple of items noted in #7677
上级 cc10b52b
......@@ -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
......
......@@ -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}'
......
......@@ -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);
......
......@@ -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, <snip>, 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, <snip>, 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 }"
......
......@@ -2273,8 +2273,8 @@ public static void Main(string[] args)
}
else
{
thread1.Start();
thread2.Start();
thread1.Start();
}
comp.VerifyDiagnostics();
......
......@@ -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)
......
......@@ -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()
{
......
......@@ -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.
......
......@@ -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 &&
......
......@@ -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,
......
......@@ -120,7 +120,7 @@ private bool HasMatchingEndTag(XmlElementStartTagSyntax parentStartTag)
}
var parentElement = parentStartTag.Parent as XmlElementSyntax;
if (parentStartTag == null)
if (parentElement == null)
{
return false;
}
......
......@@ -113,13 +113,11 @@ private int GetFirstEndOfLineIndex(List<SyntaxTrivia> 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]) ||
......
......@@ -29,7 +29,7 @@ protected internal sealed class DiagnosticAsyncToken : AsyncToken
int lineNumber)
: base(listener)
{
Name = Name;
Name = name;
Tag = tag;
FilePath = filePath;
LineNumber = lineNumber;
......
......@@ -15,10 +15,20 @@ public static class EqualityUtil
util.RunAll();
}
public static void RunAll<T>(EqualityUnit<T> unit, bool checkIEquatable = true)
{
RunAll(checkIEquatable, new[] { unit });
}
public static void RunAll<T>(params EqualityUnit<T>[] values)
{
RunAll(checkIEquatable: true, values: values);
}
public static void RunAll<T>(bool checkIEquatable, params EqualityUnit<T>[] values)
{
var util = new EqualityUtil<T>(values);
util.RunAll();
util.RunAll(checkIEquatable);
}
}
}
......@@ -29,7 +29,7 @@ public sealed class EqualityUtil<T>
_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));
}
}
......
......@@ -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))
......
......@@ -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;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册