K2: fix handling of synthetic calls in delegate inference
This commit is intended to avoid the second resolve of delegate when we need to consider provideDelegate() possibility in inference. Also here we provide correct completion of synthetic calls during delegate inference. #KT-58013 Fixed
This commit is contained in:
committed by
Space Team
parent
8c8ca7bb70
commit
3964ee38be
+36
@@ -8889,6 +8889,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elvisInDelegated.kt")
|
||||
public void testElvisInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/elvisInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionGet.kt")
|
||||
public void testExtensionGet() throws Exception {
|
||||
@@ -8913,6 +8919,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ifInDelegated.kt")
|
||||
public void testIfInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/ifInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt41952.kt")
|
||||
public void testKt41952() throws Exception {
|
||||
@@ -8955,12 +8967,24 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultTypeOfLambdaForConventionMethods.kt")
|
||||
public void testResultTypeOfLambdaForConventionMethods() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryInGenerated.kt")
|
||||
public void testTryInGenerated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/tryInGenerated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeOfLazyDelegatedPropertyWithObject.kt")
|
||||
public void testTypeOfLazyDelegatedPropertyWithObject() throws Exception {
|
||||
@@ -9055,6 +9079,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onObject.kt")
|
||||
public void testOnObject() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/onObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadResolutionForSeveralProvideDelegates.kt")
|
||||
public void testOverloadResolutionForSeveralProvideDelegates() throws Exception {
|
||||
|
||||
+36
@@ -8889,6 +8889,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elvisInDelegated.kt")
|
||||
public void testElvisInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/elvisInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionGet.kt")
|
||||
public void testExtensionGet() throws Exception {
|
||||
@@ -8913,6 +8919,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ifInDelegated.kt")
|
||||
public void testIfInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/ifInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt41952.kt")
|
||||
public void testKt41952() throws Exception {
|
||||
@@ -8955,12 +8967,24 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultTypeOfLambdaForConventionMethods.kt")
|
||||
public void testResultTypeOfLambdaForConventionMethods() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryInGenerated.kt")
|
||||
public void testTryInGenerated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/tryInGenerated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeOfLazyDelegatedPropertyWithObject.kt")
|
||||
public void testTypeOfLazyDelegatedPropertyWithObject() throws Exception {
|
||||
@@ -9055,6 +9079,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onObject.kt")
|
||||
public void testOnObject() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/onObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadResolutionForSeveralProvideDelegates.kt")
|
||||
public void testOverloadResolutionForSeveralProvideDelegates() throws Exception {
|
||||
|
||||
+36
@@ -8889,6 +8889,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elvisInDelegated.kt")
|
||||
public void testElvisInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/elvisInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionGet.kt")
|
||||
public void testExtensionGet() throws Exception {
|
||||
@@ -8913,6 +8919,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ifInDelegated.kt")
|
||||
public void testIfInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/ifInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt41952.kt")
|
||||
public void testKt41952() throws Exception {
|
||||
@@ -8955,12 +8967,24 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultTypeOfLambdaForConventionMethods.kt")
|
||||
public void testResultTypeOfLambdaForConventionMethods() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryInGenerated.kt")
|
||||
public void testTryInGenerated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/tryInGenerated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeOfLazyDelegatedPropertyWithObject.kt")
|
||||
public void testTypeOfLazyDelegatedPropertyWithObject() throws Exception {
|
||||
@@ -9055,6 +9079,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onObject.kt")
|
||||
public void testOnObject() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/onObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadResolutionForSeveralProvideDelegates.kt")
|
||||
public void testOverloadResolutionForSeveralProvideDelegates() throws Exception {
|
||||
|
||||
+36
@@ -8895,6 +8895,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elvisInDelegated.kt")
|
||||
public void testElvisInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/elvisInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionGet.kt")
|
||||
public void testExtensionGet() throws Exception {
|
||||
@@ -8919,6 +8925,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ifInDelegated.kt")
|
||||
public void testIfInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/ifInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt41952.kt")
|
||||
public void testKt41952() throws Exception {
|
||||
@@ -8961,12 +8973,24 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultTypeOfLambdaForConventionMethods.kt")
|
||||
public void testResultTypeOfLambdaForConventionMethods() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryInGenerated.kt")
|
||||
public void testTryInGenerated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/tryInGenerated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeOfLazyDelegatedPropertyWithObject.kt")
|
||||
public void testTypeOfLazyDelegatedPropertyWithObject() throws Exception {
|
||||
@@ -9061,6 +9085,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onObject.kt")
|
||||
public void testOnObject() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/onObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadResolutionForSeveralProvideDelegates.kt")
|
||||
public void testOverloadResolutionForSeveralProvideDelegates() throws Exception {
|
||||
|
||||
+5
-2
@@ -324,7 +324,7 @@ open class FirDeclarationsResolveTransformer(
|
||||
.transformSingle(components.integerLiteralAndOperatorApproximationTransformer, null)
|
||||
|
||||
// Second, replace result type of delegate expression with stub type if delegate not yet resolved
|
||||
if (delegateExpression is FirQualifiedAccessExpression) {
|
||||
if (delegateExpression is FirResolvable) {
|
||||
val calleeReference = delegateExpression.calleeReference
|
||||
if (calleeReference is FirNamedReferenceWithCandidate) {
|
||||
val system = calleeReference.candidate.system
|
||||
@@ -343,11 +343,14 @@ open class FirDeclarationsResolveTransformer(
|
||||
}
|
||||
|
||||
val provideDelegateCall = wrappedDelegateExpression.delegateProvider as FirFunctionCall
|
||||
provideDelegateCall.replaceExplicitReceiver(delegateExpression)
|
||||
|
||||
// Resolve call for provideDelegate, without completion
|
||||
// TODO: this generates some nodes in the control flow graph which we don't want if we
|
||||
// end up not selecting this option.
|
||||
provideDelegateCall.transformSingle(this, ResolutionMode.ContextIndependent)
|
||||
transformer.expressionsTransformer.transformFunctionCallInternal(
|
||||
provideDelegateCall, ResolutionMode.ContextIndependent, provideDelegate = true
|
||||
)
|
||||
|
||||
// If we got successful candidate for provideDelegate, let's select it
|
||||
val provideDelegateCandidate = provideDelegateCall.candidate()
|
||||
|
||||
+15
-1
@@ -391,6 +391,13 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
}
|
||||
|
||||
override fun transformFunctionCall(functionCall: FirFunctionCall, data: ResolutionMode): FirStatement =
|
||||
transformFunctionCallInternal(functionCall, data, provideDelegate = false)
|
||||
|
||||
internal fun transformFunctionCallInternal(
|
||||
functionCall: FirFunctionCall,
|
||||
data: ResolutionMode,
|
||||
provideDelegate: Boolean,
|
||||
): FirStatement =
|
||||
whileAnalysing(session, functionCall) {
|
||||
val calleeReference = functionCall.calleeReference
|
||||
if (
|
||||
@@ -416,7 +423,14 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
val initialExplicitReceiver = functionCall.explicitReceiver
|
||||
val withTransformedArguments = if (!resolvingAugmentedAssignment) {
|
||||
dataFlowAnalyzer.enterCallArguments(functionCall, functionCall.arguments)
|
||||
transformExplicitReceiver(functionCall).also {
|
||||
// In provideDelegate mode the explicitReceiver is already resolved
|
||||
// E.g. we have val some by someDelegate
|
||||
// At 1st stage of delegate inference we resolve someDelegate itself,
|
||||
// at 2nd stage in provideDelegate mode we are trying to resolve someDelegate.provideDelegate(),
|
||||
// and 'someDelegate' explicit receiver is resolved at 1st stage
|
||||
// See also FirDeclarationsResolveTransformer.transformWrappedDelegateExpression
|
||||
val withResolvedExplicitReceiver = if (provideDelegate) functionCall else transformExplicitReceiver(functionCall)
|
||||
withResolvedExplicitReceiver.also {
|
||||
it.replaceArgumentList(it.argumentList.transform(this, ResolutionMode.ContextDependent))
|
||||
dataFlowAnalyzer.exitCallArguments()
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
FILE: elvisInDelegated.kt
|
||||
public final data class Ref<D> : R|kotlin/Any| {
|
||||
public constructor<D>(t: R|D|): R|Ref<D>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val t: R|D| = R|<local>/t|
|
||||
public get(): R|D|
|
||||
|
||||
public final operator fun component1(): R|D|
|
||||
|
||||
public final fun copy(t: R|D| = this@R|/Ref|.R|/Ref.t|): R|Ref<D>|
|
||||
|
||||
}
|
||||
public final operator fun <V> R|Ref<V>|.getValue(hisRef: R|kotlin/Any?|, property: R|kotlin/reflect/KProperty<*>|): R|V| {
|
||||
^getValue this@R|/getValue|.R|SubstitutionOverride</Ref.t: R|V|>|
|
||||
}
|
||||
public final fun <E> R|kotlin/collections/List<Ref<*>>|.getElement(i: R|kotlin/Int|): R|Ref<E>| {
|
||||
^getElement (this@R|/getElement|.R|SubstitutionOverride<kotlin/collections/List.get: R|Ref<*>|>|(R|<local>/i|) as R|Ref<E>|)
|
||||
}
|
||||
public final fun test(list: R|kotlin/collections/List<Ref<*>>|): R|kotlin/Unit| {
|
||||
lval data: R|kotlin/String|by R|<local>/list|.R|/getElement|<R|kotlin/String|>(Int(0)) ?: R|kotlin/error|(String())
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-58013 (related)
|
||||
// WITH_REFLECT
|
||||
// FIR_DUMP
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
data class Ref<D>(val t: D)
|
||||
|
||||
operator fun <V> Ref<V>.getValue(hisRef: Any?, property: KProperty<*>): V = this.t
|
||||
|
||||
fun <E> List<Ref<*>>.getElement(i: Int): Ref<E> = this[i] <!UNCHECKED_CAST!>as Ref<E><!>
|
||||
|
||||
fun test(list: List<Ref<*>>) {
|
||||
val data: String by list.getElement(0) <!USELESS_ELVIS!>?: error("")<!>
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
FILE: ifInDelegated.kt
|
||||
public final data class Ref<D> : R|kotlin/Any| {
|
||||
public constructor<D>(t: R|D|): R|Ref<D>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val t: R|D| = R|<local>/t|
|
||||
public get(): R|D|
|
||||
|
||||
public final operator fun component1(): R|D|
|
||||
|
||||
public final fun copy(t: R|D| = this@R|/Ref|.R|/Ref.t|): R|Ref<D>|
|
||||
|
||||
}
|
||||
public final operator fun <V> R|Ref<V>|.getValue(hisRef: R|kotlin/Any?|, property: R|kotlin/reflect/KProperty<*>|): R|V| {
|
||||
^getValue this@R|/getValue|.R|SubstitutionOverride</Ref.t: R|V|>|
|
||||
}
|
||||
public final fun <E> R|kotlin/collections/List<Ref<*>>|.getElement(i: R|kotlin/Int|): R|Ref<E>| {
|
||||
^getElement (this@R|/getElement|.R|SubstitutionOverride<kotlin/collections/List.get: R|Ref<*>|>|(R|<local>/i|) as R|Ref<E>|)
|
||||
}
|
||||
public final fun test(list: R|kotlin/collections/List<Ref<*>>|, arg: R|kotlin/Boolean|): R|kotlin/Unit| {
|
||||
lval data: R|kotlin/String|by when () {
|
||||
R|<local>/arg| -> {
|
||||
R|<local>/list|.R|/getElement|<R|kotlin/String|>(Int(0))
|
||||
}
|
||||
else -> {
|
||||
R|<local>/list|.R|/getElement|<R|kotlin/String|>(Int(1))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-58013 (related)
|
||||
// WITH_REFLECT
|
||||
// FIR_DUMP
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
data class Ref<D>(val t: D)
|
||||
|
||||
operator fun <V> Ref<V>.getValue(hisRef: Any?, property: KProperty<*>): V = this.t
|
||||
|
||||
fun <E> List<Ref<*>>.getElement(i: Int): Ref<E> = this[i] <!UNCHECKED_CAST!>as Ref<E><!>
|
||||
|
||||
fun test(list: List<Ref<*>>, arg: Boolean) {
|
||||
val data: String by if (arg) list.getElement(0) else list.getElement(1)
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
FILE: notNullAssertionInLocalDelegated.kt
|
||||
public final data class Ref<D> : R|kotlin/Any| {
|
||||
public constructor<D>(t: R|D|): R|Ref<D>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val t: R|D| = R|<local>/t|
|
||||
public get(): R|D|
|
||||
|
||||
public final operator fun component1(): R|D|
|
||||
|
||||
public final fun copy(t: R|D| = this@R|/Ref|.R|/Ref.t|): R|Ref<D>|
|
||||
|
||||
}
|
||||
public final operator fun <V> R|Ref<V>|.getValue(hisRef: R|kotlin/Any?|, property: R|kotlin/reflect/KProperty<*>|): R|V| {
|
||||
^getValue this@R|/getValue|.R|SubstitutionOverride</Ref.t: R|V|>|
|
||||
}
|
||||
public final fun <E> R|kotlin/collections/List<Ref<*>>|.getElement(i: R|kotlin/Int|): R|Ref<E>| {
|
||||
^getElement (this@R|/getElement|.R|SubstitutionOverride<kotlin/collections/List.get: R|Ref<*>|>|(R|<local>/i|) as R|Ref<E>|)
|
||||
}
|
||||
public final fun test(list: R|kotlin/collections/List<Ref<*>>|): R|kotlin/Unit| {
|
||||
lval data: R|kotlin/String|by R|<local>/list|.R|/getElement|<R|kotlin/String|>(Int(0))!!
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-58013
|
||||
// WITH_REFLECT
|
||||
// FIR_DUMP
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
data class Ref<D>(val t: D)
|
||||
|
||||
operator fun <V> Ref<V>.getValue(hisRef: Any?, property: KProperty<*>): V = this.t
|
||||
|
||||
fun <E> List<Ref<*>>.getElement(i: Int): Ref<E> = this[i] <!UNCHECKED_CAST!>as Ref<E><!>
|
||||
|
||||
fun test(list: List<Ref<*>>) {
|
||||
val data: String by list.getElement(0)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
FILE: tryInGenerated.kt
|
||||
public final data class Ref<D> : R|kotlin/Any| {
|
||||
public constructor<D>(t: R|D|): R|Ref<D>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val t: R|D| = R|<local>/t|
|
||||
public get(): R|D|
|
||||
|
||||
public final operator fun component1(): R|D|
|
||||
|
||||
public final fun copy(t: R|D| = this@R|/Ref|.R|/Ref.t|): R|Ref<D>|
|
||||
|
||||
}
|
||||
public final operator fun <V> R|Ref<V>|.getValue(hisRef: R|kotlin/Any?|, property: R|kotlin/reflect/KProperty<*>|): R|V| {
|
||||
^getValue this@R|/getValue|.R|SubstitutionOverride</Ref.t: R|V|>|
|
||||
}
|
||||
public final fun <E> R|kotlin/collections/List<Ref<*>>|.getElement(i: R|kotlin/Int|): R|Ref<E>| {
|
||||
^getElement (this@R|/getElement|.R|SubstitutionOverride<kotlin/collections/List.get: R|Ref<*>|>|(R|<local>/i|) as R|Ref<E>|)
|
||||
}
|
||||
public final fun test(list: R|kotlin/collections/List<Ref<*>>|): R|kotlin/Unit| {
|
||||
lval data: R|kotlin/String|by try {
|
||||
R|<local>/list|.R|/getElement|<R|kotlin/String|>(Int(0))
|
||||
}
|
||||
finally {
|
||||
}
|
||||
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-58013 (related)
|
||||
// WITH_REFLECT
|
||||
// FIR_DUMP
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
data class Ref<D>(val t: D)
|
||||
|
||||
operator fun <V> Ref<V>.getValue(hisRef: Any?, property: KProperty<*>): V = this.t
|
||||
|
||||
fun <E> List<Ref<*>>.getElement(i: Int): Ref<E> = this[i] <!UNCHECKED_CAST!>as Ref<E><!>
|
||||
|
||||
fun test(list: List<Ref<*>>) {
|
||||
val data: String by try { list.getElement(0) } finally {}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// ISSUE: KT-58013
|
||||
// WITH_REFLECT
|
||||
// FIR_DUMP
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
data class Ref<D>(val t: D)
|
||||
|
||||
class GenericDelegate<G>(val value: G)
|
||||
|
||||
operator fun <V> Ref<V>.provideDelegate(a: Any?, p: KProperty<*>): GenericDelegate<V> = GenericDelegate(this.t)
|
||||
|
||||
operator fun <W> GenericDelegate<W>.getValue(a: Any?, p: KProperty<*>): W = this.value
|
||||
|
||||
fun <E> List<Ref<*>>.getElement(i: Int): Ref<E> = this[i] <!UNCHECKED_CAST!>as Ref<E><!>
|
||||
|
||||
fun test(list: List<Ref<*>>) {
|
||||
val data: String by list.getElement(0)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||
|
||||
val data2: String by list.getElement(0)
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
FILE: notNullAssertionInLocalDelegated.fir.kt
|
||||
public final data class Ref<D> : R|kotlin/Any| {
|
||||
public constructor<D>(t: R|D|): R|Ref<D>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val t: R|D| = R|<local>/t|
|
||||
public get(): R|D|
|
||||
|
||||
public final operator fun component1(): R|D|
|
||||
|
||||
public final fun copy(t: R|D| = this@R|/Ref|.R|/Ref.t|): R|Ref<D>|
|
||||
|
||||
}
|
||||
public final class GenericDelegate<G> : R|kotlin/Any| {
|
||||
public constructor<G>(value: R|G|): R|GenericDelegate<G>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val value: R|G| = R|<local>/value|
|
||||
public get(): R|G|
|
||||
|
||||
}
|
||||
public final operator fun <V> R|Ref<V>|.provideDelegate(a: R|kotlin/Any?|, p: R|kotlin/reflect/KProperty<*>|): R|GenericDelegate<V>| {
|
||||
^provideDelegate R|/GenericDelegate.GenericDelegate|<R|V|>(this@R|/provideDelegate|.R|SubstitutionOverride</Ref.t: R|V|>|)
|
||||
}
|
||||
public final operator fun <W> R|GenericDelegate<W>|.getValue(a: R|kotlin/Any?|, p: R|kotlin/reflect/KProperty<*>|): R|W| {
|
||||
^getValue this@R|/getValue|.R|SubstitutionOverride</GenericDelegate.value: R|W|>|
|
||||
}
|
||||
public final fun <E> R|kotlin/collections/List<Ref<*>>|.getElement(i: R|kotlin/Int|): R|Ref<E>| {
|
||||
^getElement (this@R|/getElement|.R|SubstitutionOverride<kotlin/collections/List.get: R|Ref<*>|>|(R|<local>/i|) as R|Ref<E>|)
|
||||
}
|
||||
public final fun test(list: R|kotlin/collections/List<Ref<*>>|): R|kotlin/Unit| {
|
||||
lval data: R|kotlin/String|by R|<local>/list|.R|/getElement|<R|kotlin/String|>(Int(0))!!.R|/provideDelegate|<R|kotlin/String|>(Null(null), ::R|<local>/data|)
|
||||
lval data2: R|kotlin/String|by R|<local>/list|.R|/getElement|<R|kotlin/String|>(Int(0)).R|/provideDelegate|<R|kotlin/String|>(Null(null), ::R|<local>/data2|)
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// ISSUE: KT-58013
|
||||
// WITH_REFLECT
|
||||
// FIR_DUMP
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
data class Ref<D>(val t: D)
|
||||
|
||||
class GenericDelegate<G>(val value: G)
|
||||
|
||||
operator fun <V> Ref<V>.provideDelegate(a: Any?, p: KProperty<*>): GenericDelegate<V> = GenericDelegate(this.t)
|
||||
|
||||
operator fun <W> GenericDelegate<W>.getValue(a: Any?, p: KProperty<*>): W = this.value
|
||||
|
||||
fun <E> List<Ref<*>>.getElement(i: Int): Ref<E> = this[i] <!UNCHECKED_CAST!>as Ref<E><!>
|
||||
|
||||
fun test(list: List<Ref<*>>) {
|
||||
val data: String by <!DELEGATE_SPECIAL_FUNCTION_MISSING, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>list.getElement(0)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!><!>
|
||||
|
||||
val data2: String by list.getElement(0)
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// FIR_IDENTICAL
|
||||
class C {
|
||||
operator fun getValue(x: Any?, y: Any?): String = ""
|
||||
}
|
||||
|
||||
object O {
|
||||
operator fun provideDelegate(x: Any?, y: Any?): C = C()
|
||||
}
|
||||
|
||||
val x: String by O
|
||||
Generated
+36
@@ -8895,6 +8895,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("elvisInDelegated.kt")
|
||||
public void testElvisInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/elvisInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionGet.kt")
|
||||
public void testExtensionGet() throws Exception {
|
||||
@@ -8919,6 +8925,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ifInDelegated.kt")
|
||||
public void testIfInDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/ifInDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt41952.kt")
|
||||
public void testKt41952() throws Exception {
|
||||
@@ -8961,12 +8973,24 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/noExpectedTypeForSupertypeConstraint.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resultTypeOfLambdaForConventionMethods.kt")
|
||||
public void testResultTypeOfLambdaForConventionMethods() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/resultTypeOfLambdaForConventionMethods.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryInGenerated.kt")
|
||||
public void testTryInGenerated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/inference/tryInGenerated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeOfLazyDelegatedPropertyWithObject.kt")
|
||||
public void testTypeOfLazyDelegatedPropertyWithObject() throws Exception {
|
||||
@@ -9061,6 +9085,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("notNullAssertionInLocalDelegated.kt")
|
||||
public void testNotNullAssertionInLocalDelegated() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/notNullAssertionInLocalDelegated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onObject.kt")
|
||||
public void testOnObject() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/onObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadResolutionForSeveralProvideDelegates.kt")
|
||||
public void testOverloadResolutionForSeveralProvideDelegates() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user