Skip to content

Commit

Permalink
Fix locally scoped constant array (#644)
Browse files Browse the repository at this point in the history
* add failing test for LocallyScopedConstantArray

* add LocallyScopedConstantArray target assembly

* ElementType.Array should be treated the same as object in ReadLocalConstant

* assert constant is null

* Style fixes

Co-authored-by: Jb Evain <jb@evain.net>
  • Loading branch information
SimonCropp and jbevain authored Jan 31, 2020
1 parent 0a2f294 commit 933575c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Mono.Cecil/AssemblyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3017,7 +3017,7 @@ ConstantDebugInformation ReadLocalConstant (uint rid)
value = new decimal (signature.ReadInt32 (), signature.ReadInt32 (), signature.ReadInt32 (), (b & 0x80) != 0, (byte) (b & 0x7f));
} else if (type.IsTypeOf ("System", "DateTime")) {
value = new DateTime (signature.ReadInt64());
} else if (type.etype == ElementType.Object || type.etype == ElementType.None || type.etype == ElementType.Class) {
} else if (type.etype == ElementType.Object || type.etype == ElementType.None || type.etype == ElementType.Class || type.etype == ElementType.Array) {
value = null;
} else
value = signature.ReadConstantSignature (type.etype);
Expand Down
14 changes: 14 additions & 0 deletions Test/Mono.Cecil.Tests/ImageReadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ public void Net471TargetingAssembly ()
});
}

[Test]
public void LocallyScopedConstantArray ()
{
TestModule ("LocallyScopedConstantArray.dll", module => {
Assert.IsTrue (module.HasDebugHeader);
var method = module.Types
.Single (x => x.Name == "TestClass")
.Methods
.Single (x => x.Name == "TestMethod");
var debugInformation = method.DebugInformation;
Assert.IsNull (debugInformation.Scope.Constants.Single ().Value);
}, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider));
}

[Test]
public void ExternalPdbDeterministicAssembly ()
{
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 933575c

Please sign in to comment.