Enclosed is a patch for AvoidRepetitiveCastsRule. This fixes a number  
of false positives:

// old code complained about this because the Operand calls were  
assigned to the same local
MyInstruction i = (MyInstruction)  (o.Operand); 
return (MyInstruction) (i.Operand);

// old code used TraceBack if the call wasn't followed by stloc which  
was highly problematic
Console.WriteLine((string) Compute(3));
Console.WriteLine((string) Compute(5));

// old code didn't check indexes
string s = (string) a1 [7];     
string t = (string) a1 [8];

self-test now returns one violation for the following:
         while (a is TypeSpecification || b is TypeSpecification) {
             if (a.GetType () != b.GetType ())
                 return false;

             a = ((TypeSpecification) a).ElementType;
             b = ((TypeSpecification) b).ElementType;
         }
which it did before and seems like a more or less legit warning.

self-test does not flag:
     case Code.Stfld:
         //TODO: we do not check what instance is on the stack
         return new StoreSlot (StoreType.Field, (int)  
((FieldReference) ins.Operand).MetadataToken.ToUInt ());
     case Code.Stsfld:
         return new StoreSlot (StoreType.StaticField, (int)  
((FieldReference) ins.Operand).MetadataToken.ToUInt ());
which it did before. This is arguably also a legit warning. Maybe we  
could get this working by using TraceBack for nullary method calls.

-- Jesse


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Gendarme" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/gendarme?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: diff
Description: Binary data



Reply via email to