out of curiosity i’ve started peeking into the kot...
# announcements
m
out of curiosity i’ve started peeking into the kotlin byte code again. This time though ive been noticing some off behavior when decompiled back to java. Notice the random boolean declarations that are not used, these are littered throughout, anyone have any insight their use may be?
Copy code
@NotNull
   public final List makeCachedVendorList(@Nullable Integer size) {
      int var2 = size != null ? size : TestDataFactory.INSTANCE.randomInt(1, 15);
      boolean var3 = false;
      boolean var4 = false;
      ArrayList var5 = new ArrayList(var2);
      boolean var6 = false;
      boolean var7 = false;
      int var15 = 0;

      for(int var8 = var2; var15 < var8; ++var15) {
         boolean var10 = false;
         int var12 = false;
         CachedVendor var14 = makeCachedVendor$default(INSTANCE, 0, 1, (Object)null);
         var5.add(var14);
      }

      return (List)var5;
   }
e
What’s the original Kotlin source?
m
In this example it’s just a couple of functions generating test data
Copy code
fun makeCachedVendorList(size: Int? = null): List<CachedVendor> {
    return List(size ?: TestDataFactory.randomInt(1, 15)) {
        makeCachedVendor()
    }
}

fun makeCachedVendor(
    id: Int = TestDataFactory.randomInt(),
    distance: Int = TestDataFactory.randomInt()
): CachedVendor {
    return with(TestDataFactory) {
        CachedVendor(
            id = id,
            name = randomString(),
            images = listOf(randomString()),
            distance = distance
        )
    }
}
Here is the `randomInt() function for reference:
Copy code
fun randomInt(min: Int = 0, max: Int = 10000): Int {
    return ThreadLocalRandom.current().nextInt(min, max + 1)
}
i
These variables are generated by inliner for debugger to determine whether we are inside inline function/lambda or not.
👍 1