Skip to content

Commit

Permalink
Revert "[FE 1.0] Take care callable reference candidates with recursi…
Browse files Browse the repository at this point in the history
…ve candidate return type"

This reverts commit d04beaa.
  • Loading branch information
petukhovv authored and Space committed May 26, 2022
1 parent 1df9fea commit 1adc50b
Show file tree
Hide file tree
Showing 32 changed files with 53 additions and 217 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,6 @@ class DiagnosticReporterByTrackingStrategy(
SmartCastDiagnostic::class.java -> reportSmartCast(diagnostic as SmartCastDiagnostic)
UnstableSmartCastDiagnosticError::class.java,
UnstableSmartCastResolutionError::class.java -> reportUnstableSmartCast(diagnostic as UnstableSmartCast)
TypeCheckerHasRanIntoRecursion::class.java -> {
diagnostic as TypeCheckerHasRanIntoRecursion
val argumentExpression =
diagnostic.onArgument?.psiCallArgument?.valueArgument?.getArgumentExpression()
if (argumentExpression != null) {
trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.errorFactory.on(argumentExpression))
}
}
VisibilityErrorOnArgument::class.java -> {
diagnostic as VisibilityErrorOnArgument
val invisibleMember = diagnostic.invisibleMember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class NewResolutionOldInference(
extensionReceiverCandidates: List<ReceiverValueWithSmartCastInfo>
): MyCandidate = error("${this::class.simpleName} doesn't support candidates with multiple extension receiver candidates")

override fun createErrorCandidate(reason: ErrorCandidateReason): MyCandidate {
override fun createErrorCandidate(): MyCandidate {
throw IllegalStateException("Not supported creating error candidate for the old type inference candidate factory")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.types.error.LazyWrappedTypeComputationException;

public class ReenteringLazyValueComputationException extends LazyWrappedTypeComputationException {
public class ReenteringLazyValueComputationException extends RuntimeException {
public ReenteringLazyValueComputationException() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.tower.RecursiveCallableReferenceType
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityErrorOnArgument
import org.jetbrains.kotlin.resolve.calls.tower.isInapplicable
import org.jetbrains.kotlin.resolve.calls.model.TypeCheckerHasRanIntoRecursion

class CallableReferenceArgumentResolver(val callableReferenceOverloadConflictResolver: CallableReferenceOverloadConflictResolver) {
fun processCallableReferenceArgument(
Expand Down Expand Up @@ -48,7 +46,6 @@ class CallableReferenceArgumentResolver(val callableReferenceOverloadConflictRes
val transformedDiagnostic = when (it) {
is CompatibilityWarning -> CompatibilityWarningOnArgument(argument, it.candidate)
is VisibilityError -> VisibilityErrorOnArgument(argument, it.invisibleMember)
is RecursiveCallableReferenceType -> TypeCheckerHasRanIntoRecursion(argument)
else -> it
}
diagnosticsHolder.addDiagnostic(transformedDiagnostic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class KotlinCallCompleter(
constraintSystem.errors.forEach(diagnosticsHolder::addError)

if (returnType is ErrorType && returnType.kind == ErrorTypeKind.RECURSIVE_TYPE) {
diagnosticsHolder.addDiagnostic(TypeCheckerHasRanIntoRecursion())
diagnosticsHolder.addDiagnostic(TypeCheckerHasRanIntoRecursion)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.tower.*
import org.jetbrains.kotlin.resolve.calls.util.ErrorCandidateReason
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.error.*
import org.jetbrains.kotlin.types.error.ErrorScopeKind
import org.jetbrains.kotlin.types.error.ErrorUtils
import org.jetbrains.kotlin.types.error.ErrorTypeKind
import org.jetbrains.kotlin.types.expressions.CoercionStrategy
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.utils.SmartList
Expand All @@ -43,7 +43,7 @@ class CallableReferencesCandidateFactory(
private val CallableReceiver.asReceiverValueForVisibilityChecks: ReceiverValue
get() = receiver.receiverValue

override fun createErrorCandidate(reason: ErrorCandidateReason): CallableReferenceResolutionCandidate {
override fun createErrorCandidate(): CallableReferenceResolutionCandidate {
val errorScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE, kotlinCall.toString())
val errorDescriptor = errorScope.getContributedFunctions(kotlinCall.rhsName, scopeTower.location).first()

Expand All @@ -56,36 +56,21 @@ class CallableReferencesCandidateFactory(
buildTypeWithConversions = kotlinCall is CallableReferenceKotlinCallArgument
)

val candidate = CallableReferenceResolutionCandidate(
return CallableReferenceResolutionCandidate(
errorDescriptor, dispatchReceiver = null, extensionReceiver = null,
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, reflectionCandidateType, callableReferenceAdaptation,
kotlinCall, expectedType, callComponents, scopeTower, resolutionCallbacks, baseSystem
)

when (reason) {
ErrorCandidateReason.TYPE_COMPUTATION_RECURSION -> candidate.addDiagnostic(RecursiveCallableReferenceType)
ErrorCandidateReason.OTHER -> {}
}

return candidate
}

private fun KotlinType.isErrorRecursiveType(): Boolean {
val unwrapped = if (this is WrappedType && isComputed()) unwrap() else this
return unwrapped is ErrorType && unwrapped.kind == ErrorTypeKind.RECURSIVE_TYPE
}

private fun createCandidateInternal(
override fun createCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
explicitReceiverKind: ExplicitReceiverKind,
extensionReceiver: ReceiverValueWithSmartCastInfo?
): CallableReferenceResolutionCandidate {
val dispatchCallableReceiver = towerCandidate.dispatchReceiver?.let {
toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER)
}
val extensionCallableReceiver = extensionReceiver?.let {
toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.EXTENSION_RECEIVER)
}
val dispatchCallableReceiver =
towerCandidate.dispatchReceiver?.let { toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER) }
val extensionCallableReceiver = extensionReceiver?.let { toCallableReceiver(it, explicitReceiverKind == ExplicitReceiverKind.EXTENSION_RECEIVER) }
val candidateDescriptor = towerCandidate.descriptor
val diagnostics = SmartList<KotlinCallDiagnostic>()

Expand Down Expand Up @@ -137,30 +122,6 @@ class CallableReferencesCandidateFactory(
return createCallableReferenceCallCandidate(diagnostics)
}

override fun createCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
explicitReceiverKind: ExplicitReceiverKind,
extensionReceiver: ReceiverValueWithSmartCastInfo?
): CallableReferenceResolutionCandidate =
createRecursionTolerantCandidate(towerCandidate, explicitReceiverKind, extensionReceiver) {
createErrorCandidate(ErrorCandidateReason.TYPE_COMPUTATION_RECURSION)
}

private fun createRecursionTolerantCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
explicitReceiverKind: ExplicitReceiverKind,
extensionReceiver: ReceiverValueWithSmartCastInfo?,
onRecursion: () -> CallableReferenceResolutionCandidate,
): CallableReferenceResolutionCandidate =
try {
val resolutionCandidate = createCandidateInternal(towerCandidate, explicitReceiverKind, extensionReceiver)
val returnType = resolutionCandidate.candidate.returnType

if (returnType == null || !returnType.isErrorRecursiveType()) resolutionCandidate else onRecursion()
} catch (e: LazyWrappedTypeComputationException) {
onRecursion()
}

/**
* The function is called only inside [NoExplicitReceiverScopeTowerProcessor] with [TowerData.BothTowerLevelAndContextReceiversGroup].
* This case involves only [SimpleCandidateFactory].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,8 @@ class WrongCountOfTypeArguments(
override fun report(reporter: DiagnosticReporter) = reporter.onTypeArguments(this)
}

class TypeCheckerHasRanIntoRecursion(val onArgument: KotlinCallArgument? = null) : KotlinCallDiagnostic(INAPPLICABLE) {
override fun report(reporter: DiagnosticReporter) {
return if (onArgument != null) {
reporter.onCallArgument(onArgument, this)
} else {
reporter.onCall(this)
}
}
object TypeCheckerHasRanIntoRecursion : KotlinCallDiagnostic(INAPPLICABLE) {
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
}

// Callable reference resolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.tower.*
import org.jetbrains.kotlin.resolve.calls.util.ErrorCandidateReason
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
import org.jetbrains.kotlin.types.error.ErrorUtils
Expand Down Expand Up @@ -161,7 +160,7 @@ class SimpleCandidateFactory(
return candidate
}

override fun createErrorCandidate(reason: ErrorCandidateReason): SimpleResolutionCandidate {
override fun createErrorCandidate(): SimpleResolutionCandidate {
val errorScope = ErrorUtils.createErrorScope(ErrorScopeKind.SCOPE_FOR_ERROR_RESOLUTION_CANDIDATE, kotlinCall.toString())
val errorDescriptor = if (kotlinCall.callKind == KotlinCallKind.VARIABLE) {
errorScope.getContributedVariables(kotlinCall.name, scopeTower.location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ object ResolvedUsingNewFeatures : ResolutionDiagnostic(RESOLVED_NEED_PRESERVE_CO
object UnstableSmartCastDiagnostic : ResolutionDiagnostic(UNSTABLE_SMARTCAST)
object HiddenExtensionRelatedToDynamicTypes : ResolutionDiagnostic(HIDDEN)
object HiddenDescriptor : ResolutionDiagnostic(HIDDEN)
object RecursiveCallableReferenceType : ResolutionDiagnostic(INAPPLICABLE)

object InvokeConventionCallNoOperatorModifier : ResolutionDiagnostic(CONVENTION_ERROR)
object InfixCallNoInfixModifier : ResolutionDiagnostic(CONVENTION_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.tower
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.calls.util.ErrorCandidateReason
import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST
import org.jetbrains.kotlin.resolve.scopes.HierarchicalScope
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
Expand Down Expand Up @@ -48,7 +47,7 @@ interface CandidateFactory<out C : Candidate> {
extensionReceiver: ReceiverValueWithSmartCastInfo?
): C

fun createErrorCandidate(reason: ErrorCandidateReason = ErrorCandidateReason.OTHER): C
fun createErrorCandidate(): C

fun createCandidate(
towerCandidate: CandidateWithBoundDispatchReceiver,
Expand Down

This file was deleted.

15 changes: 0 additions & 15 deletions compiler/testData/codegen/box/callableReference/kt51844.kt

This file was deleted.

2 changes: 1 addition & 1 deletion compiler/testData/diagnostics/tests/delegation/kt49477.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ infix fun filter(filter: (R, Any?) -> Boolean): Delegate<R, T>
class GitLabChangesProcessor: DatabaseEntity {
var buildProcessors by <!DEBUG_INFO_EXPRESSION_TYPE("Delegate<GitLabChangesProcessor, kotlin.collections.MutableCollection<GitLabBuildProcessor>>"), TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR!>child_many(
GitLabBuildProcessor::class.java,
<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR, TYPE_MISMATCH!>GitLabBuildProcessor::<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>processor<!><!>
GitLabBuildProcessor::processor
)<!>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ infix fun filter(filter: (R, Any?) -> Boolean): Delegate<R, T>
class GitLabChangesProcessor: DatabaseEntity {
var buildProcessors by <!DEBUG_INFO_EXPRESSION_TYPE("Delegate<GitLabChangesProcessor, kotlin.collections.MutableCollection<GitLabBuildProcessor>>"), TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR!>child_many(
GitLabBuildProcessor::class.java,
<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR, TYPE_MISMATCH!>GitLabBuildProcessor::<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>processor<!><!>
GitLabBuildProcessor::processor
)<!>
}

Expand Down
11 changes: 0 additions & 11 deletions compiler/testData/diagnostics/tests/inference/kt51844.fir.kt

This file was deleted.

11 changes: 0 additions & 11 deletions compiler/testData/diagnostics/tests/inference/kt51844.kt

This file was deleted.

11 changes: 0 additions & 11 deletions compiler/testData/diagnostics/tests/inference/kt51844.txt

This file was deleted.

31 changes: 31 additions & 0 deletions compiler/testData/diagnostics/tests/platformTypes/kt50877.fir.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// FULL_JDK
// WITH_STDLIB

// FILE: Schematic.kt
class Schematic {
var name: String? = null

var error: String? = null

override fun toString(): String {
return name!!
}
}

// FILE: SortedListModel.java
import java.util.Comparator;

public class SortedListModel<T> {
public SortedListModel(Comparator<? super T> comparator) {
}
}


// FILE: main.kt
val model = SortedListModel<Schematic>(Comparator.comparing { b1: Schematic ->
when {
b1.error != null -> 2
b1.name!!.contains(":") -> 1
else -> 0
}
}.thenComparing { b1: Schematic -> b1.name!! })
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// FULL_JDK
// WITH_STDLIB

Expand Down
Loading

0 comments on commit 1adc50b

Please sign in to comment.