diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_WithExpression.cs b/src/Compilers/CSharp/Portable/Binder/Binder_WithExpression.cs index e9ac626629dc1..c7d51f7d17ba1 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_WithExpression.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_WithExpression.cs @@ -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. @@ -25,8 +25,6 @@ private BoundExpression BindWithExpression(WithExpressionSyntax syntax, Diagnost var receiverType = receiver.Type; var lookupResult = LookupResult.GetInstance(); - HashSet? useSiteDiagnostics = null; - bool hasErrors = false; if (receiverType is null || receiverType.IsVoidType()) @@ -38,6 +36,8 @@ private BoundExpression BindWithExpression(WithExpressionSyntax syntax, Diagnost MethodSymbol? cloneMethod = null; if (!receiverType.IsErrorType()) { + HashSet? useSiteDiagnostics = null; + LookupMembersInType( lookupResult, receiverType, @@ -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); } var initializer = BindInitializerExpression(