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

Report use-site diagnostics in BindWithExpression #45664

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Compilers/CSharp/Portable/Binder/Binder_WithExpression.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -25,8 +25,6 @@ private BoundExpression BindWithExpression(WithExpressionSyntax syntax, Diagnost
var receiverType = receiver.Type;

var lookupResult = LookupResult.GetInstance();
HashSet<DiagnosticInfo>? useSiteDiagnostics = null;

bool hasErrors = false;

if (receiverType is null || receiverType.IsVoidType())
Expand All @@ -38,6 +36,8 @@ private BoundExpression BindWithExpression(WithExpressionSyntax syntax, Diagnost
MethodSymbol? cloneMethod = null;
if (!receiverType.IsErrorType())
{
HashSet<DiagnosticInfo>? useSiteDiagnostics = null;

LookupMembersInType(
lookupResult,
receiverType,
Expand Down Expand Up @@ -69,10 +69,11 @@ private BoundExpression BindWithExpression(WithExpressionSyntax syntax, Diagnost
TypeCompareKind.ConsiderEverything,
ref useSiteDiagnostics))
{
useSiteDiagnostics = null;
hasErrors = true;
diagnostics.Add(ErrorCode.ERR_NoSingleCloneMethod, syntax.Expression.Location, receiverType);
}

diagnostics.Add(syntax.Expression, useSiteDiagnostics);
Copy link
Member

@cston cston Jul 6, 2020

Choose a reason for hiding this comment

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

Please add a test that is affected by the change. #Resolved

Copy link
Contributor Author

@AlekseyTs AlekseyTs Jul 6, 2020

Choose a reason for hiding this comment

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

Please add a test that is affected by the change.

I do not believe it is worth spending time looking for the scenario. Code like this should be written mechanically without waiting for something to break. This is the same as passing DiagnosticsBag around.


In reply to: 450415003 [](ancestors = 450415003)

}

var initializer = BindInitializerExpression(
Expand Down