dotnet/roslyn

Shortcomings in computing diagnostics for extension methods

开放

#24,787 创建于 2018年2月12日

 (0 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-CompilersBugConcept-Design DebtConcept-Diagnostic Clarityhelp wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

I was recently implementing support for dotnet/csharplang#98 and discovered a regression in the quality of diagnostic for the situation in test DelegatesFromInvalidOverloads.

It is caused by a combination of two shortcomings in the computation of diagnostics. First, in BindExtensionMethod when we fail to find an applicable extension method, we only report a diagnostic for the first extension method group that failed, even if some other extension method group contains a much better candidate. In the case of this test the first extension method group contains a method with the wrong number of parameters, while the second one has an extension method that fails only because of its return type mismatch.

Second, in OverloadResolutionResult<TMember>.ReportDiagnostics<T>, we do not report a diagnostic for the failure MemberResolutionKind.NoCorrespondingParameter, leaving it to the caller to notice that we failed to produce a diagnostic (the caller has to grub through the diagnostic bag to see that there is no error there) and then the caller has to produce a generic error message, which we see below. It does not appear that all callers have that test, though, suggesting there may be a latent bug of missing diagnostics.

贡献者指南