google/flatbuffers

[Kotlin] parameter name isn't the same as its usage in struct

Opened this issue · 0 comments

There is an inconsistency in the parameter naming generated by FlatBuffers for the Second.kt file. Specifically:

The generated parameter in the createSecond function is named opFirst_final, but the usage inside the function refers to op_first_final. Might be related to struct, because table works fine.

Steps to Reproduce:

  1. Use the following schema in Best.fbs:
struct First {
    first: uint16;
}

struct Second {
    op_first: First;
}

table Third {
    or_second: [Second] (required);
}

root_type Third;
  1. Run the following FlatBuffers command:
    flatc -o . --kotlin Best.fbs

  2. Inspect the generated Kotlin code, particularly in Second.kt, and observe the following discrepancy:

class Second : Struct() {

    fun __init(_i: Int, _bb: ByteBuffer)  {
        __reset(_i, _bb)
    }
    fun __assign(_i: Int, _bb: ByteBuffer) : Second {
        __init(_i, _bb)
        return this
    }
    val opFirst : First? get() = opFirst(First())
    fun opFirst(obj: First) : First? = obj.__assign(bb_pos + 0, bb)
    companion object {
        fun createSecond(builder: FlatBufferBuilder, opFirst_final: UShort) : Int {
            builder.prep(2, 2)
            builder.prep(2, 2)
            builder.putShort(op_first_final.toShort())
            return builder.offset()
        }
    }
}

Expected Behavior:
Generated and used parameters for op_first_final should be the same.

Actual Behavior:
The parameter is declared as opFirst_final, but the function uses op_first_final, causing the issues.