diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt index fb8f6ef3bc1..c0a1020eb43 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt @@ -41,6 +41,8 @@ import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.types.Variance +import org.jetbrains.kotlin.utils.addToStdlib.runIf +import org.jetbrains.kotlin.utils.addToStdlib.unreachableBranch private val SAM_PARAMETER_NAME = Name.identifier("function") @@ -73,14 +75,13 @@ class FirSamResolver( val upperType = getFunctionTypeForPossibleSamType(type.upperBound) ?: return null ConeFlexibleType(lowerType.lowerBoundIfFlexible(), upperType.upperBoundIfFlexible()) } - is ConeStubType -> null - // TODO: support those types as well - is ConeTypeParameterType, is ConeTypeVariableType, + + is ConeStubType, is ConeTypeParameterType, is ConeTypeVariableType, is ConeCapturedType, is ConeDefinitelyNotNullType, is ConeIntersectionType, is ConeIntegerLiteralType, -> null - // TODO: Thing of getting rid of this branch since ConeLookupTagBasedType should be a sealed class - is ConeLookupTagBasedType -> null + + is ConeLookupTagBasedType -> unreachableBranch(type) } } @@ -282,7 +283,6 @@ private fun FirRegularClass.getSingleAbstractMethodOrNull( session: FirSession, scopeSession: ScopeSession, ): FirSimpleFunction? { - // TODO: restrict to Java interfaces if (classKind != ClassKind.INTERFACE || hasMoreThenOneAbstractFunctionOrHasAbstractProperty()) return null val samCandidateNames = computeSamCandidateNames(session) diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt index ef56069fdaa..a5de062f2cd 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt @@ -334,3 +334,10 @@ private inline fun Iterable.zipWithDefault(other: Iterable, leftDef fun Iterable.zipWithNulls(other: Iterable): List> { return zipWithDefault(other, { null }, { null }) } + +/** + * Use this function to indicate that some when branch is semantically unreachable + */ +fun unreachableBranch(argument: Any?): Nothing { + error("This argument should've been processed by previous when branches but it wasn't: $argument") +}