When google on this error, than I realize I’m not first one!
And I’m quite new - except two Udemy courses - to Kotlin but I try to find what’s going on.
It is existing code what I’m were I’m working on:
// In this function occurs the error. (every line is underscored red in IntelliJ)
override fun getReviewtSubject(caseId: CaseId, reviewSubjectId: ReviewSubjectId): ReviewSubject = usingDSL {
context ->
context.subjectSelect(caseId)
.from(REVIEW_SUBJECT)
.where(REVIEW_SUBJECT.CASE_ID.eq(caseId.value))
.and(REVIEW_SUBJECT.REVIEWSUBJECT_ID.eq(reviewSubjectId.value))
.fetchSingle(mapping(::ReviewSubject))
}
private fun DSLContext.subjectSelect(caseId: CaseId, mainUsage: Boolean? = false) = this.select(
CASE_SUBJECT.viewSubject.ID.convertFrom { ReviewSubjectId(it!!) },
CASE_SUBJECT.viewSubject.NAME.convertFrom { it!! },
CASE_SUBJECT.viewSubject.EXPLANATION.convertFrom { explanation -> explanation?.let { RichText(it) } },
CASE_SUBJECT.viewSubject.VALIDITY, // When I add this line I will get the error
// CASE_SUBJECT.viewSubject.VALIDITY.convertFrom { it?.vanaf },
// CASE_SUBJECT.viewSubject.VALIDITY.convertFrom { it?.totEnMet },
beoordelingsgidsProjection(CASE_SUBJECT.Reviewguide),
if (mainUsage == true) // but this is false, so else is executed
.... code
else
DSL.inline(null as mainUsage?),
)
data class ReviewSubject (
val id: ReviewSubjectId,
val name: String,
val explanation: RichText? = null,
val guide: Reviewguide? = null,
val validity: String? = null, // This line is added because I have add this in fun DSLcontext.subjectSelect
// val beginValidity: LocalDate? = null,
// val endValidity: LocalDate?= null,
val usage: mainUsage? = null,
)
I have to extend the backend query with the field Validity (and later with beginValidity & endValidity).
The first function fun getSubject(…) is called from the front-end API.
This function is calling the DSLContext.subjectSelect(…) called, only with the parameter ‘caseId’.
On the moment that I add the field ‘validity’ which I also define in the data class, then I get the error “Type mismatch: inferred type is Unit but ReviewSubject was expected” for the function fun getReviewtSubject((…).
If change the return type ‘ReviewSubject’ to ‘Unit’, what is suggested by IntelliJ, still get errors!
Also the Jooq lib is used here.
Can anyone give me an idea what is wrong and\or suggestion in which direction I have to search?
I go through the code but I have till now, I have no idea what is wrong, sorry.