Skip to content

Commit

Permalink
Clear the variables collection
Browse files Browse the repository at this point in the history
Before creating `CallRegisterMethodByIndex` body. In some builds there
was `bool` variable already defined, while in CI builds there was
none. Thus clear the collection, add our `int?` variable and use it.

Newly generated IL looks like:

    .method private hidebysig static bool
            CallRegisterMethodByIndex([Java.Interop]Java.Interop.JniNativeMethodRegistrationArguments arguments,
                                      [mscorlib]System.Nullable`1<int32> typeIdx) cil managed
    {
      // Code size       9285 (0x2445)
      .maxstack  2
      .locals init ([mscorlib]System.Nullable`1<int32> V_0)
      IL_0000:  ldarg.1
      IL_0001:  stloc.0
      IL_0002:  ldloca.s   V_0
      IL_0004:  call       instance !0 [mscorlib]System.Nullable`1<int32>::GetValueOrDefault()
      IL_0009:  switch     (
    ...
  • Loading branch information
radekdoulik committed Apr 16, 2020
1 parent a3c06d0 commit 4e9be13
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ void UpdateRegistrationSwitch (MethodDefinition method, MethodReference[] switch
genericTypeNullable.GenericArguments.Add (GetType ("mscorlib", "System.Int32"));

var typeIdxVariable = new VariableDefinition (module.ImportReference (genericTypeNullable));
method.Body.Variables.Clear ();
method.Body.Variables.Add (typeIdxVariable);

instructions.Add (Instruction.Create (OpCodes.Ldarg_1));
instructions.Add (Instruction.Create (OpCodes.Stloc_1));
instructions.Add (Instruction.Create (OpCodes.Stloc_0));
instructions.Add (Instruction.Create (OpCodes.Ldloca_S, typeIdxVariable));

var genericMethodGetValueOrDefault = CreateGenericMethodReference (methodGetValueOrDefault, genericTypeNullable);
Expand Down

0 comments on commit 4e9be13

Please sign in to comment.