Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
serhii-solodilov opened this issue Oct 7, 2024 · 0 comments
Open

Comments

@serhii-solodilov
Copy link

serhii-solodilov commented Oct 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant