-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't include snippets of source in diagnostics about types #7515
Changes from 10 commits
5314d3a
aff6d10
d956770
f21f816
43862ee
dad7e4c
c73ea99
149a434
db713ea
213d7f8
9c01f74
34c3ddc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like lines of code 1285, 1424, 1431 are also using syntax node as a diagnostics argument. Should they be changed too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AlekseyTs Those are fixed now, too. Can you please re-review? |
||
} | ||
|
||
|
@@ -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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be simply an override of ErrorDisplayName? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess not, because this type doesn't derive from NameSyntax. |
||
{ | ||
// Dev10 uses the name from source, even if it's an alias. | ||
return Name.ToString(); | ||
return Name.ErrorDisplayName(); | ||
} | ||
|
||
internal AttributeArgumentSyntax GetNamedArgumentSyntax(string namedArgName) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we testing these cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, some of the changed tests are due to this. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,10 @@ internal override SimpleNameSyntax GetUnqualifiedName() | |
{ | ||
return Right; | ||
} | ||
|
||
internal override string ErrorDisplayName() | ||
{ | ||
return Left.ErrorDisplayName() + "." + Right.ErrorDisplayName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we testing this case and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the test changes are due to this. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1424,6 +1424,17 @@ static int Main(string[] args) | |
Assert.Equal(CandidateReason.OverloadResolutionFailure, symbolInfo.CandidateReason); | ||
} | ||
|
||
[Fact] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this test be linked to the issue? |
||
public void TestLookupVerbatimVar() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is not properly marked as a test method. |
||
{ | ||
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<ISymbol> actual_lookupSymbols) | ||
{ | ||
var namespaceX = (NamespaceSymbol)actual_lookupSymbols.Where((sym) => sym.Name.Equals("X") && sym.Kind == SymbolKind.Namespace).Single(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like lines 1285, 1424, 1431 are also using syntax node as a diagnostics argument. Should they be changed too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no compiler error codes between 1113 and 1501, so I'm not sure what you're referring to. From ErrorCode.cs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am referring to lines of code in this file.