Skip to content

Commit 8af7170

Browse files
paulovapLuckyRu
authored andcommitted
[Kotlin] Fix union vector accessor after change in Java API (google#5605)
Kolin uses java library as dependency, which changed the way it access union vector recently (e365c50). This changes updates kotlin code generation to match Java's changes.
1 parent bdf1086 commit 8af7170

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/idl_gen_kotlin.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,6 @@ class KotlinGenerator : public BaseGenerator {
975975
params = "obj: " + field_type + ", j: Int";
976976
}
977977

978-
979-
writer.SetValue("toType", "YYYYY");
980-
981978
auto ret_type = return_type + nullable;
982979
GenerateFun(writer, field_name, params, ret_type, [&](){
983980
auto inline_size = NumToString(InlineSize(vectortype));
@@ -1008,7 +1005,7 @@ class KotlinGenerator : public BaseGenerator {
10081005
GenerateFun(writer, field_name, "obj: " + field_type,
10091006
return_type + "?", [&](){
10101007
writer += OffsetWrapperOneLine(offset_val,
1011-
bbgetter + "(obj, o)",
1008+
bbgetter + "(obj, o + bb_pos)",
10121009
"null");
10131010
});
10141011
break;

tests/MyGame/Example/Monster.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Monster : Table() {
116116
}
117117
}
118118
fun test(obj: Table) : Table? {
119-
val o = __offset(20); return if (o != 0) __union(obj, o) else null
119+
val o = __offset(20); return if (o != 0) __union(obj, o + bb_pos) else null
120120
}
121121
fun test4(j: Int) : MyGame.Example.Test? = test4(MyGame.Example.Test(), j)
122122
fun test4(obj: MyGame.Example.Test, j: Int) : MyGame.Example.Test? {
@@ -717,7 +717,7 @@ class Monster : Table() {
717717
}
718718
}
719719
fun anyUnique(obj: Table) : Table? {
720-
val o = __offset(92); return if (o != 0) __union(obj, o) else null
720+
val o = __offset(92); return if (o != 0) __union(obj, o + bb_pos) else null
721721
}
722722
val anyAmbiguousType : UByte
723723
get() {
@@ -734,7 +734,7 @@ class Monster : Table() {
734734
}
735735
}
736736
fun anyAmbiguous(obj: Table) : Table? {
737-
val o = __offset(96); return if (o != 0) __union(obj, o) else null
737+
val o = __offset(96); return if (o != 0) __union(obj, o + bb_pos) else null
738738
}
739739
fun vectorOfEnums(j: Int) : UByte {
740740
val o = __offset(98)

tests/union_vector/Movie.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Movie : Table() {
3030
}
3131
}
3232
fun mainCharacter(obj: Table) : Table? {
33-
val o = __offset(6); return if (o != 0) __union(obj, o) else null
33+
val o = __offset(6); return if (o != 0) __union(obj, o + bb_pos) else null
3434
}
3535
fun charactersType(j: Int) : UByte {
3636
val o = __offset(8)

0 commit comments

Comments
 (0)