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

[Bug] Type mismatch: inferred type is QueryResult<R> but R was expected when generateAsync is set to true. #4374

Closed
yesitskev opened this issue Jul 14, 2023 · 1 comment · Fixed by #4378
Assignees

Comments

@yesitskev
Copy link

yesitskev commented Jul 14, 2023

SQLDelight Version

2.0.0-rc02

Operating System

Mac OS

Gradle Version

gradle-7.6.1-bin

Kotlin Version

1.8.22

Dialect

sqlite

AGP Version

No response

Describe the Bug

When setting generateAsync.set(true) in the gradle configuration, .sq files containing grouped statements which return a result, the compiled ExecutableQuery throws a compilation error:

Type mismatch: inferred type is QueryResult<R> but R was expected

An example grouped statement that would cause this issue:

insertResult {
INSERT INTO result(batch_test_id, status)
VALUES(?, ?);

SELECT last_insert_rowid();
}

Generated code by SqlDelight:

  private inner class InsertResultQuery<out T : Any>(
    public val batch_test_id: Long,
    public val status: String?,
    mapper: (SqlCursor) -> T,
  ) : ExecutableQuery<T>(mapper) {
    override fun <R> execute(mapper: (SqlCursor) -> QueryResult<R>): QueryResult<R> =
        QueryResult.AsyncValue {
      transactionWithResult {
        driver.execute(-522_152_271, """
            |INSERT INTO result(batch_test_id, status)
            |VALUES(?, ?)
            """.trimMargin(), 2) {
              bindLong(0, batch_test_id)
              bindString(1, status)
            }.await()
        // it is at the line below that has the compile error of
        // Type mismatch: inferred type is QueryResult<R> but R was expected
        driver.executeQuery(-522_152_270, """SELECT last_insert_rowid()""", mapper, 0)
      }
    }

    override fun toString(): String = "Result.sq:insertResult"
  }

Stacktrace

Type mismatch: inferred type is QueryResult<R> but R was expected

Gradle Build Script

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.8.22"
    application
    id("app.cash.sqldelight") version "2.0.0-rc02"
    id("org.jetbrains.kotlinx.dataframe") version "0.11.0"
}

group = "com.example"
version = "1.0-SNAPSHOT"

sqldelight {
    databases {
        create("Database") {
            packageName.set("com.example.data")
            generateAsync.set(true)
            deriveSchemaFromMigrations.set(false)
            verifyMigrations.set(false)
            version = 1
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.jetbrains.kotlinx:dataframe:0.11.0")
    implementation("org.jetbrains.kotlinx:kotlinx-cli-jvm:0.3.5")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2")
    implementation("org.jetbrains.kotlinx:kotlinx-datetime-jvm:0.4.0")
    implementation("app.cash.sqldelight:sqlite-driver:2.0.0-rc02")
    implementation("app.cash.sqldelight:coroutines-extensions:2.0.0-rc02")
    implementation("app.cash.sqldelight:primitive-adapters:2.0.0-rc02")
    implementation("com.squareup.okhttp3:logging-interceptor:4.10.0")
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")

    implementation(platform("io.arrow-kt:arrow-stack:1.2.0"))
    implementation("io.arrow-kt:arrow-core")
    implementation("io.arrow-kt:arrow-fx-coroutines")
    implementation("io.arrow-kt:arrow-core-retrofit")
}

repositories {
    mavenCentral()
}

application {
    mainClass.set("MainKt")
}
@yesitskev yesitskev added the bug label Jul 14, 2023
@dellisd
Copy link
Collaborator

dellisd commented Jul 14, 2023

This is definitely a bug and will be fixed. That being said, based on your gradle configuration you're targeting the JVM with the SQLite dialect which isn't a setup where you need to (or should) use generateAsync. Unless you plan to target Kotlin/JS where async drivers are needed, I would recommend not using generateAsync.

Either way, thank you for reporting this!

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

Successfully merging a pull request may close this issue.

3 participants