Skip to content
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

Closed
wants to merge 12 commits into from

Conversation

gafter
Copy link
Member

@gafter gafter commented Dec 16, 2015

Fixes #7387

@dotnet/roslyn-compiler Please review.

@gafter gafter added Area-Compilers 4 - In Review A fix for the issue is submitted for review. labels Dec 16, 2015
@gafter gafter self-assigned this Dec 16, 2015
@gafter gafter added this to the 1.2 milestone Dec 16, 2015
internal override string ErrorDisplayName()
{
var pb = PooledStringBuilder.GetInstance();
pb.Builder.Append(Identifier.ValueText).Append("<").Append(new string(',', Arity - 1)).Append(">");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder has Append(char, int) overload.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the error display name? It seems appropriate for an unbound generic. However, if this is a bound generic, why not have the type argument list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because when we are unable to resolve the type name, the actual type arguments are irrelevant.

@cston
Copy link
Member

cston commented Dec 16, 2015

LGTM

var pb = PooledStringBuilder.GetInstance();
pb.Builder.Append(Identifier.ValueText).Append("<").Append(new string(',', Arity - 1)).Append(">");
return pb.ToStringAndFree();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we testing these cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, some of the changed tests are due to this.

@leppie
Copy link
Contributor

leppie commented Dec 16, 2015

These changes allows for the following to compile incorrectly

class C { public static void Main() { @var v = 1; } }

This is slightly modified version of the failing code action test case.

I think the error should still be CS0246.

Update: Possible fix looks easy, just verifying the previous failing case.
Update: Works, see details below.

@leppie
Copy link
Contributor

leppie commented Dec 16, 2015

This is failing due to an incorrect check now for var. A simple fix is just to change (in Binder.NotFound):

if (whereText == "var" && !options.IsAttributeTypeLookup())

to

if (where.ToString() == "var" && !options.IsAttributeTypeLookup())

Also consider adding the following (and more if there are) as a test:

class C { public static void Main() { @var v = 1; } }

to report CS0246

Note: Not sure how expensive where.ToString() is, but it was previously called. This fix would also explain why whereText was probably introduced in Binder.NotFound. Perhaps knowing the reason now, and that both callsites of this method passes the same value as simpleName, it can be removed.

@leppie
Copy link
Contributor

leppie commented Dec 16, 2015

This PR also seems to partially fix #7493 to bring it inline with what the legacy compiler reported.

@@ -1524,7 +1524,7 @@ public int Compare(Symbol fst, Symbol snd)
node = node.Parent;
}

CSDiagnosticInfo info = NotFound(where, simpleName, arity, where.ToString(), diagnostics, aliasOpt, qualifierOpt, options);
CSDiagnosticInfo info = NotFound(where, simpleName, arity, simpleName, diagnostics, aliasOpt, qualifierOpt, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are only two call sites for this function and now both are passing the same value for the second and the forth parameter. We should probably get rid of one of them to simplify things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so. One of the call sites looks like this:

                NotFound(where, simpleName, arity, whereText + "Attribute", diagnostics, aliasOpt, qualifierOpt, options | LookupOptions.VerbatimNameAttributeTypeOnly);

@gafter
Copy link
Member Author

gafter commented Dec 17, 2015

@dotnet/roslyn-compiler Could I have a second review, please?

@@ -1524,7 +1524,7 @@ public int Compare(Symbol fst, Symbol snd)
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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlekseyTs Those are fixed now, too. Can you please re-review?

@gafter
Copy link
Member Author

gafter commented Dec 29, 2015

@dotnet-bot test this please

@@ -1424,6 +1424,17 @@ static int Main(string[] args)
Assert.Equal(CandidateReason.OverloadResolutionFailure, symbolInfo.CandidateReason);
}

[Fact]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test be linked to the issue?

@AlekseyTs
Copy link
Contributor

It looks like the baseline for Microsoft.CodeAnalysis.CSharp.UnitTests.CompilationErrorTests.CS0104ERR_AmbigContext01 test should be adjusted.

@AlekseyTs
Copy link
Contributor

LGTM, modulo the base line adjustment for CS0104ERR_AmbigContext01.

@gafter gafter closed this in cc10b52 Jan 4, 2016
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Jan 4, 2016
@gafter gafter deleted the fix7387 branch May 24, 2018 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants