#1549·wcdb

[Android][KSP] Generated Kotlin ORM fails to compile for auto-increment Long primary key (Operator '==' cannot be applied to 'Long' and 'Int')

Author: Suosuo123Created Jun 8, 2026Updated Jun 8, 2026

Environment

  • WCDB 2.1.15 (com.tencent.wcdb:compiler / main / annotation)
  • Annotation processing via KSP (com.google.devtools.ksp), Kotlin 2.x, AGP 9, Android

Problem

For a Kotlin @WCDBTableCoding model with an auto-increment Long primary key, the KSP-generated ORM (DBXxxModel.kt) emits an isAutoIncrement that does not compile:

kotlin
override fun isAutoIncrement(`object`: KspAutoIncProbe): Boolean {
    return `object`.databaseId == 0
}

databaseId is Long, the literal 0 is Int, and Kotlin rejects mixed-type ==:

e: .../DBKspAutoIncProbe.kt:83:10 Operator '==' cannot be applied to 'Long' and 'Int'.

So any Kotlin model with an auto-increment Long primary key fails to compile. The Java generator is unaffected because Java applies numeric promotion for long == 0; Kotlin does not allow Long == Int.

The field must stay Long (the generated setLastInsertRowId(object, lastInsertRowId: Long) assigns a Long, and rowid is 64-bit), so it cannot be worked around on the model side.

Minimal reproduction

kotlin
package com.example

import com.tencent.wcdb.WCDBField
import com.tencent.wcdb.WCDBTableCoding

@WCDBTableCoding
class KspAutoIncProbe {
    @WCDBField(isPrimary = true, isAutoIncrement = true)
    var databaseId: Long = 0

    @WCDBField
    var nullableLong: Long? = null
}

Build with the KSP processor. The generated DBKspAutoIncProbe.kt contains return \object`.databaseId == 0`, which fails Kotlin compilation.

Suggested fix

Emit a Long literal in the generated comparison for Long fields, e.g. \object`.databaseId == 0L(or.toLong()), wherever the Kotlin generator compares a Long` field against an integer literal.

Question

Is this already fixed in 2.1.16 (current latest)? We are on 2.1.15 and would like to migrate our Java ORM models to Kotlin once the generated Kotlin compiles for auto-increment Long primary keys.