Skip to content

Commit

Permalink
Couple of code fixes
Browse files Browse the repository at this point in the history
Corrects a couple of items noted in #7677
  • Loading branch information
jaredpar committed Jan 5, 2016
1 parent cc10b52 commit 58e1368
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 72 deletions.
7 changes: 0 additions & 7 deletions src/Compilers/CSharp/Portable/Binder/InMethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -7226,13 +7229,15 @@ 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);
Assert.Contains("warning CS8032", output, StringComparison.Ordinal);

// 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);
Expand Down Expand Up @@ -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);
Expand All @@ -7293,13 +7300,15 @@ 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);
Assert.Contains("warning CS8032", output, StringComparison.Ordinal);

// 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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2273,8 +2273,8 @@ public static void Main(string[] args)
}
else
{
thread1.Start();
thread2.Start();
thread1.Start();
}

comp.VerifyDiagnostics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/CommandLine/CompilerServerLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
12 changes: 6 additions & 6 deletions src/Compilers/Extension/CompilerPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private bool HasMatchingEndTag(XmlElementStartTagSyntax parentStartTag)
}

var parentElement = parentStartTag.Parent as XmlElementSyntax;
if (parentStartTag == null)
if (parentElement == null)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ private Dictionary<TriviaLocation, SyntaxToken> RecoverTokensAtEdges(

// 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]) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DiagnosticAsyncToken(
int lineNumber)
: base(listener)
{
Name = Name;
Name = name;
Tag = tag;
FilePath = filePath;
LineNumber = lineNumber;
Expand Down
12 changes: 11 additions & 1 deletion src/Test/Utilities/Shared/Assert/EqualityUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ public static void RunAll<T>(
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);
}
}
}
22 changes: 15 additions & 7 deletions src/Test/Utilities/Shared/Assert/EqualityUtil`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public EqualityUtil(
_compareWithInequalityOperator = compInequality;
}

public void RunAll()
public void RunAll(bool checkIEquatable = true)
{
if (_compareWithEqualityOperator != null)
{
Expand All @@ -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()
Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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));
}
}

Expand Down
Loading

0 comments on commit 58e1368

Please sign in to comment.