[NI] Add required FactoryPattern annotation for factory pattern resolve
#KT-11265
This commit is contained in:
+5
@@ -1809,6 +1809,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
||||
public void testOverloadByLambdaReturnType_enabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadByLambdaReturnType_enabled_no_annotation.kt")
|
||||
public void testOverloadByLambdaReturnType_enabled_no_annotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_enabled_no_annotation.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop")
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
|
||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
||||
@@ -36,6 +37,9 @@ class KotlinCallResolver(
|
||||
private val callableReferenceResolver: CallableReferenceResolver,
|
||||
private val callComponents: KotlinCallComponents
|
||||
) {
|
||||
companion object {
|
||||
private val FACTORY_PATTERN_ANNOTATION = FqName.fromSegments(listOf("annotations", "FactoryPattern"))
|
||||
}
|
||||
|
||||
fun resolveCall(
|
||||
scopeTower: ImplicitScopeTower,
|
||||
@@ -147,13 +151,16 @@ class KotlinCallResolver(
|
||||
discriminateGenerics = true // todo
|
||||
)
|
||||
|
||||
if (maximallySpecificCandidates.size > 1 && callComponents.languageVersionSettings.supportsFeature(LanguageFeature.FactoryPatternResolution)) {
|
||||
if (
|
||||
maximallySpecificCandidates.size > 1 &&
|
||||
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.FactoryPatternResolution) &&
|
||||
candidates.any { it.resolvedCall.candidateDescriptor.annotations.hasAnnotation(FACTORY_PATTERN_ANNOTATION) } &&
|
||||
candidates.all { resolutionCallbacks.inferenceSession.shouldRunCompletion(it) }
|
||||
) {
|
||||
maximallySpecificCandidates = kotlinCallCompleter.chooseCandidateRegardingFactoryPatternResolution(maximallySpecificCandidates, resolutionCallbacks)
|
||||
}
|
||||
|
||||
return kotlinCallCompleter.runCompletion(candidateFactory, maximallySpecificCandidates, expectedType, resolutionCallbacks)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -2,6 +2,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||
// ISSUE: KT-11265
|
||||
|
||||
// FILE: FactoryPattern.kt
|
||||
|
||||
package annotations
|
||||
|
||||
annotation class FactoryPattern
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import annotations.FactoryPattern
|
||||
|
||||
@FactoryPattern
|
||||
fun create(f: (Int) -> Int): Int = 1
|
||||
fun create(f: (Int) -> String): String = ""
|
||||
|
||||
@@ -22,6 +33,7 @@ fun test_3() {
|
||||
val x = <!AMBIGUITY!>create<!> { 1.0 }
|
||||
}
|
||||
|
||||
@FactoryPattern
|
||||
fun <K> create(x: K, f: (K) -> Int): Int = 1
|
||||
fun <T> create(x: T, f: (T) -> String): String = ""
|
||||
|
||||
|
||||
Vendored
+12
@@ -2,6 +2,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||
// ISSUE: KT-11265
|
||||
|
||||
// FILE: FactoryPattern.kt
|
||||
|
||||
package annotations
|
||||
|
||||
annotation class FactoryPattern
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import annotations.FactoryPattern
|
||||
|
||||
@FactoryPattern
|
||||
fun create(f: (Int) -> Int): Int = 1
|
||||
fun create(f: (Int) -> String): String = ""
|
||||
|
||||
@@ -22,6 +33,7 @@ fun test_3() {
|
||||
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY!>create<!> { 1.0 }
|
||||
}
|
||||
|
||||
@FactoryPattern
|
||||
fun <K> create(x: K, f: (K) -> Int): Int = 1
|
||||
fun <T> create(x: T, f: (T) -> String): String = ""
|
||||
|
||||
|
||||
compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_disabled.txt
Vendored
+12
-2
@@ -1,8 +1,8 @@
|
||||
package
|
||||
|
||||
public fun create(/*0*/ f: (kotlin.Int) -> kotlin.Int): kotlin.Int
|
||||
@annotations.FactoryPattern public fun create(/*0*/ f: (kotlin.Int) -> kotlin.Int): kotlin.Int
|
||||
public fun create(/*0*/ f: (kotlin.Int) -> kotlin.String): kotlin.String
|
||||
public fun </*0*/ K> create(/*0*/ x: K, /*1*/ f: (K) -> kotlin.Int): kotlin.Int
|
||||
@annotations.FactoryPattern public fun </*0*/ K> create(/*0*/ x: K, /*1*/ f: (K) -> kotlin.Int): kotlin.Int
|
||||
public fun </*0*/ T> create(/*0*/ x: T, /*1*/ f: (T) -> kotlin.String): kotlin.String
|
||||
public fun takeInt(/*0*/ s: kotlin.Int): kotlin.Unit
|
||||
public fun takeString(/*0*/ s: kotlin.String): kotlin.Unit
|
||||
@@ -11,3 +11,13 @@ public fun test_2(): kotlin.Unit
|
||||
public fun test_3(): kotlin.Unit
|
||||
public fun test_4(): kotlin.Unit
|
||||
public fun test_5(): kotlin.Unit
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -2,6 +2,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||
// ISSUE: KT-11265
|
||||
|
||||
// FILE: FactoryPattern.kt
|
||||
|
||||
package annotations
|
||||
|
||||
annotation class FactoryPattern
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import annotations.FactoryPattern
|
||||
|
||||
@FactoryPattern
|
||||
fun create(f: (Int) -> Int): Int = 1
|
||||
fun create(f: (Int) -> String): String = ""
|
||||
|
||||
@@ -22,6 +33,7 @@ fun test_3() {
|
||||
val x = <!AMBIGUITY!>create<!> { 1.0 }
|
||||
}
|
||||
|
||||
@FactoryPattern
|
||||
fun <K> create(x: K, f: (K) -> Int): Int = 1
|
||||
fun <T> create(x: T, f: (T) -> String): String = ""
|
||||
|
||||
|
||||
Vendored
+12
@@ -2,6 +2,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||
// ISSUE: KT-11265
|
||||
|
||||
// FILE: FactoryPattern.kt
|
||||
|
||||
package annotations
|
||||
|
||||
annotation class FactoryPattern
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
import annotations.FactoryPattern
|
||||
|
||||
@FactoryPattern
|
||||
fun create(f: (Int) -> Int): Int = 1
|
||||
fun create(f: (Int) -> String): String = ""
|
||||
|
||||
@@ -22,6 +33,7 @@ fun test_3() {
|
||||
val x = <!NONE_APPLICABLE!>create<!> { 1.0 }
|
||||
}
|
||||
|
||||
@FactoryPattern
|
||||
fun <K> create(x: K, f: (K) -> Int): Int = 1
|
||||
fun <T> create(x: T, f: (T) -> String): String = ""
|
||||
|
||||
|
||||
Vendored
+12
-2
@@ -1,8 +1,8 @@
|
||||
package
|
||||
|
||||
public fun create(/*0*/ f: (kotlin.Int) -> kotlin.Int): kotlin.Int
|
||||
@annotations.FactoryPattern public fun create(/*0*/ f: (kotlin.Int) -> kotlin.Int): kotlin.Int
|
||||
public fun create(/*0*/ f: (kotlin.Int) -> kotlin.String): kotlin.String
|
||||
public fun </*0*/ K> create(/*0*/ x: K, /*1*/ f: (K) -> kotlin.Int): kotlin.Int
|
||||
@annotations.FactoryPattern public fun </*0*/ K> create(/*0*/ x: K, /*1*/ f: (K) -> kotlin.Int): kotlin.Int
|
||||
public fun </*0*/ T> create(/*0*/ x: T, /*1*/ f: (T) -> kotlin.String): kotlin.String
|
||||
public fun takeInt(/*0*/ s: kotlin.Int): kotlin.Unit
|
||||
public fun takeString(/*0*/ s: kotlin.String): kotlin.Unit
|
||||
@@ -11,3 +11,13 @@ public fun test_2(): kotlin.Unit
|
||||
public fun test_3(): kotlin.Unit
|
||||
public fun test_4(): kotlin.Unit
|
||||
public fun test_5(): kotlin.Unit
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||
// ISSUE: KT-11265
|
||||
|
||||
fun create(f: (Int) -> Int): Int = 1
|
||||
fun create(f: (Int) -> String): String = ""
|
||||
|
||||
fun takeString(s: String) {}
|
||||
fun takeInt(s: Int) {}
|
||||
|
||||
fun test_1() {
|
||||
val x = <!AMBIGUITY!>create<!> { "" }
|
||||
takeString(x)
|
||||
}
|
||||
|
||||
fun test_2() {
|
||||
val x = <!AMBIGUITY!>create<!> { 1 }
|
||||
takeInt(x)
|
||||
}
|
||||
|
||||
fun test_3() {
|
||||
val x = <!AMBIGUITY!>create<!> { 1.0 }
|
||||
}
|
||||
|
||||
fun <K> create(x: K, f: (K) -> Int): Int = 1
|
||||
fun <T> create(x: T, f: (T) -> String): String = ""
|
||||
|
||||
fun test_4() {
|
||||
val x = <!AMBIGUITY!>create<!>("") { "" }
|
||||
takeString(x)
|
||||
}
|
||||
|
||||
fun test_5() {
|
||||
val x = <!AMBIGUITY!>create<!>("") { 1 }
|
||||
takeInt(x)
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// !LANGUAGE: +NewInference +FactoryPatternResolution
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||
// ISSUE: KT-11265
|
||||
|
||||
fun create(f: (Int) -> Int): Int = 1
|
||||
fun create(f: (Int) -> String): String = ""
|
||||
|
||||
fun takeString(s: String) {}
|
||||
fun takeInt(s: Int) {}
|
||||
|
||||
fun test_1() {
|
||||
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY!>create<!> { "" }
|
||||
takeString(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>)
|
||||
}
|
||||
|
||||
fun test_2() {
|
||||
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY!>create<!> { 1 }
|
||||
takeInt(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>)
|
||||
}
|
||||
|
||||
fun test_3() {
|
||||
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY!>create<!> { 1.0 }
|
||||
}
|
||||
|
||||
fun <K> create(x: K, f: (K) -> Int): Int = 1
|
||||
fun <T> create(x: T, f: (T) -> String): String = ""
|
||||
|
||||
fun test_4() {
|
||||
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY!>create<!>("") { "" }
|
||||
takeString(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>)
|
||||
}
|
||||
|
||||
fun test_5() {
|
||||
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY!>create<!>("") { 1 }
|
||||
takeInt(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>)
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
public fun create(/*0*/ f: (kotlin.Int) -> kotlin.Int): kotlin.Int
|
||||
public fun create(/*0*/ f: (kotlin.Int) -> kotlin.String): kotlin.String
|
||||
public fun </*0*/ K> create(/*0*/ x: K, /*1*/ f: (K) -> kotlin.Int): kotlin.Int
|
||||
public fun </*0*/ T> create(/*0*/ x: T, /*1*/ f: (T) -> kotlin.String): kotlin.String
|
||||
public fun takeInt(/*0*/ s: kotlin.Int): kotlin.Unit
|
||||
public fun takeString(/*0*/ s: kotlin.String): kotlin.Unit
|
||||
public fun test_1(): kotlin.Unit
|
||||
public fun test_2(): kotlin.Unit
|
||||
public fun test_3(): kotlin.Unit
|
||||
public fun test_4(): kotlin.Unit
|
||||
public fun test_5(): kotlin.Unit
|
||||
+5
@@ -2824,6 +2824,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
public void testOverloadByLambdaReturnType_enabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadByLambdaReturnType_enabled_no_annotation.kt")
|
||||
public void testOverloadByLambdaReturnType_enabled_no_annotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_enabled_no_annotation.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop")
|
||||
|
||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -2824,6 +2824,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
public void testOverloadByLambdaReturnType_enabled() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_enabled.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overloadByLambdaReturnType_enabled_no_annotation.kt")
|
||||
public void testOverloadByLambdaReturnType_enabled_no_annotation() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/factoryPattern/overloadByLambdaReturnType_enabled_no_annotation.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop")
|
||||
|
||||
Reference in New Issue
Block a user