Skip to content

Constructors parameters are wrongly assigned when compiled. (8.15.0) #709

@maxpiva

Description

@maxpiva

Version 8.15.0
After fixing this, Kotlin 1.9.25 and okhttp3 5.0.0-alpha.11 work correctly on IKVM 🙂
Kotlin lambdas are the most frequent offenders.

Example 1:

  .custom instance void [IKVM.Runtime]IKVM.Attributes.SignatureAttribute::.ctor(string) = ( 01 00 5C 4C 6A 61 76 61 2F 75 74 69 6C 2F 41 72   // ..\Ljava/util/Ar
                                                                                            72 61 79 4C 69 73 74 3C 4C 6B 6F 74 6C 69 6E 2F   // rayList<Lkotlin/
                                                                                            72 65 66 6C 65 63 74 2F 6A 76 6D 2F 69 6E 74 65   // reflect/jvm/inte
                                                                                            72 6E 61 6C 2F 69 6D 70 6C 2F 72 65 73 6F 6C 76   // rnal/impl/resolv
                                                                                            65 2F 63 6F 6E 73 74 61 6E 74 73 2F 43 6F 6E 73   // e/constants/Cons
                                                                                            74 61 6E 74 56 61 6C 75 65 3C 2A 3E 3B 3E 3B 00   // tantValue<*>;>;.
                                                                                            00 ) 
  .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 12 00 00 00 ) 
  .field assembly class kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl this$0
  .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 10 10 00 00 ) 
  .field assembly class kotlin.reflect.jvm.internal.impl.name.Name $name
  .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 10 10 00 00 ) 
  .field assembly class kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl/AbstractAnnotationArgumentVisitor this$1
  .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 10 10 00 00 ) 
  .method assembly hidebysig specialname rtspecialname 
          instance void  .ctor(class kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl $receiver1,
                               class kotlin.reflect.jvm.internal.impl.name.Name $name,
                               class kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl/AbstractAnnotationArgumentVisitor $receiver2) cil managed
  {
    .custom instance void [IKVM.Runtime]IKVM.Attributes.LineNumberTableAttribute::.ctor(uint8[]) = ( 01 00 07 00 00 00 9F 62 61 5F 03 69 2C 00 00 )    // .......ba_.i,..
    // Code size       57 (0x39)
    .maxstack  4
    .locals init (object V_0,
             class kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl$AbstractAnnotationArgumentVisitor$visitArray$1 V_1)
    IL_0000:  nop
    IL_0001:  ldarg.1
    IL_0002:  stloc.0
    IL_0003:  ldarg.0
    IL_0004:  ldloc.0
    IL_0005:  castclass  kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl
    IL_000a:  stfld      class kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl$AbstractAnnotationArgumentVisitor$visitArray$1::this$0
    IL_000f:  ldarg.0
    IL_0010:  ldarg.2
    IL_0011:  stfld      class kotlin.reflect.jvm.internal.impl.name.Name kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl$AbstractAnnotationArgumentVisitor$visitArray$1::$name
    IL_0016:  ldarg.0
    IL_0017:  ldloc.0
    IL_0018:  castclass  kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl/AbstractAnnotationArgumentVisitor
    IL_001d:  stfld      class kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl/AbstractAnnotationArgumentVisitor kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl$AbstractAnnotationArgumentVisitor$visitArray$1::this$1
    IL_0022:  nop
    IL_0023:  ldarg.0
    IL_0024:  call       instance void [IKVM.Java]java.lang.Object::.ctor()
    IL_0029:  ldarg.0
    IL_002a:  stloc.1
    IL_002b:  nop
    IL_002c:  ldarg.0
    IL_002d:  newobj     instance void [IKVM.Java]java.util.ArrayList::.ctor()
    IL_0032:  stfld      class [IKVM.Java]java.util.ArrayList kotlin.reflect.jvm.internal.impl.load.kotlin.BinaryClassAnnotationAndConstantLoaderImpl$AbstractAnnotationArgumentVisitor$visitArray$1::elements
    IL_0037:  nop
    IL_0038:  ret
  } // end of method BinaryClassAnnotationAndConstantLoaderImpl$AbstractAnnotationArgumentVisitor$visitArray$1::.ctor

In this case

IL_0017: ldloc.0 should be ldarg.3

Example 2:

       extends okio.ForwardingSink
{
  .custom instance void kotlin.MetadataAttribute::.ctor(object[]) = ( 01 00 0C 00 00 00 05 40 0E 11 4C 6B 6F 74 6C 69   // [email protected]
                                                                      6E 2F 4D 65 74 61 64 61 74 61 3B 0E 02 6D 76 1D   // n/Metadata;..mv.
                                                                      51 04 00 00 00 05 5B 08 01 00 00 00 08 07 00 00   // Q.....[.........
                                                                      00 08 01 00 00 00 0E 01 6B 08 01 00 00 00 0E 02   // ........k.......
                                                                      78 69 08 30 00 00 00 0E 02 64 31 1D 51 02 00 00   // xi.0.....d1.Q...
                                                                      00 05 5B 0E 29 00 11 0A 00 0A 02 18 02 0A 00 0A   // ..[.)...........
                                                                      02 10 02 0A 00 2A 01 00 08 0A 18 00 32 02 30 01   // .....*......2.0.
                                                                      4A 08 10 02 1A 02 30 03 48 16 C2 A8 06 04 0E 02   // J.....0.H.......
                                                                      64 32 1D 51 06 00 00 00 05 5B 0E 20 6F 6B 68 74   // d2.Q.....[. okht
                                                                      74 70 33 2F 43 61 63 68 65 24 52 65 61 6C 43 61   // tp3/Cache$RealCa
                                                                      63 68 65 52 65 71 75 65 73 74 24 31 0E 15 4C 6F   // cheRequest$1..Lo
                                                                      6B 69 6F 2F 46 6F 72 77 61 72 64 69 6E 67 53 69   // kio/ForwardingSi
                                                                      6E 6B 3B 0E 05 63 6C 6F 73 65 0E 00 0E 06 6F 6B   // nk;..close....ok
                                                                      68 74 74 70 00 00 )                               // http..
  .custom instance void [IKVM.Runtime]IKVM.Attributes.InnerClassAttribute::.ctor(string,
                                                                                 valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 20 6F 6B 68 74 74 70 33 2E 43 61 63 68 65   // .. okhttp3.Cache
                                                                                                                                        24 52 65 61 6C 43 61 63 68 65 52 65 71 75 65 73   // $RealCacheReques
                                                                                                                                        74 24 31 19 00 00 00 )                            // t$1....
  .custom instance void [IKVM.Runtime]IKVM.Attributes.EnclosingMethodAttribute::.ctor(string,
                                                                                      string,
                                                                                      string) = ( 01 00 1E 6F 6B 68 74 74 70 33 2E 43 61 63 68 65   // ...okhttp3.Cache
                                                                                                  24 52 65 61 6C 43 61 63 68 65 52 65 71 75 65 73   // $RealCacheReques
                                                                                                  74 06 3C 69 6E 69 74 3E 3E 28 4C 6F 6B 68 74 74   // t.<init>>(Lokhtt
                                                                                                  70 33 2E 43 61 63 68 65 3B 4C 6F 6B 68 74 74 70   // p3.Cache;Lokhttp
                                                                                                  33 2E 69 6E 74 65 72 6E 61 6C 2E 63 61 63 68 65   // 3.internal.cache
                                                                                                  2E 44 69 73 6B 4C 72 75 43 61 63 68 65 24 45 64   // .DiskLruCache$Ed
                                                                                                  69 74 6F 72 3B 29 56 00 00 )                      // itor;)V..
  .field assembly class okhttp3.Cache this$0
  .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 10 10 00 00 ) 
  .field assembly class okhttp3.Cache/RealCacheRequest this$1
  .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 10 10 00 00 ) 
  .method assembly hidebysig specialname rtspecialname 
          instance void  .ctor(class okhttp3.Cache $receiver1,
                               class okhttp3.Cache/RealCacheRequest $receiver2,
                               class okio.Sink $super_call_param$1) cil managed
  {
    .custom instance void [IKVM.Runtime]IKVM.Attributes.LineNumberTableAttribute::.ctor(uint8[]) = ( 01 00 04 00 00 00 9F 29 81 5B 00 00 )             // .......).[..
    // Code size       38 (0x26)
    .maxstack  2
    .locals init (object V_0)
    IL_0000:  nop
    IL_0001:  ldarg.1
    IL_0002:  stloc.0
    IL_0003:  ldarg.0
    IL_0004:  ldloc.0
    IL_0005:  castclass  okhttp3.Cache
    IL_000a:  stfld      class okhttp3.Cache okhttp3.Cache$RealCacheRequest$1::this$0
    IL_000f:  ldarg.0
    IL_0010:  ldloc.0
    IL_0011:  castclass  okhttp3.Cache/RealCacheRequest
    IL_0016:  stfld      class okhttp3.Cache/RealCacheRequest okhttp3.Cache$RealCacheRequest$1::this$1
    IL_001b:  nop
    IL_001c:  ldarg.0
    IL_001d:  ldarg.3
    IL_001e:  call       instance void okio.ForwardingSink::.ctor(class okio.Sink)
    IL_0023:  leave.s    IL_0025

    IL_0025:  ret
  } // end of method Cache$RealCacheRequest$1::.ctor

IL_0010: ldloc.0 should be ldarg.2

Example 3:

           extends okio.ForwardingSource
    {
      .custom instance void kotlin.MetadataAttribute::.ctor(object[]) = ( 01 00 0C 00 00 00 05 40 0E 11 4C 6B 6F 74 6C 69   // [email protected]
                                                                          6E 2F 4D 65 74 61 64 61 74 61 3B 0E 02 6D 76 1D   // n/Metadata;..mv.
                                                                          51 04 00 00 00 05 5B 08 01 00 00 00 08 07 00 00   // Q.....[.........
                                                                          00 08 01 00 00 00 0E 01 6B 08 01 00 00 00 0E 02   // ........k.......
                                                                          78 69 08 30 00 00 00 0E 02 64 31 1D 51 02 00 00   // xi.0.....d1.Q...
                                                                          00 05 5B 0E 41 00 17 0A 00 0A 02 18 02 0A 00 0A   // ..[.A...........
                                                                          02 10 0B 0A 00 0A 02 10 02 0A 00 2A 01 00 08 0A   // ...........*....
                                                                          18 00 32 02 30 01 4A 08 10 04 1A 02 30 05 48 16   // ..2.0.J.....0.H.
                                                                          52 0E 10 02 1A 02 30 03 58 C2 82 0E C2 A2 06 02   // R.....0.X.......
                                                                          0A 00 C2 A8 06 06 0E 02 64 32 1D 51 08 00 00 00   // ........d2.Q....
                                                                          05 5B 0E 35 6F 6B 68 74 74 70 33 2F 69 6E 74 65   // .[.5okhttp3/inte
                                                                          72 6E 61 6C 2F 63 61 63 68 65 2F 44 69 73 6B 4C   // rnal/cache/DiskL
                                                                          72 75 43 61 63 68 65 24 45 6E 74 72 79 24 6E 65   // ruCache$Entry$ne
                                                                          77 53 6F 75 72 63 65 24 31 0E 17 4C 6F 6B 69 6F   // wSource$1..Lokio
                                                                          2F 46 6F 72 77 61 72 64 69 6E 67 53 6F 75 72 63   // /ForwardingSourc
                                                                          65 3B 0E 06 63 6C 6F 73 65 64 0E 00 0E 05 63 6C   // e;..closed....cl
                                                                          6F 73 65 0E 00 0E 06 6F 6B 68 74 74 70 00 00 )    // ose....okhttp..
      .custom instance void [IKVM.Runtime]IKVM.Attributes.InnerClassAttribute::.ctor(string,
                                                                                     valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 FF 19 00 00 00 ) 
      .custom instance void [IKVM.Runtime]IKVM.Attributes.EnclosingMethodAttribute::.ctor(string,
                                                                                          string,
                                                                                          string) = ( 01 00 FF 09 6E 65 77 53 6F 75 72 63 65 10 28 49   // ....newSource.(I
                                                                                                      29 4C 6F 6B 69 6F 2E 53 6F 75 72 63 65 3B 00 00 ) // )Lokio.Source;..
      .field private bool closed
      .field assembly class okhttp3.internal.cache.DiskLruCache this$0
      .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 10 10 00 00 ) 
      .field assembly class okhttp3.internal.cache.DiskLruCache/Entry this$1
      .custom instance void [IKVM.Runtime]IKVM.Attributes.ModifiersAttribute::.ctor(valuetype [IKVM.Runtime]IKVM.Attributes.Modifiers) = ( 01 00 10 10 00 00 ) 
      .method assembly hidebysig specialname rtspecialname 
              instance void  .ctor(class okio.Source $fileSource,
                                   class okhttp3.internal.cache.DiskLruCache $receiver1,
                                   class okhttp3.internal.cache.DiskLruCache/Entry $receiver2) cil managed
      {
        .custom instance void [IKVM.Runtime]IKVM.Attributes.LineNumberTableAttribute::.ctor(uint8[]) = ( 01 00 04 00 00 00 9E 89 61 5B 00 00 )             // ........a[..
        // Code size       38 (0x26)
        .maxstack  2
        .locals init (object V_0)
        IL_0000:  nop
        IL_0001:  ldarg.2
        IL_0002:  stloc.0
        IL_0003:  ldarg.0
        IL_0004:  ldloc.0
        IL_0005:  castclass  okhttp3.internal.cache.DiskLruCache
        IL_000a:  stfld      class okhttp3.internal.cache.DiskLruCache okhttp3.internal.cache.DiskLruCache/Entry/newSource$1::this$0
        IL_000f:  ldarg.0
        IL_0010:  ldloc.0
        IL_0011:  castclass  okhttp3.internal.cache.DiskLruCache/Entry
        IL_0016:  stfld      class okhttp3.internal.cache.DiskLruCache/Entry okhttp3.internal.cache.DiskLruCache/Entry/newSource$1::this$1
        IL_001b:  nop
        IL_001c:  ldarg.0
        IL_001d:  ldarg.1
        IL_001e:  call       instance void okio.ForwardingSource::.ctor(class okio.Source)
        IL_0023:  leave.s    IL_0025

        IL_0025:  ret
      } // end of method newSource$1::.ctor

IL_0010: ldloc.0 should be ldarg.3

How it look from dotPeek:

Image

If anyone can point me to the relevant area in IKVM to modify, I’m happy to open a PR.
I’m currently working around the issue with a Mono.Cecil patcher.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions