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' could not be found (are you missing a using directive or an assembly reference?) + Diagnostic(ErrorCode.ERR_RbraceExpected, ";").WithLocation(9, 18), + // (6,21): error CS0246: The type or namespace name 'Dictionary<,>' could not be found (are you missing a using directive or an assembly reference?) // var d = new Dictionary() - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Dictionary").WithArguments("Dictionary"), + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Dictionary").WithArguments("Dictionary<,>").WithLocation(6, 21), // (8,13): error CS0747: Invalid initializer member declarator // {"s", 1 }, - Diagnostic(ErrorCode.ERR_InvalidInitializerElementInitializer, @"{""s"", 1 }"), + Diagnostic(ErrorCode.ERR_InvalidInitializerElementInitializer, @"{""s"", 1 }").WithLocation(8, 13), // (9,9): error CS0103: The name 'var' does not exist in the current context // var x = 1; - Diagnostic(ErrorCode.ERR_NameNotInContext, "var").WithArguments("var"), + Diagnostic(ErrorCode.ERR_NameNotInContext, "var").WithArguments("var").WithLocation(9, 9), // (9,9): error CS0747: Invalid initializer member declarator // var x = 1; - Diagnostic(ErrorCode.ERR_InvalidInitializerElementInitializer, "var")); + Diagnostic(ErrorCode.ERR_InvalidInitializerElementInitializer, "var").WithLocation(9, 9) + ); } [WorkItem(543961, "DevDiv")] @@ -1564,25 +1565,26 @@ public static void Main() CreateCompilationWithMscorlib(source).VerifyDiagnostics( // (6,25): error CS1513: } expected // new List() { { { 1 } } }; - Diagnostic(ErrorCode.ERR_RbraceExpected, "{"), + Diagnostic(ErrorCode.ERR_RbraceExpected, "{").WithLocation(6, 25), // (6,25): error CS1003: Syntax error, ',' expected // new List() { { { 1 } } }; - Diagnostic(ErrorCode.ERR_SyntaxError, "{").WithArguments(",", "{"), + Diagnostic(ErrorCode.ERR_SyntaxError, "{").WithArguments(",", "{").WithLocation(6, 25), // (6,33): error CS1002: ; expected // new List() { { { 1 } } }; - Diagnostic(ErrorCode.ERR_SemicolonExpected, "}"), + Diagnostic(ErrorCode.ERR_SemicolonExpected, "}").WithLocation(6, 33), // (6,34): error CS1597: Semicolon after method or accessor block is not valid // new List() { { { 1 } } }; - Diagnostic(ErrorCode.ERR_UnexpectedSemicolon, ";"), + Diagnostic(ErrorCode.ERR_UnexpectedSemicolon, ";").WithLocation(6, 34), // (8,1): error CS1022: Type or namespace definition, or end-of-file expected // } - Diagnostic(ErrorCode.ERR_EOFExpected, "}"), - // (6,9): error CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?) + Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(8, 1), + // (6,9): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?) // new List() { { { 1 } } }; - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "List").WithArguments("List"), + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "List").WithArguments("List<>").WithLocation(6, 9), // (6,23): error CS1920: Element initializer cannot be empty // new List() { { { 1 } } }; - Diagnostic(ErrorCode.ERR_EmptyElementInitializer, "{ ")); + Diagnostic(ErrorCode.ERR_EmptyElementInitializer, "{ ").WithLocation(6, 23) + ); } [WorkItem(544484, "DevDiv")] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index a433dca8158f9..67c30a97378ea 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -22371,13 +22371,13 @@ static void Main() } }"; CreateCompilationWithMscorlib(text).VerifyDiagnostics( - // (7,41): error CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?) + // (7,41): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?) // var d = (Action>)delegate(List t) {}; - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "List").WithArguments("List"), - // (7,21): error CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?) + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "List").WithArguments("List<>").WithLocation(7, 41), + // (7,21): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?) // var d = (Action>)delegate(List t) {}; - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "List").WithArguments("List") - ); + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "List").WithArguments("List<>").WithLocation(7, 21) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs index 0e5fc158f227a..9a9b27b420339 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs @@ -2521,15 +2521,20 @@ class C void M() where U : Z, A { } }"; CreateCompilationWithMscorlib(source).VerifyDiagnostics( - // (4,15): error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?) - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "X").WithArguments("X").WithLocation(4, 15), - // (5,15): error CS0246: The type or namespace name 'I' could not be found (are you missing a using directive or an assembly reference?) - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "I").WithArguments("I").WithLocation(5, 15), // (10,18): error CS0246: The type or namespace name 'Y' could not be found (are you missing a using directive or an assembly reference?) + // where T : A, Y Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Y").WithArguments("Y").WithLocation(10, 18), + // (4,15): error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?) + // where T : X + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "X").WithArguments("X").WithLocation(4, 15), + // (5,15): error CS0246: The type or namespace name 'I<>' could not be found (are you missing a using directive or an assembly reference?) + // where U : I + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "I").WithArguments("I<>").WithLocation(5, 15), // (13,27): error CS0246: The type or namespace name 'Z' could not be found (are you missing a using directive or an assembly reference?) + // void M() where U : Z, A { } Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Z").WithArguments("Z").WithLocation(13, 27), // (13,30): error CS0406: The class type constraint 'A' must come before any other constraints + // void M() where U : Z, A { } Diagnostic(ErrorCode.ERR_ClassBoundNotFirst, "A").WithArguments("A").WithLocation(13, 30)); } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/TypeForwarders.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/TypeForwarders.cs index bb481fd8f36ab..11e0fe9a63c76 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/TypeForwarders.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/PE/TypeForwarders.cs @@ -793,27 +793,28 @@ class Test var ref1 = CompileIL(il1, appendDefaultHeader: false); CreateCompilationWithMscorlib(csharp, new[] { ref1 }).VerifyDiagnostics( - // (4,5): error CS1070: The type name 'Outer' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly. - // Outer P { get; set; } - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Outer").WithArguments("Outer", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"), // (5,5): error CS1070: The type name 'Outer' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly. // Outer.Inner M() { return null; } - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Outer").WithArguments("Outer", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"), - // (6,5): error CS1070: The type name 'Outer' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly. - // Outer.Inner F; - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Outer").WithArguments("Outer", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"), - // (6,25): warning CS0169: The field 'Test.F' is never used - // Outer.Inner F; - Diagnostic(ErrorCode.WRN_UnreferencedField, "F").WithArguments("Test.F"), + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Outer").WithArguments("Outer", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(5, 5), // (8,5): error CS0246: The type or namespace name 'Generic' could not be found (are you missing a using directive or an assembly reference?) // Generic G0 { get; set; } - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Generic").WithArguments("Generic"), - // (9,5): error CS1070: The type name 'Generic' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly. + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Generic").WithArguments("Generic").WithLocation(8, 5), + // (9,5): error CS1070: The type name 'Generic<>' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly. // Generic G1 { get; set; } - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Generic").WithArguments("Generic", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"), - // (10,5): error CS0246: The type or namespace name 'Generic' could not be found (are you missing a using directive or an assembly reference?) + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Generic").WithArguments("Generic<>", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(9, 5), + // (10,5): error CS0246: The type or namespace name 'Generic<,>' could not be found (are you missing a using directive or an assembly reference?) // Generic G2 { get; set; } - Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Generic").WithArguments("Generic")); + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Generic").WithArguments("Generic<,>").WithLocation(10, 5), + // (4,5): error CS1070: The type name 'Outer' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly. + // Outer P { get; set; } + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Outer").WithArguments("Outer", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(4, 5), + // (6,5): error CS1070: The type name 'Outer' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly. + // Outer.Inner F; + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFoundFwd, "Outer").WithArguments("Outer", "pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(6, 5), + // (6,25): warning CS0169: The field 'Test.F' is never used + // Outer.Inner F; + Diagnostic(ErrorCode.WRN_UnreferencedField, "F").WithArguments("Test.F").WithLocation(6, 25) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs index 08049fbf5cad0..abd4418cd5d4f 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs @@ -1544,11 +1544,9 @@ static void Main() { } "; CreateCompilationWithCustomILSource(cSharpSource, ilSource).VerifyDiagnostics( - // (4,16): error CS0104: 'A' is an ambiguous reference between 'A' and 'A' + // (4,16): error CS0104: 'A<>' is an ambiguous reference between 'A' and 'A' // object x = A.Foo; - Diagnostic(ErrorCode.ERR_AmbigContext, "A").WithArguments("A", "A", "A")); - // Dev10 error: - // error CS0433: The type 'A' exists in both 'X.dll' and 'X.dll' + Diagnostic(ErrorCode.ERR_AmbigContext, "A").WithArguments("A<>", "A", "A").WithLocation(4, 16)); } [WorkItem(538789, "DevDiv")] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index 61e4c1cfdf2e8..757ad3f4ed962 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -1519,15 +1519,15 @@ struct S }"; var comp = CreateCompilationWithMscorlib(text); comp.VerifyDiagnostics( - // (16,25): error CS0104: 'IFoo' is an ambiguous reference between 'n1.IFoo' and 'n3.n2.IFoo' - // public class C : IFoo - Diagnostic(ErrorCode.ERR_AmbigContext, "IFoo").WithArguments("IFoo", "n1.IFoo", "n3.n2.IFoo"), // (22,9): error CS0104: 'A' is an ambiguous reference between 'n1.A' and 'n3.n2.A' // A a; - Diagnostic(ErrorCode.ERR_AmbigContext, "A").WithArguments("A", "n1.A", "n3.n2.A"), - // (22,11): warning CS0169: The field 'n3.S.a' is never used + Diagnostic(ErrorCode.ERR_AmbigContext, "A").WithArguments("A", "n1.A", "n3.n2.A").WithLocation(22, 9), + // (16,25): error CS0104: 'IFoo<>' is an ambiguous reference between 'n1.IFoo' and 'n3.n2.IFoo' + // public class C : IFoo + Diagnostic(ErrorCode.ERR_AmbigContext, "IFoo").WithArguments("IFoo<>", "n1.IFoo", "n3.n2.IFoo").WithLocation(16, 25), + // (22,11): warning CS0169: The field 'S.a' is never used // A a; - Diagnostic(ErrorCode.WRN_UnreferencedField, "a").WithArguments("n3.S.a") + Diagnostic(ErrorCode.WRN_UnreferencedField, "a").WithArguments("n3.S.a").WithLocation(22, 11) ); var ns3 = comp.SourceModule.GlobalNamespace.GetMember("n3"); @@ -2882,27 +2882,28 @@ class C N.C c; }"; CreateCompilationWithMscorlib(text, references: new[] { SystemCoreRef }).VerifyDiagnostics( + // (2,16): error CS0234: The type or namespace name 'B<>' does not exist in the namespace 'N' (are you missing an assembly reference?) + // using NB = C>; + Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "B").WithArguments("B<>", "N").WithLocation(2, 16), // (1,14): error CS0234: The type or namespace name 'A' does not exist in the namespace 'N' (are you missing an assembly reference?) // using NA = N.A; - Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "A").WithArguments("A", "N"), - // (2,16): error CS0234: The type or namespace name 'B' does not exist in the namespace 'N' (are you missing an assembly reference?) - // using NB = C>; - Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "B").WithArguments("B", "N"), - // (8,7): error CS0234: The type or namespace name 'C' does not exist in the namespace 'N' (are you missing an assembly reference?) + Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "A").WithArguments("A", "N").WithLocation(1, 14), + // (8,7): error CS0234: The type or namespace name 'C<>' does not exist in the namespace 'N' (are you missing an assembly reference?) // N.C c; - Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "C").WithArguments("C", "N"), + Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "C").WithArguments("C<>", "N").WithLocation(8, 7), // (8,11): error CS0234: The type or namespace name 'D' does not exist in the namespace 'N' (are you missing an assembly reference?) // N.C c; - Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "D").WithArguments("D", "N"), + Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "D").WithArguments("D", "N").WithLocation(8, 11), // (6,8): warning CS0169: The field 'C.a' is never used // NA a; - Diagnostic(ErrorCode.WRN_UnreferencedField, "a").WithArguments("C.a"), + Diagnostic(ErrorCode.WRN_UnreferencedField, "a").WithArguments("C.a").WithLocation(6, 8), // (7,8): warning CS0169: The field 'C.b' is never used // NB b; - Diagnostic(ErrorCode.WRN_UnreferencedField, "b").WithArguments("C.b"), + Diagnostic(ErrorCode.WRN_UnreferencedField, "b").WithArguments("C.b").WithLocation(7, 8), // (8,14): warning CS0169: The field 'C.c' is never used // N.C c; - Diagnostic(ErrorCode.WRN_UnreferencedField, "c").WithArguments("C.c")); + Diagnostic(ErrorCode.WRN_UnreferencedField, "c").WithArguments("C.c").WithLocation(8, 14) + ); } [Fact]