提交 7b6f27d5 编写于 作者: V vladres

Test for bug 1077204: Because a foreach iteration variable of a value type is...

Test for bug 1077204: Because a foreach iteration variable of a value type is read-only, an invocation of a mutating method on its instance field of a value type should make a temp copy rather than mutate the field in-place (changeset 1367129)
上级 1eeff68b
......@@ -949,6 +949,41 @@ void Foo(int i)
Diagnostic(ErrorCode.ERR_ForEachMissingMember, "i").WithArguments("int", "GetEnumerator"));
}
[Fact(Skip = "Bug 1077204")]
[WorkItem(1077204)]
public void TestIterationVariableIsReadOnly()
{
const string source = @"
using System;
struct A
{
public B B;
static void Main()
{
A[] array = { default(A) };
foreach (A a in array)
{
a.B.SetField(5);
Console.Write(a.B.Field);
}
}
}
struct B
{
public int Field;
public void SetField(int value)
{
this.Field = value;
}
}";
CompileAndVerify(source, expectedOutput: "0");
}
[Fact]
public void TestErrorModifyIterationVariable()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册