Skip to content

Commit 6a9164b

Browse files
author
Julien Couvreur
committed
Address feedback
1 parent 7f4d084 commit 6a9164b

17 files changed

+99
-86
lines changed

src/Compilers/CSharp/Portable/Binder/Binder.OperatorResolutionForReporting.cs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ private struct OperatorResolutionForReporting
2222
private object? _nonExtensionResult;
2323
private object? _extensionResult;
2424

25+
[Conditional("DEBUG")]
26+
private void AssertInvariant()
27+
{
28+
Debug.Assert(_nonExtensionResult is null or OverloadResolutionResult<MethodSymbol> or BinaryOperatorOverloadResolutionResult or UnaryOperatorOverloadResolutionResult);
29+
Debug.Assert(_extensionResult is null or OverloadResolutionResult<MethodSymbol> or BinaryOperatorOverloadResolutionResult or UnaryOperatorOverloadResolutionResult);
30+
}
31+
2532
/// <returns>Returns true if the result was set and <see cref="OperatorResolutionForReporting"/> took ownership of the result.</returns>
2633
private bool SaveResult(object result, ref object? savedResult)
2734
{
@@ -71,7 +78,7 @@ public bool SaveResult(UnaryOperatorOverloadResolutionResult result, bool isExte
7178
/// <summary>
7279
/// Follows a very simplified version of OverloadResolutionResult.ReportDiagnostics which can be expanded in the future if needed.
7380
/// </summary>
74-
internal bool TryReportDiagnostics(SyntaxNode node, BindingDiagnosticBag diagnostics, Binder binder, object leftDisplay, object? rightDisplay)
81+
internal bool TryReportDiagnostics(SyntaxNode node, Binder binder, object leftDisplay, object? rightDisplay, BindingDiagnosticBag diagnostics)
7582
{
7683
object? resultToUse = pickResultToUse(_nonExtensionResult, _extensionResult);
7784
if (resultToUse is null)
@@ -82,16 +89,22 @@ internal bool TryReportDiagnostics(SyntaxNode node, BindingDiagnosticBag diagnos
8289
var results = ArrayBuilder<(MethodSymbol?, OperatorAnalysisResultKind)>.GetInstance();
8390
populateResults(results, resultToUse);
8491

85-
bool reported = tryReportDiagnostics(node, diagnostics, binder, results, leftDisplay, rightDisplay);
92+
bool reported = tryReportDiagnostics(node, binder, results, leftDisplay, rightDisplay, diagnostics);
8693
results.Free();
8794

8895
return reported;
8996

90-
static bool tryReportDiagnostics(SyntaxNode node, BindingDiagnosticBag diagnostics, Binder binder, ArrayBuilder<(MethodSymbol? member, OperatorAnalysisResultKind resultKind)> results, object leftDisplay, object? rightDisplay)
97+
static bool tryReportDiagnostics(
98+
SyntaxNode node,
99+
Binder binder,
100+
ArrayBuilder<(MethodSymbol? member, OperatorAnalysisResultKind resultKind)> results,
101+
object leftDisplay,
102+
object? rightDisplay,
103+
BindingDiagnosticBag diagnostics)
91104
{
92105
assertNone(results, OperatorAnalysisResultKind.Undefined);
93106

94-
if (hadAmbiguousBestMethods(results, node, diagnostics, binder))
107+
if (hadAmbiguousBestMethods(results, node, binder, diagnostics))
95108
{
96109
return true;
97110
}
@@ -102,6 +115,12 @@ static bool tryReportDiagnostics(SyntaxNode node, BindingDiagnosticBag diagnosti
102115
}
103116

104117
assertNone(results, OperatorAnalysisResultKind.Applicable);
118+
119+
if (results.Any(m => m.resultKind == OperatorAnalysisResultKind.Worse))
120+
{
121+
return false;
122+
}
123+
105124
assertNone(results, OperatorAnalysisResultKind.Worse);
106125

107126
Debug.Assert(results.All(r => r.resultKind == OperatorAnalysisResultKind.Inapplicable));
@@ -112,12 +131,12 @@ static bool tryReportDiagnostics(SyntaxNode node, BindingDiagnosticBag diagnosti
112131
var toReport = nodeToReport(node);
113132
if (rightDisplay is null)
114133
{
115-
// error: Operator cannot be applied on operand of type '{0}'. The closest inapplicable candidate is '{1}'
134+
// error: Operator cannot be applied to operand of type '{0}'. The closest inapplicable candidate is '{1}'
116135
Error(diagnostics, ErrorCode.ERR_SingleInapplicableUnaryOperator, toReport, leftDisplay, inapplicableMember);
117136
}
118137
else
119138
{
120-
// error: Operator cannot be applied on operands of type '{0}' and '{1}'. The closest inapplicable candidate is '{2}'
139+
// error: Operator cannot be applied to operands of type '{0}' and '{1}'. The closest inapplicable candidate is '{2}'
121140
Error(diagnostics, ErrorCode.ERR_SingleInapplicableBinaryOperator, toReport, leftDisplay, rightDisplay, inapplicableMember);
122141
}
123142

@@ -165,7 +184,7 @@ static OperatorAnalysisResultKind getBestKind(object result)
165184
{
166185
if (res.Signature.Method is null)
167186
{
168-
// Skip build-in operators
187+
// Skip built-in operators
169188
continue;
170189
}
171190

@@ -181,7 +200,7 @@ static OperatorAnalysisResultKind getBestKind(object result)
181200
{
182201
if (res.Signature.Method is null)
183202
{
184-
// Skip build-in operators
203+
// Skip built-in operators
185204
continue;
186205
}
187206

@@ -199,7 +218,7 @@ static OperatorAnalysisResultKind getBestKind(object result)
199218
return bestKind;
200219
}
201220

202-
static bool hadAmbiguousBestMethods(ArrayBuilder<(MethodSymbol?, OperatorAnalysisResultKind)> results, SyntaxNode node, BindingDiagnosticBag diagnostics, Binder binder)
221+
static bool hadAmbiguousBestMethods(ArrayBuilder<(MethodSymbol?, OperatorAnalysisResultKind)> results, SyntaxNode node, Binder binder, BindingDiagnosticBag diagnostics)
203222
{
204223
if (!tryGetTwoBest(results, out var first, out var second))
205224
{
@@ -222,6 +241,7 @@ static SyntaxNodeOrToken nodeToReport(SyntaxNode node)
222241
};
223242
}
224243

244+
[Conditional("DEBUG")]
225245
static void assertNone(ArrayBuilder<(MethodSymbol? member, OperatorAnalysisResultKind resultKind)> results, OperatorAnalysisResultKind kind)
226246
{
227247
Debug.Assert(results.All(r => r.resultKind != kind));
@@ -259,9 +279,9 @@ static bool tryGetTwoBest(ArrayBuilder<(MethodSymbol?, OperatorAnalysisResultKin
259279
return false;
260280
}
261281

262-
static void populateResults(ArrayBuilder<(MethodSymbol?, OperatorAnalysisResultKind)> results, object? extensionResult)
282+
static void populateResults(ArrayBuilder<(MethodSymbol?, OperatorAnalysisResultKind)> results, object? result)
263283
{
264-
switch (extensionResult)
284+
switch (result)
265285
{
266286
case OverloadResolutionResult<MethodSymbol> result1:
267287
foreach (var res in result1.ResultsBuilder)
@@ -287,7 +307,7 @@ static void populateResults(ArrayBuilder<(MethodSymbol?, OperatorAnalysisResultK
287307
break;
288308

289309
default:
290-
throw ExceptionUtilities.UnexpectedValue(extensionResult);
310+
throw ExceptionUtilities.UnexpectedValue(result);
291311
}
292312
}
293313

@@ -329,12 +349,5 @@ static void free(ref object? result)
329349
result = null;
330350
}
331351
}
332-
333-
[Conditional("DEBUG")]
334-
private void AssertInvariant()
335-
{
336-
Debug.Assert(_nonExtensionResult is null or OverloadResolutionResult<MethodSymbol> or BinaryOperatorOverloadResolutionResult or UnaryOperatorOverloadResolutionResult);
337-
Debug.Assert(_extensionResult is null or OverloadResolutionResult<MethodSymbol> or BinaryOperatorOverloadResolutionResult or UnaryOperatorOverloadResolutionResult);
338-
}
339352
}
340353
}

src/Compilers/CSharp/Portable/CSharpResources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8172,10 +8172,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
81728172
<value>The extension resolution is ambiguous between the following members: '{0}' and '{1}'</value>
81738173
</data>
81748174
<data name="ERR_SingleInapplicableBinaryOperator" xml:space="preserve">
8175-
<value>Operator cannot be applied on operands of type '{0}' and '{1}'. The closest inapplicable candidate is '{2}'</value>
8175+
<value>Operator cannot be applied to operands of type '{0}' and '{1}'. The closest inapplicable candidate is '{2}'</value>
81768176
</data>
81778177
<data name="ERR_SingleInapplicableUnaryOperator" xml:space="preserve">
8178-
<value>Operator cannot be applied on operand of type '{0}'. The closest inapplicable candidate is '{1}'</value>
8178+
<value>Operator cannot be applied to operand of type '{0}'. The closest inapplicable candidate is '{1}'</value>
81798179
</data>
81808180
<data name="ERR_AmbigOperator" xml:space="preserve">
81818181
<value>Operator resolution is ambiguous between the following members: '{0}' and '{1}'</value>

src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)