[NI] Don't resolve delegates twice

#KT-31219 Fixed
#KT-31679 Fixed
#KT-32249 Fixed
This commit is contained in:
Dmitriy Novozhilov
2019-12-23 12:49:46 +03:00
parent 0c01499d98
commit e83941a98e
38 changed files with 378 additions and 72 deletions
@@ -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")
@@ -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<FunctionDescriptor>,
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
}
}
@@ -66,36 +66,62 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
fun resolveCandidates(resolutionCallbacks: KotlinResolutionCallbacks): List<ResolutionResultCallInfo<D>> {
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<ResolvedAtom>) {
kotlinConstraintSystemCompleter.runCompletion(
constraintSystem.asConstraintSystemCompleterContext(),
KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.FULL,
atoms,
builtIns.unitType
) {
postponedArgumentsAnalyzer.analyze(
constraintSystem.asPostponedArgumentsAnalyzerContext(), resolutionCallbacks, it, diagnosticHolder
)
}
}
val allCandidates = arrayListOf<ResolutionResultCallInfo<D>>()
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
}
@@ -21,7 +21,7 @@ public object DefaultHttpClient : HttpClient {
public object DefaultHttpClientWithBy : HttpClient {
private constructor DefaultHttpClientWithBy()
public final val client: [ERROR : <ERROR FUNCTION RETURN TYPE>]
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
@@ -1,5 +1,6 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !LANGUAGE: -ProhibitTypeParametersForLocalVariables
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -1,5 +1,6 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !LANGUAGE: -ProhibitTypeParametersForLocalVariables
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -10,7 +11,7 @@ fun test() {
<!WRONG_MODIFIER_TARGET!>const<!> val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS_WARNING!><T><!> a3 = 0
<!INAPPLICABLE_LATEINIT_MODIFIER, INAPPLICABLE_LATEINIT_MODIFIER, INAPPLICABLE_LATEINIT_MODIFIER!>lateinit<!> val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS_WARNING!><T><!> a4 = 0
val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS_WARNING!><T><!> a5 by Delegate<Int>()
val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS_WARNING!><T><!> a6 by Delegate<<!UNRESOLVED_REFERENCE!>T<!>>()
val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS_WARNING!><T><!> a6 by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate<<!UNRESOLVED_REFERENCE!>T<!>>()<!>
}
class Delegate<F> {
@@ -1,5 +1,6 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !LANGUAGE: +ProhibitTypeParametersForLocalVariables
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -1,5 +1,6 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// !LANGUAGE: +ProhibitTypeParametersForLocalVariables
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -10,7 +11,7 @@ fun test() {
<!WRONG_MODIFIER_TARGET!>const<!> val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS!><T><!> a3 = 0
<!INAPPLICABLE_LATEINIT_MODIFIER, INAPPLICABLE_LATEINIT_MODIFIER, INAPPLICABLE_LATEINIT_MODIFIER!>lateinit<!> val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS!><T><!> a4 = 0
val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS!><T><!> a5 by Delegate<Int>()
val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS!><T><!> a6 by Delegate<<!UNRESOLVED_REFERENCE!>T<!>>()
val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS!><T><!> a6 by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate<<!UNRESOLVED_REFERENCE!>T<!>>()<!>
}
class Delegate<F> {
@@ -10,8 +10,8 @@ class A(outer: Outer) {
var g: String by outer.getContainer().getMyProperty()
var b: String by foo(<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())
var r: String by foo(outer.getContainer().<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())
var b: String by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>foo(<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())<!>
var r: String by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>foo(outer.getContainer().<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())<!>
var e: String by <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>+<!> <!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>())
var f: String by <!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>()) <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>-<!> 1
}
@@ -4,10 +4,10 @@ package foo
import kotlin.reflect.KProperty
open class A {
val B.w: Int by <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!><!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()<!>
val B.w: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()<!>
}
val B.r: Int by <!NI;TYPE_MISMATCH, NI;TYPE_MISMATCH!><!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()<!>
val B.r: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!OI;TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()<!>
val A.e: Int by MyProperty()
@@ -8,7 +8,7 @@ class A<R>() {
operator fun <T> setValue(t: Any?, p: KProperty<*>, x: T) = Unit
}
var a1: Int by <!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A<!>()
var a1: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A<!>()<!>
var a2: Int by A<String>()
class B<R>() {
@@ -25,4 +25,4 @@ class C<R>() {
}
var c1: Int by C()
var c2: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>C<Number>()<!>
var c2: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, OI;DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>C<Number>()<!>
@@ -4,8 +4,8 @@ package foo
import kotlin.reflect.KProperty
class A {
var a5: String by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty1<!>()<!>
var b5: String by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty1<!>()<!>
var a5: String by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty1<!>()<!>
var b5: String by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty1<!>()<!>
}
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
@@ -24,8 +24,8 @@ class MyProperty1<T, R> {
// -----------------
class B {
var a5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>MyProperty2()<!>
var b5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>getMyProperty2()<!>
var a5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty2<!>()<!>
var b5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty2<!>()<!>
}
fun <A, B> getMyProperty2() = MyProperty2<A, B>()
@@ -3,7 +3,7 @@
import kotlin.reflect.KProperty
class A {
var a by <!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty<!>()
var a by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!><!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty<!>()<!>
}
class MyProperty<T, R> {
@@ -2,7 +2,7 @@ package
public final class A {
public constructor A()
public final var a: [ERROR : <ERROR FUNCTION RETURN TYPE>]
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
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
import kotlin.reflect.KProperty
@@ -1,10 +1,11 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
import kotlin.reflect.KProperty
class B {
val c by Delegate(<!UNRESOLVED_REFERENCE!>ag<!>)
val c by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>Delegate(<!UNRESOLVED_REFERENCE!>ag<!>)<!>
}
class Delegate<T: Any>(val init: T) {
@@ -2,7 +2,7 @@ package
public final class B {
public constructor B()
public final val c: [ERROR : <ERROR FUNCTION RETURN TYPE>]
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
@@ -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 <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>"OK"<!>
val test2: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, OI;DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>"OK"<!>
val test3 by "OK"
@@ -11,7 +11,7 @@ operator fun <T> String.provideDelegate(receiver: Any?, p: Any) = Delegate<T>()
var test1: String by <!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Delegate<!>()
var test2: String by Delegate<String>()
var test3: String by <!DELEGATE_SPECIAL_FUNCTION_MISSING, DELEGATE_SPECIAL_FUNCTION_MISSING, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>"OK"<!>
var test3: String by <!OI;DELEGATE_SPECIAL_FUNCTION_MISSING, OI;DELEGATE_SPECIAL_FUNCTION_MISSING, OI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>"OK"<!>
var test4: String by "OK".<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>provideDelegate<!>(null, "")
var test5: String by "OK".provideDelegate<String>(null, "")
@@ -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 <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>"OK"<!>
val test2: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, OI;DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>"OK"<!>
val test3 by "OK"
@@ -6,7 +6,7 @@ import kotlin.reflect.KProperty
val a by <!NI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, OI;TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>a<!>
val b by Delegate(<!OI;TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>b<!>)
val b by Delegate(<!NI;DEBUG_INFO_MISSING_UNRESOLVED, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>b<!>)
val c by <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, UNINITIALIZED_VARIABLE!>d<!>
val d by <!NI;DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE, OI;TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>c<!>
@@ -2,7 +2,7 @@ package
public val a: [ERROR : <ERROR FUNCTION RETURN TYPE>]
public val b: kotlin.Int
public val c: [ERROR : <ERROR FUNCTION RETURN TYPE>]
public val c: [ERROR : Type from delegate]
public val d: [ERROR : <ERROR FUNCTION RETURN TYPE>]
public final class Delegate {
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -3,7 +3,7 @@
import kotlin.reflect.KProperty
val c: Int by <!DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>Delegate()<!>
val c: Int by <!NI;DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, OI;DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH!>Delegate()<!>
class Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): String {
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.reflect.KProperty
@@ -0,0 +1,17 @@
// !LANGUAGE: +NewInference
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-31219
import kotlin.reflect.KProperty
interface Intf
interface GenericIntf<T>
class Foo {
private val generic1 by lazy {
abstract class LocalIntf : GenericIntf<CharSequence>
object : LocalIntf() {}
}
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +NewInference
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-31219
import kotlin.reflect.KProperty
interface Intf
interface GenericIntf<T>
class Foo {
private val generic1 by lazy {
abstract class LocalIntf : GenericIntf<CharSequence>
object : LocalIntf() {}
}
}
@@ -0,0 +1,21 @@
package
public final class Foo {
public constructor Foo()
private final val generic1: Foo.generic1.<anonymous>.<no name provided>
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</*0*/ T> {
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
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-31679
import kotlin.reflect.KProperty
class MyDelegate<T>(p: () -> T) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO()
}
private val privateObj by MyDelegate {
object {
val x = 42
}
}
fun test() {
privateObj.<!UNRESOLVED_REFERENCE!>x<!>
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +NewInference
// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-31679
import kotlin.reflect.KProperty
class MyDelegate<T>(p: () -> T) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = TODO()
}
private val privateObj by MyDelegate {
object {
val x = 42
}
}
fun test() {
privateObj.x
}
@@ -0,0 +1,12 @@
package
private val privateObj: privateObj.<anonymous>.<no name provided>
public fun test(): kotlin.Unit
public final class MyDelegate</*0*/ T> {
public constructor MyDelegate</*0*/ T>(/*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
}
@@ -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<T>(val name: String, val defaultValue: T)
private fun <T> wrapper(defaultValue: T) = object : ReadOnlyProperty<Any, Wrapper<T>> {
override fun getValue(thisRef: Any, property: KProperty<*>): Wrapper<T> = null!!
}
object Foo {
val x by wrapper(true)
val y: Wrapper<Boolean> by wrapper(true)
}
@@ -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<T>(val name: String, val defaultValue: T)
private fun <T> wrapper(defaultValue: T) = object : ReadOnlyProperty<Any, Wrapper<T>> {
override fun getValue(thisRef: Any, property: KProperty<*>): Wrapper<T> = null!!
}
object Foo {
val x by wrapper(true)
val y: Wrapper<Boolean> by wrapper(true)
}
@@ -0,0 +1,21 @@
package
private fun </*0*/ T> wrapper(/*0*/ defaultValue: T): wrapper.<no name provided><T>
public object Foo {
private constructor Foo()
public final val x: Wrapper<kotlin.Boolean>
public final val y: Wrapper<kotlin.Boolean>
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</*0*/ T> {
public constructor Wrapper</*0*/ T>(/*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
}
@@ -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")
@@ -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")