[FIR] Fix FirDuplicateParameterNameInFunctionTypeChecker

It was supposed to check only function types...

Also note that it's probably impossible
to write a simpler test right now,
because we have a massive problem that
we ignore `FirTypeRef`s with `null`
sources despite having a dedicated
family of checkers for them
specifically. This will be fixed
separately as KT-65647.

^KT-65584 Fixed
^KT-65647
This commit is contained in:
Nikolay Lunyak
2024-02-07 18:04:37 +02:00
committed by Space Team
parent 8ec248131d
commit 3db7df6898
4 changed files with 4 additions and 47 deletions
@@ -13,14 +13,11 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
import org.jetbrains.kotlin.fir.expressions.FirLiteralExpression
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.customAnnotations
import org.jetbrains.kotlin.fir.types.type
import org.jetbrains.kotlin.fir.types.*
object FirDuplicateParameterNameInFunctionTypeChecker : FirTypeRefChecker(MppCheckerKind.Common) {
override fun check(typeRef: FirTypeRef, context: CheckerContext, reporter: DiagnosticReporter) {
if (typeRef !is FirResolvedTypeRef) return
if (typeRef !is FirResolvedTypeRef || !typeRef.type.isSomeFunctionType(context.session)) return
val nameToArgumentProjection = typeRef.type.typeArguments.dropLast(1).groupBy {
val type = it.type ?: return@groupBy null
@@ -1,41 +0,0 @@
// ISSUE: KT-65584
// WITH_STDLIB
fun interface Flow<out T> {
suspend fun collect(collector: FlowCollector<T>)
}
fun interface FlowCollector<in T> {
suspend fun emit(value: T)
}
inline fun <T, R> Flow<T>.flatMapLatest(crossinline transform: suspend (value: T) -> Flow<R>) = Flow { collector ->
collect { it1 -> transform(it1).collect { it2 -> collector.emit(it2) } }
}
fun <T> flowOf(value: T): Flow<T> = Flow { collector -> collector.emit(value) }
inline fun <T, R> Flow<T>.map(crossinline transform: suspend (value: T) -> R): Flow<R> = Flow { collector ->
collect { collector.emit(transform(it)) }
}
// ------
class StationId
class Playable
class Entity(val stationId: StationId)
class State(val playbackEntity: Entity)
internal suspend fun init(
queueState: State,
state: Flow<Playable>
) {
state
.flatMapLatest { playable ->
flowOf(playable).map { Triple(it, playable, queueState.playbackEntity.stationId) }
}
.collect { <!DUPLICATE_PARAMETER_NAME_IN_FUNCTION_TYPE!>(likeState, playable, stationId)<!> ->
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// ISSUE: KT-65584
// WITH_STDLIB
@@ -8,7 +8,7 @@ class MyTriple<T, K, M>(val a: T, val b: K, val c: M)
fun test() {
giveItName(10) {
MyTriple(it, it, it).also { <!DUPLICATE_PARAMETER_NAME_IN_FUNCTION_TYPE!>self<!> -> }
MyTriple(it, it, it).also { self -> }
(duplicateIt(it) { a, b -> }).also { <!DUPLICATE_PARAMETER_NAME_IN_FUNCTION_TYPE!>function<!> -> }
}
}