Skip to content

Commit d6f483e

Browse files
author
Neal Gafter
authored
Add test to confirm that a bug is fixed. (#27157)
Fixes #27104
1 parent 0d83995 commit d6f483e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6580,5 +6580,36 @@ public void UnmanagedConstraint_Delegate()
65806580
SymbolDisplayPartKind.Space,
65816581
SymbolDisplayPartKind.Keyword);
65826582
}
6583+
6584+
[Fact, WorkItem(27104, "https://github.com/dotnet/roslyn/issues/27104")]
6585+
public void BadDiscardInForeachLoop_01()
6586+
{
6587+
var source = @"
6588+
class C
6589+
{
6590+
void M()
6591+
{
6592+
foreach(_ in """")
6593+
{
6594+
}
6595+
}
6596+
}";
6597+
var compilation = CreateCompilation(source);
6598+
compilation.VerifyDiagnostics(
6599+
// (6,17): error CS8186: A foreach loop must declare its iteration variables.
6600+
// foreach(_ in "")
6601+
Diagnostic(ErrorCode.ERR_MustDeclareForeachIteration, "_").WithLocation(6, 17)
6602+
);
6603+
var tree = compilation.SyntaxTrees[0];
6604+
var variable = tree.GetRoot().DescendantNodes().OfType<ForEachVariableStatementSyntax>().Single().Variable;
6605+
var model = compilation.GetSemanticModel(tree);
6606+
var symbol = model.GetSymbolInfo(variable).Symbol;
6607+
Verify(
6608+
symbol.ToMinimalDisplayParts(model, variable.SpanStart),
6609+
"var _",
6610+
SymbolDisplayPartKind.ErrorTypeName, // var
6611+
SymbolDisplayPartKind.Space,
6612+
SymbolDisplayPartKind.Punctuation); // _
6613+
}
65836614
}
65846615
}

0 commit comments

Comments
 (0)