dotnet/roslyn
Voir sur GitHubSuppress cascaded diagnostics for unused vars and funcs declared improperly
Open
#13 315 ouverte le 23 août 2016
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted
Métriques du dépôt
- Stars
- (20 414 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (256 PRs mergées en 30 j)
Description
A typical situation appears in this test:
[Fact, WorkItem(10521, "https://github.com/dotnet/roslyn/issues/10521")]
public void LabeledLocalFunctionInIf()
{
var source = @"
class Program
{
static void Main(string[] args)
{
if () // typing at this point
a: int Add(int x, int y) => x + y;
}
}
";
VerifyDiagnostics(source,
// (6,13): error CS1525: Invalid expression term ')'
// if () // typing at this point
Diagnostic(ErrorCode.ERR_InvalidExprTerm, ")").WithArguments(")").WithLocation(6, 13),
// (7,1): error CS1023: Embedded statement cannot be a declaration or labeled statement
// a: int Add(int x, int y) => x + y;
Diagnostic(ErrorCode.ERR_BadEmbeddedStmt, "a: int Add(int x, int y) => x + y;").WithLocation(7, 1),
// (7,1): warning CS0164: This label has not been referenced
// a: int Add(int x, int y) => x + y;
Diagnostic(ErrorCode.WRN_UnreferencedLabel, "a").WithLocation(7, 1),
// (7,13): warning CS0168: The variable 'Add' is declared but never used
// a: int Add(int x, int y) => x + y;
Diagnostic(ErrorCode.WRN_UnreferencedVar, "Add").WithArguments("Add").WithLocation(7, 13)
);
}
The latter two diagnostics should be suppressed by the compiler.