mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 18:34:12 +00:00
[Kotlin] Fix Access to union of vector element (#5994)
Kotlin code generation was producing wrong logic for accessors of vector of union elements. This was shadowed by the fact[1] that asserts in Kotlin are silently ignored unless the flag "-ea" is passed to the JVM. The tests are also updated to enable asserts. 1 - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/assert.html
This commit is contained in:
@@ -942,7 +942,7 @@ class KotlinGenerator : public BaseGenerator {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BASE_TYPE_UNION:
|
case BASE_TYPE_UNION:
|
||||||
found = "{{bbgetter}}(obj, {{index}} - bb_pos){{ucast}}";
|
found = "{{bbgetter}}(obj, {{index}}){{ucast}}";
|
||||||
break;
|
break;
|
||||||
default: found = "{{bbgetter}}({{index}}){{ucast}}";
|
default: found = "{{bbgetter}}({{index}}){{ucast}}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ class KotlinTest {
|
|||||||
|
|
||||||
val monster = Monster.getRootAsMonster(bb)
|
val monster = Monster.getRootAsMonster(bb)
|
||||||
|
|
||||||
assert(monster.testhashu32Fnv1 == (1u + Integer.MAX_VALUE.toUInt()))
|
assert(monster.testhashu32Fnv1 == (Integer.MAX_VALUE + 1L).toUInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TestNamespaceNesting() {
|
fun TestNamespaceNesting() {
|
||||||
@@ -331,7 +331,7 @@ class KotlinTest {
|
|||||||
Monster.addTest4(fbb, test4)
|
Monster.addTest4(fbb, test4)
|
||||||
Monster.addTestarrayofstring(fbb, testArrayOfString)
|
Monster.addTestarrayofstring(fbb, testArrayOfString)
|
||||||
Monster.addTestbool(fbb, true)
|
Monster.addTestbool(fbb, true)
|
||||||
Monster.addTesthashu32Fnv1(fbb, UInt.MAX_VALUE + 1u)
|
Monster.addTesthashu32Fnv1(fbb, (Integer.MAX_VALUE + 1L).toUInt())
|
||||||
Monster.addTestarrayoftables(fbb, sortMons)
|
Monster.addTestarrayoftables(fbb, sortMons)
|
||||||
val mon = Monster.endMonster(fbb)
|
val mon = Monster.endMonster(fbb)
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ kotlinc $all_kt_files -classpath $targetdir -include-runtime -d $targetdir
|
|||||||
# Make jar
|
# Make jar
|
||||||
jar cvf ${testdir}/kotlin_test.jar -C $targetdir . > /dev/null
|
jar cvf ${testdir}/kotlin_test.jar -C $targetdir . > /dev/null
|
||||||
# Run test
|
# Run test
|
||||||
kotlin -cp ${testdir}/kotlin_test.jar KotlinTest
|
kotlin -J"-ea" -cp ${testdir}/kotlin_test.jar KotlinTest
|
||||||
# clean up
|
# clean up
|
||||||
rm -rf $targetdir
|
rm -rf $targetdir
|
||||||
rm ${testdir}/kotlin_test.jar
|
rm ${testdir}/kotlin_test.jar
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class Movie : Table() {
|
|||||||
fun characters(obj: Table, j: Int) : Table? {
|
fun characters(obj: Table, j: Int) : Table? {
|
||||||
val o = __offset(10)
|
val o = __offset(10)
|
||||||
return if (o != 0) {
|
return if (o != 0) {
|
||||||
__union(obj, __vector(o) + j * 4 - bb_pos)
|
__union(obj, __vector(o) + j * 4)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user