diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java index 575fac17455..191f91ff8de 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java @@ -1978,6 +1978,34 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/delegates") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Delegates extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInDelegates() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/delegates"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt31219.kt") + public void testKt31219() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.kt"); + } + + @TestMetadata("kt31679.kt") + public void testKt31679() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.kt"); + } + + @TestMetadata("kt32249.kt") + public void testKt32249() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inline") diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index 040ad349541..09a1aafab69 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -9,9 +9,11 @@ import com.google.common.collect.Lists import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.VariableAccessorDescriptor +import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors import org.jetbrains.kotlin.diagnostics.Errors.* -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext.* @@ -25,7 +27,6 @@ import org.jetbrains.kotlin.resolve.calls.context.ContextDependency import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemCompleter import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter -import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.FROM_COMPLETER import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor import org.jetbrains.kotlin.resolve.calls.inference.toHandle @@ -36,9 +37,7 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.calls.tower.PSICallResolver -import org.jetbrains.kotlin.resolve.calls.tower.ResolutionResultCallInfo import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor -import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.ScopeUtils import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver @@ -87,7 +86,7 @@ class DelegatedPropertyResolver( ScopeUtils.makeScopeForPropertyInitializer(propertyHeaderScope, variableDescriptor) else propertyHeaderScope - val byExpressionType =resolveDelegateExpression( + val byExpressionType = resolveDelegateExpression( delegateExpression, property, variableDescriptor, initializerScope, trace, outerDataFlowInfo, inferenceSession ) @@ -372,7 +371,7 @@ class DelegatedPropertyResolver( val resolutionResult = fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, functionName, delegateExpression) - trace.record(BindingContext.DELEGATED_PROPERTY_CALL, accessor, resolutionResult.first) + trace.record(DELEGATED_PROPERTY_CALL, accessor, resolutionResult.first) return resolutionResult.second } @@ -475,9 +474,18 @@ class DelegatedPropertyResolver( dataFlowInfo: DataFlowInfo, inferenceSession: InferenceSession ): KotlinType { - val traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property") - val propertyExpectedType = if (property.typeReference != null) variableDescriptor.type else NO_EXPECTED_TYPE + + resolveWithNewInference( + delegateExpression, + variableDescriptor, + scopeForDelegate, + trace, + dataFlowInfo, + inferenceSession + )?.let { return it } + + val traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property") val completer = ConstraintSystemCompleterImpl( property, propertyExpectedType, @@ -492,12 +500,10 @@ class DelegatedPropertyResolver( traceToResolveDelegatedProperty.record(CONSTRAINT_SYSTEM_COMPLETER, it, completer) } - val delegatedPropertyTypeFromNI = - resolveWithNewInference(delegateExpression, variableDescriptor, scopeForDelegate, trace, dataFlowInfo, inferenceSession) val delegateType = expressionTypingServices.safeGetType( scopeForDelegate, delegateExpression, - delegatedPropertyTypeFromNI ?: NO_EXPECTED_TYPE, + NO_EXPECTED_TYPE, dataFlowInfo, inferenceSession, traceToResolveDelegatedProperty @@ -548,9 +554,9 @@ class DelegatedPropertyResolver( delegateType = provideDelegateDescriptor.returnType ?: return null delegateDataFlow = provideDelegateResults.resultingCall.dataFlowInfoForArguments.resultInfo } + trace.record(PROVIDE_DELEGATE_RESOLVED_CALL, variableDescriptor, provideDelegateResults.resultingCall) } } - return inferDelegateTypeFromGetSetValueMethods( delegateExpression, variableDescriptor, scopeForDelegate, traceToResolveDelegatedProperty, delegateType, delegateDataFlow ) @@ -560,7 +566,7 @@ class DelegatedPropertyResolver( delegateExpression: KtExpression, variableDescriptor: VariableDescriptorWithAccessors, scopeForDelegate: LexicalScope, - trace: BindingTrace, + trace: TemporaryBindingTrace, delegateType: KotlinType, delegateDataFlow: DataFlowInfo ): UnwrappedType { @@ -576,6 +582,24 @@ class DelegatedPropertyResolver( variableDescriptor, scopeForDelegate, delegateDataFlow, trace, inferenceSession ) + fun recordResolvedDelegateOrReportError( + result: OverloadResolutionResults, + isGet: Boolean + ) { + val accessor = when (isGet) { + true -> variableDescriptor.getter + false -> variableDescriptor.setter + } + requireNotNull(accessor) { + "Delegated property should have getter/setter $variableDescriptor ${delegateExpression.text}" + } + if (result.isSuccess) { + recordDelegateOperatorResults(result, variableDescriptor, accessor, trace) + } else { + reportGetSetValueResolutionError(result, accessor, delegateExpression, delegateType, trace, isGet) + } + } + getGetSetValueMethod( variableDescriptor, delegateExpression, delegateType, trace, scopeForDelegate, delegateDataFlow, @@ -591,11 +615,19 @@ class DelegatedPropertyResolver( } val resolutionCallbacks = psiCallResolver.createResolutionCallbacks(trace, inferenceSession, context = null) - inferenceSession.resolveCandidates(resolutionCallbacks) + val resolutionResults = inferenceSession.resolveCandidates(resolutionCallbacks) + + for ((name, isGet) in listOf(OperatorNameConventions.GET_VALUE to true, OperatorNameConventions.SET_VALUE to false)) { + val result = resolutionResults.firstOrNull { + it.resolutionResult.resultCallAtom()?.atom?.name == name + } + result?.let { recordResolvedDelegateOrReportError(it.overloadResolutionResults, isGet) } + } val resolvedDelegateType = extractResolvedDelegateType(delegateExpression, trace) - - return TypeSubstitutor.create(AnonymousTypeSubstitutor).safeSubstitute(resolvedDelegateType, Variance.INVARIANT).unwrap() + trace.recordType(delegateExpression, resolvedDelegateType) + trace.commit() + return resolvedDelegateType.unwrap() } private fun extractResolvedDelegateType(delegateExpression: KtExpression, trace: BindingTrace): KotlinType { @@ -724,13 +756,3 @@ class DelegatedPropertyResolver( } } -private object AnonymousTypeSubstitutor : TypeConstructorSubstitution() { - override fun get(key: TypeConstructor): TypeProjection? { - val declarationDescriptor = key.declarationDescriptor - if (declarationDescriptor is ClassifierDescriptor && DescriptorUtils.isAnonymousObject(declarationDescriptor)) { - return key.supertypes.firstOrNull()?.let(::TypeProjectionImpl) - } - - return null - } -} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt index 2bc6f202af5..dcaa9fe8275 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ManyCandidatesResolver.kt @@ -66,36 +66,62 @@ abstract class ManyCandidatesResolver( fun resolveCandidates(resolutionCallbacks: KotlinResolutionCallbacks): List> { val resolvedCallsInfo = partiallyResolvedCallsInfo.toList() - val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns).apply { - addOtherSystem(currentConstraintSystem()) - } - - prepareForCompletion(commonSystem, resolvedCallsInfo) - val diagnosticHolder = KotlinDiagnosticsHolder.SimpleHolder() - kotlinConstraintSystemCompleter.runCompletion( - commonSystem.asConstraintSystemCompleterContext(), - KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.FULL, - resolvedCallsInfo.map { it.callResolutionResult }, - builtIns.unitType - ) { - postponedArgumentsAnalyzer.analyze( - commonSystem.asPostponedArgumentsAnalyzerContext(), resolutionCallbacks, it, diagnosticHolder - ) + val hasOneSuccessfulAndOneErrorCandidate = if (resolvedCallsInfo.size > 1) { + val hasErrors = resolvedCallsInfo.map { + it.callResolutionResult.constraintSystem.errors.isNotEmpty() || it.callResolutionResult.diagnostics.isNotEmpty() + } + hasErrors.any { it } && !hasErrors.all { it } + } else { + false + } + + fun runCompletion(constraintSystem: NewConstraintSystem, atoms: List) { + kotlinConstraintSystemCompleter.runCompletion( + constraintSystem.asConstraintSystemCompleterContext(), + KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.FULL, + atoms, + builtIns.unitType + ) { + postponedArgumentsAnalyzer.analyze( + constraintSystem.asPostponedArgumentsAnalyzerContext(), resolutionCallbacks, it, diagnosticHolder + ) + } + } val allCandidates = arrayListOf>() - resolvedCallsInfo.mapTo(allCandidates) { - val resolutionResult = it.asCallResolutionResult(diagnosticHolder, commonSystem) - ResolutionResultCallInfo( - resolutionResult, psiCallResolver.convertToOverloadResolutionResults(it.context, resolutionResult, it.tracingStrategy) - ) + if (hasOneSuccessfulAndOneErrorCandidate) { + for (callInfo in resolvedCallsInfo) { + val system = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns).apply { + addOtherSystem(callInfo.callResolutionResult.constraintSystem) + } + runCompletion(system, listOf(callInfo.callResolutionResult)) + val resolutionResult = callInfo.asCallResolutionResult(diagnosticHolder, system) + allCandidates += ResolutionResultCallInfo( + resolutionResult, + psiCallResolver.convertToOverloadResolutionResults(callInfo.context, resolutionResult, callInfo.tracingStrategy) + ) + } + } else { + val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns).apply { + addOtherSystem(currentConstraintSystem()) + } + + prepareForCompletion(commonSystem, resolvedCallsInfo) + runCompletion(commonSystem, resolvedCallsInfo.map { it.callResolutionResult }) + resolvedCallsInfo.mapTo(allCandidates) { + val resolutionResult = it.asCallResolutionResult(diagnosticHolder, commonSystem) + ResolutionResultCallInfo( + resolutionResult, psiCallResolver.convertToOverloadResolutionResults(it.context, resolutionResult, it.tracingStrategy) + ) + } } - errorCallsInfo.mapTo(allCandidates) { ResolutionResultCallInfo(it.callResolutionResult, it.result) } - + val results = allCandidates.map { it.resolutionResult } + errorCallsInfo.filter { it.callResolutionResult !in results }.mapTo(allCandidates) { ResolutionResultCallInfo(it.callResolutionResult, it.result) } return allCandidates } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.ni.txt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.ni.txt index 3a7cf50c0e1..cada8d78115 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.ni.txt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/fieldAsClassDelegate.ni.txt @@ -21,7 +21,7 @@ public object DefaultHttpClient : HttpClient { public object DefaultHttpClientWithBy : HttpClient { private constructor DefaultHttpClientWithBy() - public final val client: [ERROR : ] + public final val client: [ERROR : Type from delegate] public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt index 23ee4fd91c4..04ce94737f8 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.fir.kt @@ -1,5 +1,6 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE // !LANGUAGE: -ProhibitTypeParametersForLocalVariables +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.kt index 8271d9891b3..b151998c589 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_3.kt @@ -1,5 +1,6 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE // !LANGUAGE: -ProhibitTypeParametersForLocalVariables +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty @@ -10,7 +11,7 @@ fun test() { const val a3 = 0 lateinit val a4 = 0 val a5 by Delegate() - val a6 by Delegate<T>() + val a6 by Delegate<T>() } class Delegate { diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt index 7aa9f13ca44..43a52b7b1b5 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.fir.kt @@ -1,5 +1,6 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE // !LANGUAGE: +ProhibitTypeParametersForLocalVariables +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.kt b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.kt index 80ecdeade12..2efda07b425 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/localVariablesWithTypeParameters_1_4.kt @@ -1,5 +1,6 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE // !LANGUAGE: +ProhibitTypeParametersForLocalVariables +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty @@ -10,7 +11,7 @@ fun test() { const val a3 = 0 lateinit val a4 = 0 val a5 by Delegate() - val a6 by Delegate<T>() + val a6 by Delegate<T>() } class Delegate { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt index f41be83d563..5927f432a0c 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt @@ -10,8 +10,8 @@ class A(outer: Outer) { var g: String by outer.getContainer().getMyProperty() - var b: String by foo(getMyProperty()) - var r: String by foo(outer.getContainer().getMyProperty()) + var b: String by foo(getMyProperty()) + var r: String by foo(outer.getContainer().getMyProperty()) var e: String by + foo(getMyProperty()) var f: String by foo(getMyProperty()) - 1 } diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.kt index dda04dffa4d..352b8c0ae37 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/extensionProperty.kt @@ -4,10 +4,10 @@ package foo import kotlin.reflect.KProperty open class A { - val B.w: Int by MyProperty() + val B.w: Int by MyProperty() } -val B.r: Int by MyProperty() +val B.r: Int by MyProperty() val A.e: Int by MyProperty() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt index e872b5a72d8..aac12d41280 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt @@ -8,7 +8,7 @@ class A() { operator fun setValue(t: Any?, p: KProperty<*>, x: T) = Unit } -var a1: Int by A() +var a1: Int by A() var a2: Int by A() class B() { @@ -25,4 +25,4 @@ class C() { } var c1: Int by C() -var c2: Int by C() +var c2: Int by C() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.kt index c49975f293f..5227d682af4 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noErrorsForImplicitConstraints.kt @@ -4,8 +4,8 @@ package foo import kotlin.reflect.KProperty class A { - var a5: String by MyProperty1() - var b5: String by getMyProperty1() + var a5: String by MyProperty1() + var b5: String by getMyProperty1() } fun getMyProperty1() = MyProperty1() @@ -24,8 +24,8 @@ class MyProperty1 { // ----------------- class B { - var a5: String by MyProperty2() - var b5: String by getMyProperty2() + var a5: String by MyProperty2() + var b5: String by getMyProperty2() } fun getMyProperty2() = MyProperty2() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt index 488055ba112..7e0fb50564f 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt @@ -3,7 +3,7 @@ import kotlin.reflect.KProperty class A { - var a by MyProperty() + var a by MyProperty() } class MyProperty { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.ni.txt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.ni.txt index fe4e1259365..d84065a23cc 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.ni.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.ni.txt @@ -2,7 +2,7 @@ package public final class A { public constructor A() - public final var a: [ERROR : ] + public final var a: [ERROR : Type from delegate] public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt index 2ff3633fde0..ebe6e435f98 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.fir.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE // NI_EXPECTED_FILE import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.kt index cd444a26355..7a2be4ecb26 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.kt @@ -1,10 +1,11 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE // NI_EXPECTED_FILE import kotlin.reflect.KProperty class B { - val c by Delegate(ag) + val c by Delegate(ag) } class Delegate(val init: T) { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.ni.txt b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.ni.txt index 02fcb832d25..aba62fe86a0 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.ni.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/propertyDefferedType.ni.txt @@ -2,7 +2,7 @@ package public final class B { public constructor B() - public final val c: [ERROR : ] + public final val c: [ERROR : Type from delegate] public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt index 6cc2b6c2221..cd106361977 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt @@ -13,6 +13,6 @@ fun String.provideDelegate(a: Any?, p: KProperty<*>) = StringDelegate(this) operator fun String.getValue(a: Any?, p: KProperty<*>) = this val test1: String by "OK" -val test2: Int by "OK" +val test2: Int by "OK" val test3 by "OK" diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt index 17274dcb27d..6b90d11d8f5 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/setValue.kt @@ -11,7 +11,7 @@ operator fun String.provideDelegate(receiver: Any?, p: Any) = Delegate() var test1: String by Delegate() var test2: String by Delegate() -var test3: String by "OK" +var test3: String by "OK" var test4: String by "OK".provideDelegate(null, "") var test5: String by "OK".provideDelegate(null, "") \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.kt index ce168f0cb2a..1e2af347ffe 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/unsupportedOperatorProvideDelegate.kt @@ -11,5 +11,5 @@ class WrongDelegate(val x: Int) { operator fun String.getValue(thisRef: Any?, prop: Any) = this val test1: String by "OK" -val test2: Int by "OK" +val test2: Int by "OK" val test3 by "OK" \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt index 8d64edc5bf6..476124fd689 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.kt @@ -6,7 +6,7 @@ import kotlin.reflect.KProperty val a by a -val b by Delegate(b) +val b by Delegate(b) val c by d val d by c diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.ni.txt b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.ni.txt index a1da67a0de6..763ab410665 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.ni.txt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/recursiveType.ni.txt @@ -2,7 +2,7 @@ package public val a: [ERROR : ] public val b: kotlin.Int -public val c: [ERROR : ] +public val c: [ERROR : Type from delegate] public val d: [ERROR : ] public final class Delegate { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt index 8a56c046275..271810a415a 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.fir.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt index e5ac5d81f00..f529f06cc34 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/setterThisTypeMismatch.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt index 884b0ccfedb..d86d06065ff 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.kt @@ -3,7 +3,7 @@ import kotlin.reflect.KProperty -val c: Int by Delegate() +val c: Int by Delegate() class Delegate { operator fun getValue(t: Any?, p: KProperty<*>): String { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt index c7001296a54..a54bd1c8435 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.fir.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt index c91bcf038b8..20fd5336abe 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForSetParameter.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE import kotlin.reflect.KProperty diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.fir.kt new file mode 100644 index 00000000000..8e0e04562b9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-31219 + +import kotlin.reflect.KProperty + +interface Intf + +interface GenericIntf + +class Foo { + private val generic1 by lazy { + abstract class LocalIntf : GenericIntf + object : LocalIntf() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.kt new file mode 100644 index 00000000000..8e0e04562b9 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-31219 + +import kotlin.reflect.KProperty + +interface Intf + +interface GenericIntf + +class Foo { + private val generic1 by lazy { + abstract class LocalIntf : GenericIntf + object : LocalIntf() {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.txt new file mode 100644 index 00000000000..73e5d8d3e60 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.txt @@ -0,0 +1,21 @@ +package + +public final class Foo { + public constructor Foo() + private final val generic1: Foo.generic1.. + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface GenericIntf { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Intf { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.fir.kt new file mode 100644 index 00000000000..9770f4460a4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-31679 + +import kotlin.reflect.KProperty + +class MyDelegate(p: () -> T) { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO() +} + +private val privateObj by MyDelegate { + object { + val x = 42 + } +} + +fun test() { + privateObj.x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.kt new file mode 100644 index 00000000000..5714e3a6e27 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-31679 + +import kotlin.reflect.KProperty + +class MyDelegate(p: () -> T) { + operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO() +} + +private val privateObj by MyDelegate { + object { + val x = 42 + } +} + +fun test() { + privateObj.x +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.txt new file mode 100644 index 00000000000..5e509096cd6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.txt @@ -0,0 +1,12 @@ +package + +private val privateObj: privateObj.. +public fun test(): kotlin.Unit + +public final class MyDelegate { + public constructor MyDelegate(/*0*/ p: () -> T) + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final operator fun getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.fir.kt new file mode 100644 index 00000000000..8d1b2c34377 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-32249 + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class Wrapper(val name: String, val defaultValue: T) + +private fun wrapper(defaultValue: T) = object : ReadOnlyProperty> { + override fun getValue(thisRef: Any, property: KProperty<*>): Wrapper = null!! +} + +object Foo { + val x by wrapper(true) + val y: Wrapper by wrapper(true) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.kt new file mode 100644 index 00000000000..8d1b2c34377 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +NewInference +// !WITH_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER +// ISSUE: KT-32249 + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class Wrapper(val name: String, val defaultValue: T) + +private fun wrapper(defaultValue: T) = object : ReadOnlyProperty> { + override fun getValue(thisRef: Any, property: KProperty<*>): Wrapper = null!! +} + +object Foo { + val x by wrapper(true) + val y: Wrapper by wrapper(true) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.txt new file mode 100644 index 00000000000..82abd5dcc8e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.txt @@ -0,0 +1,21 @@ +package + +private fun wrapper(/*0*/ defaultValue: T): wrapper. + +public object Foo { + private constructor Foo() + public final val x: Wrapper + public final val y: Wrapper + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Wrapper { + public constructor Wrapper(/*0*/ name: kotlin.String, /*1*/ defaultValue: T) + public final val defaultValue: T + public final val name: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index ab65326aacd..fead4e339d4 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -2908,6 +2908,34 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/delegates") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Delegates extends AbstractDiagnosticsTestWithStdLib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInDelegates() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/delegates"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt31219.kt") + public void testKt31219() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.kt"); + } + + @TestMetadata("kt31679.kt") + public void testKt31679() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.kt"); + } + + @TestMetadata("kt32249.kt") + public void testKt32249() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inline") diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index b9ab7cab1f3..dcd092de4dc 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -2908,6 +2908,34 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/resolveWithOnlyInputTypesAnnotation.kt"); } } + + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/delegates") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Delegates extends AbstractDiagnosticsTestWithStdLibUsingJavac { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInDelegates() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/delegates"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt31219.kt") + public void testKt31219() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31219.kt"); + } + + @TestMetadata("kt31679.kt") + public void testKt31679() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt31679.kt"); + } + + @TestMetadata("kt32249.kt") + public void testKt32249() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/delegates/kt32249.kt"); + } + } } @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inline")