[NI] Analyse lambda in factory pattern resolution in independent context
This commit is contained in:
+5
@@ -1800,6 +1800,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/factoryPattern"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/factoryPattern"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("independentResolutionInLambda.kt")
|
||||||
|
public void testIndependentResolutionInLambda() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
||||||
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
||||||
|
|||||||
+3
-2
@@ -95,7 +95,8 @@ class KotlinResolutionCallbacksImpl(
|
|||||||
parameters: List<UnwrappedType>,
|
parameters: List<UnwrappedType>,
|
||||||
expectedReturnType: UnwrappedType?,
|
expectedReturnType: UnwrappedType?,
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
stubsForPostponedVariables: Map<NewTypeVariable, StubType>
|
stubsForPostponedVariables: Map<NewTypeVariable, StubType>,
|
||||||
|
shouldRunInIndependentContext: Boolean
|
||||||
): ReturnArgumentsAnalysisResult {
|
): ReturnArgumentsAnalysisResult {
|
||||||
val psiCallArgument = lambdaArgument.psiCallArgument as PSIFunctionKotlinCallArgument
|
val psiCallArgument = lambdaArgument.psiCallArgument as PSIFunctionKotlinCallArgument
|
||||||
val outerCallContext = psiCallArgument.outerCallContext
|
val outerCallContext = psiCallArgument.outerCallContext
|
||||||
@@ -137,7 +138,7 @@ class KotlinResolutionCallbacksImpl(
|
|||||||
|
|
||||||
val lambdaInfo = LambdaInfo(
|
val lambdaInfo = LambdaInfo(
|
||||||
expectedReturnType ?: TypeUtils.NO_EXPECTED_TYPE,
|
expectedReturnType ?: TypeUtils.NO_EXPECTED_TYPE,
|
||||||
if (expectedReturnType == null) ContextDependency.DEPENDENT else ContextDependency.INDEPENDENT
|
if (expectedReturnType != null || shouldRunInIndependentContext) ContextDependency.INDEPENDENT else ContextDependency.DEPENDENT
|
||||||
)
|
)
|
||||||
|
|
||||||
val builtIns = outerCallContext.scope.ownerDescriptor.builtIns
|
val builtIns = outerCallContext.scope.ownerDescriptor.builtIns
|
||||||
|
|||||||
+2
-1
@@ -72,7 +72,8 @@ interface KotlinResolutionCallbacks {
|
|||||||
parameters: List<UnwrappedType>,
|
parameters: List<UnwrappedType>,
|
||||||
expectedReturnType: UnwrappedType?, // null means, that return type is not proper i.e. it depends on some type variables
|
expectedReturnType: UnwrappedType?, // null means, that return type is not proper i.e. it depends on some type variables
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
stubsForPostponedVariables: Map<NewTypeVariable, StubType>
|
stubsForPostponedVariables: Map<NewTypeVariable, StubType>,
|
||||||
|
shouldRunInIndependentContext: Boolean = false
|
||||||
): ReturnArgumentsAnalysisResult
|
): ReturnArgumentsAnalysisResult
|
||||||
|
|
||||||
fun bindStubResolvedCallForCandidate(candidate: ResolvedCallAtom)
|
fun bindStubResolvedCallForCandidate(candidate: ResolvedCallAtom)
|
||||||
|
|||||||
+2
-1
@@ -115,7 +115,8 @@ class KotlinCallCompleter(
|
|||||||
firstCandidate.getSystem().asPostponedArgumentsAnalyzerContext(),
|
firstCandidate.getSystem().asPostponedArgumentsAnalyzerContext(),
|
||||||
resolutionCallbacks,
|
resolutionCallbacks,
|
||||||
firstAtom,
|
firstAtom,
|
||||||
diagnosticHolderForLambda
|
diagnosticHolderForLambda,
|
||||||
|
shouldRunInIndependentContext = true
|
||||||
)
|
)
|
||||||
lambdas.getValue(firstCandidate).setAnalyzedResults(results.returnArgumentsInfo, listOf(firstAtom))
|
lambdas.getValue(firstCandidate).setAnalyzedResults(results.returnArgumentsInfo, listOf(firstAtom))
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -70,7 +70,8 @@ class PostponedArgumentsAnalyzer(
|
|||||||
c: Context,
|
c: Context,
|
||||||
resolutionCallbacks: KotlinResolutionCallbacks,
|
resolutionCallbacks: KotlinResolutionCallbacks,
|
||||||
lambda: ResolvedLambdaAtom,
|
lambda: ResolvedLambdaAtom,
|
||||||
diagnosticHolder: KotlinDiagnosticsHolder
|
diagnosticHolder: KotlinDiagnosticsHolder,
|
||||||
|
shouldRunInIndependentContext: Boolean = false
|
||||||
): ReturnArgumentsAnalysisResult {
|
): ReturnArgumentsAnalysisResult {
|
||||||
val stubsForPostponedVariables = c.bindingStubsForPostponedVariables()
|
val stubsForPostponedVariables = c.bindingStubsForPostponedVariables()
|
||||||
val currentSubstitutor = c.buildCurrentSubstitutor(stubsForPostponedVariables.mapKeys { it.key.freshTypeConstructor(c) })
|
val currentSubstitutor = c.buildCurrentSubstitutor(stubsForPostponedVariables.mapKeys { it.key.freshTypeConstructor(c) })
|
||||||
@@ -128,7 +129,8 @@ class PostponedArgumentsAnalyzer(
|
|||||||
parameters,
|
parameters,
|
||||||
expectedTypeForReturnArguments,
|
expectedTypeForReturnArguments,
|
||||||
convertedAnnotations ?: Annotations.EMPTY,
|
convertedAnnotations ?: Annotations.EMPTY,
|
||||||
stubsForPostponedVariables.cast()
|
stubsForPostponedVariables.cast(),
|
||||||
|
shouldRunInIndependentContext
|
||||||
)
|
)
|
||||||
val (returnArgumentsInfo, inferenceSession, inferedReturnType, hasInapplicableCallForBuilderInference) =
|
val (returnArgumentsInfo, inferenceSession, inferedReturnType, hasInapplicableCallForBuilderInference) =
|
||||||
returnArgumentsAnalysisResult
|
returnArgumentsAnalysisResult
|
||||||
|
|||||||
Vendored
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||||
|
// ISSUE: KT-11265
|
||||||
|
|
||||||
|
// FILE: FactoryPattern.kt
|
||||||
|
|
||||||
|
package annotations
|
||||||
|
|
||||||
|
annotation class FactoryPattern
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
import annotations.FactoryPattern
|
||||||
|
|
||||||
|
@kotlin.jvm.JvmName("myFlatMapIterable")
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T, R> Sequence<T>.myFlatMap(transform: (T) -> Iterable<R>): Sequence<R> {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T, R> Sequence<T>.myFlatMap(transform: (T) -> Sequence<R>): Sequence<R> {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
val supertypes: Collection<B>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface B {
|
||||||
|
val descriptors: Sequence<C>?
|
||||||
|
}
|
||||||
|
|
||||||
|
interface C
|
||||||
|
|
||||||
|
fun <K : Any> elvis(x: K?, y: K): K = y
|
||||||
|
|
||||||
|
fun test(a: A) {
|
||||||
|
a.supertypes.asSequence().<!AMBIGUITY!>myFlatMap<!> {
|
||||||
|
<!INAPPLICABLE_CANDIDATE!>elvis<!>(<!UNRESOLVED_REFERENCE!>it<!>.<!UNRESOLVED_REFERENCE!>descriptors<!>, sequenceOf())
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||||
|
// ISSUE: KT-11265
|
||||||
|
|
||||||
|
// FILE: FactoryPattern.kt
|
||||||
|
|
||||||
|
package annotations
|
||||||
|
|
||||||
|
annotation class FactoryPattern
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
import annotations.FactoryPattern
|
||||||
|
|
||||||
|
@kotlin.jvm.JvmName("myFlatMapIterable")
|
||||||
|
@FactoryPattern
|
||||||
|
fun <T, R> Sequence<T>.myFlatMap(transform: (T) -> Iterable<R>): Sequence<R> {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T, R> Sequence<T>.myFlatMap(transform: (T) -> Sequence<R>): Sequence<R> {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
val supertypes: Collection<B>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface B {
|
||||||
|
val descriptors: Sequence<C>?
|
||||||
|
}
|
||||||
|
|
||||||
|
interface C
|
||||||
|
|
||||||
|
fun <K : Any> elvis(x: K?, y: K): K = y
|
||||||
|
|
||||||
|
fun test(a: A) {
|
||||||
|
a.supertypes.asSequence().myFlatMap {
|
||||||
|
elvis(it.descriptors, sequenceOf())
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun </*0*/ K : kotlin.Any> elvis(/*0*/ x: K?, /*1*/ y: K): K
|
||||||
|
public fun test(/*0*/ a: A): kotlin.Unit
|
||||||
|
@kotlin.jvm.JvmName(name = "myFlatMapIterable") @annotations.FactoryPattern public fun </*0*/ T, /*1*/ R> kotlin.sequences.Sequence<T>.myFlatMap(/*0*/ transform: (T) -> kotlin.collections.Iterable<R>): kotlin.sequences.Sequence<R>
|
||||||
|
public fun </*0*/ T, /*1*/ R> kotlin.sequences.Sequence<T>.myFlatMap(/*0*/ transform: (T) -> kotlin.sequences.Sequence<R>): kotlin.sequences.Sequence<R>
|
||||||
|
|
||||||
|
public interface A {
|
||||||
|
public abstract val supertypes: kotlin.collections.Collection<B>
|
||||||
|
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 B {
|
||||||
|
public abstract val descriptors: kotlin.sequences.Sequence<C>?
|
||||||
|
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 C {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
package annotations {
|
||||||
|
|
||||||
|
public final annotation class FactoryPattern : kotlin.Annotation {
|
||||||
|
public constructor FactoryPattern()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -2815,6 +2815,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/factoryPattern"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/factoryPattern"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("independentResolutionInLambda.kt")
|
||||||
|
public void testIndependentResolutionInLambda() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
||||||
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -2815,6 +2815,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/factoryPattern"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/factoryPattern"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("independentResolutionInLambda.kt")
|
||||||
|
public void testIndependentResolutionInLambda() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/independentResolutionInLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
@TestMetadata("overloadByLambdaReturnType_disabled.kt")
|
||||||
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
public void testOverloadByLambdaReturnType_disabled() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user