diff --git a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt index 5367a942881..773a9c01646 100644 --- a/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt +++ b/sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij/inspections/UnusedQueryInspection.kt @@ -38,7 +38,12 @@ internal class UnusedQueryInspection : LocalInspectionTool() { fileName, GlobalSearchScope.moduleScope(module), ).firstOrNull() as KtFile? ?: return PsiElementVisitor.EMPTY_VISITOR - val allMethods = generatedFile.classes[0].methods + val allMethods = generatedFile.classes.firstOrNull()?.methods + + if (allMethods == null) { + return PsiElementVisitor.EMPTY_VISITOR + } + return object : SqlDelightVisitor() { override fun visitStmtIdentifier(o: SqlDelightStmtIdentifier) = ignoreInvalidElements { if (o !is StmtIdentifierMixin || o.identifier() == null) {