diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
index dd8a679107d7b..2274deaf829a7 100644
--- a/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
+++ b/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
@@ -1282,7 +1282,7 @@ internal Symbol ResultSymbol(
// '{0}' is an ambiguous reference between '{1}' and '{2}'
info = new CSDiagnosticInfo(ErrorCode.ERR_AmbigContext, originalSymbols,
new object[] {
- where,
+ (where as NameSyntax)?.ErrorDisplayName() ?? simpleName,
new FormattedSymbol(first, SymbolDisplayFormat.CSharpErrorMessageFormat),
new FormattedSymbol(second, SymbolDisplayFormat.CSharpErrorMessageFormat) });
}
@@ -1421,14 +1421,14 @@ internal Symbol ResultSymbol(
// SPEC: is present, and a compile-time error results.
info = new CSDiagnosticInfo(ErrorCode.ERR_AmbiguousAttribute, originalSymbols,
- new object[] { where, first, second });
+ new object[] { (where as NameSyntax)?.ErrorDisplayName() ?? simpleName, first, second });
}
else
{
// '{0}' is an ambiguous reference between '{1}' and '{2}'
info = new CSDiagnosticInfo(ErrorCode.ERR_AmbigContext, originalSymbols,
new object[] {
- where,
+ (where as NameSyntax)?.ErrorDisplayName() ?? simpleName,
new FormattedSymbol(first, SymbolDisplayFormat.CSharpErrorMessageFormat),
new FormattedSymbol(second, SymbolDisplayFormat.CSharpErrorMessageFormat) });
}
@@ -1524,7 +1524,7 @@ internal Symbol ResultSymbol(
node = node.Parent;
}
- CSDiagnosticInfo info = NotFound(where, simpleName, arity, where.ToString(), diagnostics, aliasOpt, qualifierOpt, options);
+ CSDiagnosticInfo info = NotFound(where, simpleName, arity, (where as NameSyntax)?.ErrorDisplayName() ?? simpleName, diagnostics, aliasOpt, qualifierOpt, options);
return new ExtendedErrorTypeSymbol(qualifierOpt ?? Compilation.Assembly.GlobalNamespace, simpleName, arity, info);
}
@@ -1819,7 +1819,7 @@ private CSDiagnosticInfo NotFound(CSharpSyntaxNode where, string simpleName, int
return diagnostics.Add(ErrorCode.ERR_AliasNotFound, location, whereText);
}
- if (whereText == "var" && !options.IsAttributeTypeLookup())
+ if ((where as IdentifierNameSyntax)?.Identifier.Text == "var" && !options.IsAttributeTypeLookup())
{
var code = (where.Parent is QueryClauseSyntax) ? ErrorCode.ERR_TypeVarNotFoundRangeVariable : ErrorCode.ERR_TypeVarNotFound;
return diagnostics.Add(code, location);
diff --git a/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj b/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj
index f93ed12ff9737..db3fba3e62c61 100644
--- a/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj
+++ b/src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj
@@ -750,6 +750,7 @@
+
@@ -901,4 +902,4 @@
-
+
\ No newline at end of file
diff --git a/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs b/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs
index a7397bac844a3..442b868f1e169 100644
--- a/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs
+++ b/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs
@@ -655,7 +655,7 @@ private bool ValidateAttributeUsage(
// Given attribute can't be specified more than once if AllowMultiple is false.
if (!uniqueAttributeTypes.Add(attributeType) && !attributeUsageInfo.AllowMultiple)
{
- diagnostics.Add(ErrorCode.ERR_DuplicateAttribute, node.Name.Location, node.Name);
+ diagnostics.Add(ErrorCode.ERR_DuplicateAttribute, node.Name.Location, node.GetErrorDisplayName());
return false;
}
@@ -675,7 +675,7 @@ private bool ValidateAttributeUsage(
if ((attributeTarget & attributeUsageInfo.ValidTargets) == 0)
{
// generate error
- diagnostics.Add(ErrorCode.ERR_AttributeOnBadSymbolType, node.Name.Location, node.Name, attributeUsageInfo.GetValidTargetsErrorArgument());
+ diagnostics.Add(ErrorCode.ERR_AttributeOnBadSymbolType, node.Name.Location, node.GetErrorDisplayName(), attributeUsageInfo.GetValidTargetsErrorArgument());
return false;
}
diff --git a/src/Compilers/CSharp/Portable/Syntax/AliasedQualifiedNameSyntax.cs b/src/Compilers/CSharp/Portable/Syntax/AliasedQualifiedNameSyntax.cs
index fa69e38676d62..13fe42bb69cb6 100644
--- a/src/Compilers/CSharp/Portable/Syntax/AliasedQualifiedNameSyntax.cs
+++ b/src/Compilers/CSharp/Portable/Syntax/AliasedQualifiedNameSyntax.cs
@@ -15,5 +15,10 @@ internal override SimpleNameSyntax GetUnqualifiedName()
{
return this.Name;
}
+
+ internal override string ErrorDisplayName()
+ {
+ return Alias.ErrorDisplayName() + "::" + Name.ErrorDisplayName();
+ }
}
}
diff --git a/src/Compilers/CSharp/Portable/Syntax/AttributeSyntax.cs b/src/Compilers/CSharp/Portable/Syntax/AttributeSyntax.cs
index dbf1d106df885..839173339e90a 100644
--- a/src/Compilers/CSharp/Portable/Syntax/AttributeSyntax.cs
+++ b/src/Compilers/CSharp/Portable/Syntax/AttributeSyntax.cs
@@ -2,9 +2,6 @@
using System;
using System.Diagnostics;
-using Microsoft.CodeAnalysis.CSharp.Symbols;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
@@ -18,7 +15,7 @@ public partial class AttributeSyntax
internal string GetErrorDisplayName()
{
// Dev10 uses the name from source, even if it's an alias.
- return Name.ToString();
+ return Name.ErrorDisplayName();
}
internal AttributeArgumentSyntax GetNamedArgumentSyntax(string namedArgName)
diff --git a/src/Compilers/CSharp/Portable/Syntax/GenericNameSyntax.cs b/src/Compilers/CSharp/Portable/Syntax/GenericNameSyntax.cs
index d937f87c1c7d6..1b2f2d079f0cb 100644
--- a/src/Compilers/CSharp/Portable/Syntax/GenericNameSyntax.cs
+++ b/src/Compilers/CSharp/Portable/Syntax/GenericNameSyntax.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
@@ -15,5 +16,12 @@ public bool IsUnboundGenericName
return this.TypeArgumentList.Arguments.Any(SyntaxKind.OmittedTypeArgument);
}
}
+
+ internal override string ErrorDisplayName()
+ {
+ var pb = PooledStringBuilder.GetInstance();
+ pb.Builder.Append(Identifier.ValueText).Append("<").Append(',', Arity - 1).Append(">");
+ return pb.ToStringAndFree();
+ }
}
}
diff --git a/src/Compilers/CSharp/Portable/Syntax/IdentifierNameSyntax.cs b/src/Compilers/CSharp/Portable/Syntax/IdentifierNameSyntax.cs
new file mode 100644
index 0000000000000..03d03698ef45a
--- /dev/null
+++ b/src/Compilers/CSharp/Portable/Syntax/IdentifierNameSyntax.cs
@@ -0,0 +1,12 @@
+// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+namespace Microsoft.CodeAnalysis.CSharp.Syntax
+{
+ public partial class IdentifierNameSyntax
+ {
+ internal override string ErrorDisplayName()
+ {
+ return Identifier.ValueText;
+ }
+ }
+}
diff --git a/src/Compilers/CSharp/Portable/Syntax/NameSyntax.cs b/src/Compilers/CSharp/Portable/Syntax/NameSyntax.cs
index 173423ac4d3be..adad264e41cf9 100644
--- a/src/Compilers/CSharp/Portable/Syntax/NameSyntax.cs
+++ b/src/Compilers/CSharp/Portable/Syntax/NameSyntax.cs
@@ -26,6 +26,11 @@ public int Arity
///
internal abstract SimpleNameSyntax GetUnqualifiedName();
+ ///
+ /// Return the name in string form, without trivia or generic arguments, for use in diagnostics.
+ ///
+ internal abstract string ErrorDisplayName();
+
///
/// This inspection is entirely syntactic. We are not trying to find the alias corresponding to the assembly symbol
/// containing the explicitly implemented interface symbol - there may be more than one. We just want to know
diff --git a/src/Compilers/CSharp/Portable/Syntax/QualifiedNameSyntax.cs b/src/Compilers/CSharp/Portable/Syntax/QualifiedNameSyntax.cs
index f2855357652e8..98f8f459960cd 100644
--- a/src/Compilers/CSharp/Portable/Syntax/QualifiedNameSyntax.cs
+++ b/src/Compilers/CSharp/Portable/Syntax/QualifiedNameSyntax.cs
@@ -16,5 +16,10 @@ internal override SimpleNameSyntax GetUnqualifiedName()
{
return Right;
}
+
+ internal override string ErrorDisplayName()
+ {
+ return Left.ErrorDisplayName() + "." + Right.ErrorDisplayName();
+ }
}
}
diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs
index 9abcdf30f2163..b893e4a812939 100644
--- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests.cs
@@ -3596,7 +3596,7 @@ public void AttributeNoMultipleAndInvalidTarget()
string source = @"
using CustomAttribute;
[Base(1)]
-[BaseAttribute(""SOS"")]
+[@BaseAttribute(""SOS"")]
static class AttributeMod
{
[Derived('Q')]
@@ -3617,13 +3617,17 @@ public class Bar
compilation.VerifyDiagnostics(
// (4,2): error CS0579: Duplicate 'BaseAttribute' attribute
- Diagnostic(ErrorCode.ERR_DuplicateAttribute, @"BaseAttribute").WithArguments("BaseAttribute"),
+ // [@BaseAttribute("SOS")]
+ Diagnostic(ErrorCode.ERR_DuplicateAttribute, "@BaseAttribute").WithArguments("BaseAttribute").WithLocation(4, 2),
// (7,6): error CS0592: Attribute 'Derived' is not valid on this declaration type. It is only valid on 'struct, method, parameter' declarations.
- Diagnostic(ErrorCode.ERR_AttributeOnBadSymbolType, "Derived").WithArguments("Derived", "struct, method, parameter"),
+ // [Derived('Q')]
+ Diagnostic(ErrorCode.ERR_AttributeOnBadSymbolType, "Derived").WithArguments("Derived", "struct, method, parameter").WithLocation(7, 6),
// (8,6): error CS0579: Duplicate 'Derived' attribute
- Diagnostic(ErrorCode.ERR_DuplicateAttribute, "Derived").WithArguments("Derived"),
+ // [Derived('C')]
+ Diagnostic(ErrorCode.ERR_DuplicateAttribute, "Derived").WithArguments("Derived").WithLocation(8, 6),
// (13,6): error CS0579: Duplicate 'Base' attribute
- Diagnostic(ErrorCode.ERR_DuplicateAttribute, @"Base").WithArguments("Base"));
+ // [Base("")]
+ Diagnostic(ErrorCode.ERR_DuplicateAttribute, "Base").WithArguments("Base").WithLocation(13, 6));
}
[Fact]
@@ -3681,9 +3685,9 @@ class Class3 { }
var compilation = CreateCompilationWithMscorlib(source);
compilation.VerifyDiagnostics(
- // (13,2): error CS0246: The type or namespace name '@X' could not be found (are you missing a using directive or an assembly reference?)
+ // (13,2): error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)
// [@X] // Error: No attribute named X
- Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "@X").WithArguments("@X").WithLocation(13, 2));
+ Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "@X").WithArguments("X").WithLocation(13, 2));
}
[Fact]
diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
index 0c58b6d228bbd..c2cf2e35b53f4 100644
--- a/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBUsingTests.cs
@@ -2154,33 +2154,34 @@ static void Main()
var comp = CreateCompilationWithMscorlib(source);
comp.VerifyDiagnostics(
- // (6,11): error CS0246: The type or namespace name 'F' could not be found (are you missing a using directive or an assembly reference?)
+ // (6,11): error CS0246: The type or namespace name 'F<>' could not be found (are you missing a using directive or an assembly reference?)
// using Z = F;
- Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "F").WithArguments("F"),
+ Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "F").WithArguments("F<>").WithLocation(6, 11),
// (5,14): error CS0234: The type or namespace name 'E' does not exist in the namespace 'A' (are you missing an assembly reference?)
// using Y = A::E;
- Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "E").WithArguments("E", "A"),
+ Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "E").WithArguments("E", "A").WithLocation(5, 14),
// (4,13): error CS0426: The type name 'D' does not exist in the type 'C'
// using X = C.D;
- Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInAgg, "D").WithArguments("D", "C"),
+ Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInAgg, "D").WithArguments("D", "C").WithLocation(4, 13),
// (2,14): error CS0430: The extern alias 'A' was not specified in a /reference option
// extern alias A;
- Diagnostic(ErrorCode.ERR_BadExternAlias, "A").WithArguments("A"),
+ Diagnostic(ErrorCode.ERR_BadExternAlias, "A").WithArguments("A").WithLocation(2, 14),
// (3,7): error CS0246: The type or namespace name 'B' could not be found (are you missing a using directive or an assembly reference?)
// using B;
- Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "B").WithArguments("B"),
+ Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "B").WithArguments("B").WithLocation(3, 7),
+ // (5,1): hidden CS8019: Unnecessary using directive.
+ // using Y = A::E;
+ Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using Y = A::E;").WithLocation(5, 1),
// (3,1): hidden CS8019: Unnecessary using directive.
// using B;
- Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using B;"),
+ Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using B;").WithLocation(3, 1),
// (4,1): hidden CS8019: Unnecessary using directive.
// using X = C.D;
- Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using X = C.D;"),
+ Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using X = C.D;").WithLocation(4, 1),
// (6,1): hidden CS8019: Unnecessary using directive.
// using Z = F;
- Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using Z = F;"),
- // (5,1): hidden CS8019: Unnecessary using directive.
- // using Y = A::E;
- Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using Y = A::E;"));
+ Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using Z = F;").WithLocation(6, 1)
+ );
}
[Fact]
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LookupTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LookupTests.cs
index a2c93909e0940..0841acacea644 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/LookupTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LookupTests.cs
@@ -1424,6 +1424,17 @@ static int Main(string[] args)
Assert.Equal(CandidateReason.OverloadResolutionFailure, symbolInfo.CandidateReason);
}
+ [Fact]
+ public void TestLookupVerbatimVar()
+ {
+ var source = "class C { public static void Main() { @var v = 1; } }";
+ CreateCompilationWithMscorlib(source).VerifyDiagnostics(
+ // (1,39): error CS0246: The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)
+ // class C { public static void Main() { @var v = 1; } }
+ Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "@var").WithArguments("var").WithLocation(1, 39)
+ );
+ }
+
private void TestLookupSymbolsNestedNamespaces(List actual_lookupSymbols)
{
var namespaceX = (NamespaceSymbol)actual_lookupSymbols.Where((sym) => sym.Name.Equals("X") && sym.Kind == SymbolKind.Namespace).Single();
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ObjectAndCollectionInitializerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ObjectAndCollectionInitializerTests.cs
index 25ded91054d38..6c93f799005d9 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/ObjectAndCollectionInitializerTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ObjectAndCollectionInitializerTests.cs
@@ -1531,22 +1531,23 @@ static void Main(string[] args)
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (9,13): error CS1003: Syntax error, ',' expected
// var x = 1;
- Diagnostic(ErrorCode.ERR_SyntaxError, "x").WithArguments(",", ""),
+ Diagnostic(ErrorCode.ERR_SyntaxError, "x").WithArguments(",", "").WithLocation(9, 13),
// (9,18): error CS1513: } expected
// var x = 1;
- Diagnostic(ErrorCode.ERR_RbraceExpected, ";"),
- // (6,21): error CS0246: The type or namespace name 'Dictionary