dotnet/roslyn
在 GitHub 查看Suppress cascaded diagnostics for unused vars and funcs declared improperly
Open
#13,315 创建于 2016年8月23日
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted
仓库指标
- Star
- (20,414 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 256 个 PR)
描述
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.