Skip to content

Commit 3aa23ec

Browse files
committed
fixed tests + uncommented symbol helper code
1 parent d8a28a0 commit 3aa23ec

File tree

3 files changed

+308
-319
lines changed

3 files changed

+308
-319
lines changed

src/coverlet.core/Symbols/CecilSymbolHelper.cs

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,60 +1362,60 @@ private bool SkipExpressionBreakpointsSequences(MethodDefinition methodDefinitio
13621362
return false;
13631363
}
13641364

1365-
public bool SkipInlineAssignedAutoProperty(bool skipAutoProps, MethodDefinition methodDefinition, Instruction instruction)
1366-
{
1367-
if (!skipAutoProps || !methodDefinition.IsConstructor) return false;
1368-
1369-
return SkipGeneratedBackingFieldAssignment(methodDefinition, instruction) ||
1370-
SkipDefaultInitializationSystemObject(instruction);
1371-
}
1372-
1373-
private static bool SkipGeneratedBackingFieldAssignment(MethodDefinition methodDefinition, Instruction instruction)
1374-
{
1375-
/*
1376-
For inline initialization of properties the compiler generates a field that is set in the constructor of the class.
1377-
To skip this we search for compiler generated fields that are set in the constructor.
1378-
1379-
.field private string '<SurName>k__BackingField'
1380-
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
1381-
01 00 00 00
1382-
)
1383-
1384-
.method public hidebysig specialname rtspecialname
1385-
instance void .ctor () cil managed
1386-
{
1387-
IL_0000: ldarg.0
1388-
IL_0001: ldsfld string[System.Runtime] System.String::Empty
1389-
IL_0006: stfld string TestRepro.ClassWithPropertyInit::'<SurName>k__BackingField'
1390-
...
1391-
}
1392-
...
1393-
*/
1394-
IEnumerable<FieldDefinition> autogeneratedBackingFields = methodDefinition.DeclaringType.Fields.Where(x =>
1395-
x.CustomAttributes.Any(ca => ca.AttributeType.FullName.Equals(typeof(CompilerGeneratedAttribute).FullName)) &&
1396-
x.FullName.EndsWith("k__BackingField"));
1397-
1398-
return instruction.OpCode == OpCodes.Ldarg &&
1399-
instruction.Next?.Next?.OpCode == OpCodes.Stfld &&
1400-
instruction.Next?.Next?.Operand is FieldReference fr &&
1401-
autogeneratedBackingFields.Select(x => x.FullName).Contains(fr.FullName);
1402-
}
1403-
1404-
private static bool SkipDefaultInitializationSystemObject(Instruction instruction)
1405-
{
1406-
/*
1407-
A type always has a constructor with a default instantiation of System.Object. For record types these
1408-
instructions can have a own sequence point. This means that even the default constructor would be instrumented.
1409-
To skip this we search for call instructions with a method reference that declares System.Object.
1410-
1411-
IL_0000: ldarg.0
1412-
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
1413-
IL_0006: ret
1414-
*/
1415-
return instruction.OpCode == OpCodes.Ldarg &&
1416-
instruction.Next?.OpCode == OpCodes.Call &&
1417-
instruction.Next?.Operand is MethodReference mr && mr.DeclaringType.FullName.Equals(typeof(System.Object).FullName);
1418-
}
1365+
//public bool SkipInlineAssignedAutoProperty(bool skipAutoProps, MethodDefinition methodDefinition, Instruction instruction)
1366+
//{
1367+
// if (!skipAutoProps || !methodDefinition.IsConstructor) return false;
1368+
1369+
// return SkipGeneratedBackingFieldAssignment(methodDefinition, instruction) ||
1370+
// SkipDefaultInitializationSystemObject(instruction);
1371+
//}
1372+
1373+
//private static bool SkipGeneratedBackingFieldAssignment(MethodDefinition methodDefinition, Instruction instruction)
1374+
//{
1375+
// /*
1376+
// For inline initialization of properties the compiler generates a field that is set in the constructor of the class.
1377+
// To skip this we search for compiler generated fields that are set in the constructor.
1378+
1379+
// .field private string '<SurName>k__BackingField'
1380+
// .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
1381+
// 01 00 00 00
1382+
// )
1383+
1384+
// .method public hidebysig specialname rtspecialname
1385+
// instance void .ctor () cil managed
1386+
// {
1387+
// IL_0000: ldarg.0
1388+
// IL_0001: ldsfld string[System.Runtime] System.String::Empty
1389+
// IL_0006: stfld string TestRepro.ClassWithPropertyInit::'<SurName>k__BackingField'
1390+
// ...
1391+
// }
1392+
// ...
1393+
// */
1394+
// IEnumerable<FieldDefinition> autogeneratedBackingFields = methodDefinition.DeclaringType.Fields.Where(x =>
1395+
// x.CustomAttributes.Any(ca => ca.AttributeType.FullName.Equals(typeof(CompilerGeneratedAttribute).FullName)) &&
1396+
// x.FullName.EndsWith("k__BackingField"));
1397+
1398+
// return instruction.OpCode == OpCodes.Ldarg &&
1399+
// instruction.Next?.Next?.OpCode == OpCodes.Stfld &&
1400+
// instruction.Next?.Next?.Operand is FieldReference fr &&
1401+
// autogeneratedBackingFields.Select(x => x.FullName).Contains(fr.FullName);
1402+
//}
1403+
1404+
//private static bool SkipDefaultInitializationSystemObject(Instruction instruction)
1405+
//{
1406+
// /*
1407+
// A type always has a constructor with a default instantiation of System.Object. For record types these
1408+
// instructions can have a own sequence point. This means that even the default constructor would be instrumented.
1409+
// To skip this we search for call instructions with a method reference that declares System.Object.
1410+
1411+
// IL_0000: ldarg.0
1412+
// IL_0001: call instance void [System.Runtime]System.Object::.ctor()
1413+
// IL_0006: ret
1414+
// */
1415+
// return instruction.OpCode == OpCodes.Ldarg &&
1416+
// instruction.Next?.OpCode == OpCodes.Call &&
1417+
// instruction.Next?.Operand is MethodReference mr && mr.DeclaringType.FullName.Equals(typeof(System.Object).FullName);
1418+
//}
14191419

14201420
private static bool SkipBranchGeneratedExceptionFilter(Instruction branchInstruction, MethodDefinition methodDefinition)
14211421
{

0 commit comments

Comments
 (0)