提交 24b4ab12 编写于 作者: J Jon Hanna

Throw InvalidProgram on static field list/member bind in interpreter


Commit migrated from https://github.com/dotnet/corefx/commit/a4ff8a489ddca4ea3b5d7fdc37dc450b220985aa
上级 7426b4f8
......@@ -2428,10 +2428,16 @@ private void CompileMember(Expression from, MemberInfo member, bool forBinding)
{
if (fi.IsLiteral)
{
Debug.Assert(!forBinding);
_instructions.EmitLoad(fi.GetValue(null), fi.FieldType);
}
else if (fi.IsStatic)
{
if (forBinding)
{
throw Error.InvalidProgram();
}
if (fi.IsInitOnly)
{
_instructions.EmitLoad(fi.GetValue(null), fi.FieldType);
......@@ -2447,6 +2453,7 @@ private void CompileMember(Expression from, MemberInfo member, bool forBinding)
{
EmitThisForMethodCall(from);
}
_instructions.EmitLoadField(fi);
}
}
......
......@@ -191,7 +191,7 @@ public void StaticListProperty(bool useInterpreter)
Assert.Throws<InvalidProgramException>(() => exp.Compile(useInterpreter));
}
[Theory, InlineData(false)]
[Theory, ClassData(typeof(CompilationTypes))]
public void StaticListField(bool useInterpreter)
{
FieldInfo field = typeof(ListWrapper<int>).GetField(nameof(ListWrapper<int>.StaticListField));
......@@ -211,13 +211,6 @@ public void StaticListField(bool useInterpreter)
Assert.Throws<InvalidProgramException>(() => exp.Compile(useInterpreter));
}
[Fact, ActiveIssue(5963)]
public void StaticListFieldInterpreted()
{
// Misbalances stack.
StaticListField(true);
}
[Theory, ClassData(typeof(CompilationTypes))]
public void InitializeVoidAdd(bool useInterperter)
{
......
......@@ -142,7 +142,7 @@ public void StaticInnerProperty(bool useInterpreter)
Assert.Throws<InvalidProgramException>(() => exp.Compile(useInterpreter));
}
[Theory, InlineData(false)]
[Theory, ClassData(typeof(CompilationTypes))]
public void StaticInnerField(bool useInterpreter)
{
var exp = Expression.Lambda<Func<Outer>>(
......@@ -157,13 +157,6 @@ public void StaticInnerField(bool useInterpreter)
Assert.Throws<InvalidProgramException>(() => exp.Compile(useInterpreter));
}
[Fact, ActiveIssue(5963)]
public void StaticInnerFieldInterpreted()
{
// Mis-balances stack
StaticInnerField(true);
}
[Theory, ClassData(typeof(CompilationTypes))]
public void ReadonlyInnerProperty(bool useInterpreter)
{
......@@ -211,7 +204,7 @@ public void StaticReadonlyInnerProperty(bool useInterpreter)
Assert.Throws<InvalidProgramException>(() => exp.Compile(useInterpreter));
}
[Theory, InlineData(false)]
[Theory, ClassData(typeof(CompilationTypes))]
public void StaticReadonlyInnerField(bool useInterpreter)
{
var exp = Expression.Lambda<Func<Outer>>(
......@@ -226,12 +219,6 @@ public void StaticReadonlyInnerField(bool useInterpreter)
Assert.Throws<InvalidProgramException>(() => exp.Compile(useInterpreter));
}
[Fact, ActiveIssue(5963)]
public void StaticReadonlyInnerFieldInterpreted()
{
StaticReadonlyInnerField(true);
}
public void WriteOnlyInnerProperty()
{
var bind = Expression.Bind(typeof(Inner).GetProperty(nameof(Inner.Value)), Expression.Constant(0));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册