Fix collection literals resolve in gradle-based projects
#KT-19441 Fixed
This commit is contained in:
@@ -74,16 +74,15 @@ class CollectionLiteralResolver(val module: ModuleDescriptor, val callResolver:
|
|||||||
): KotlinTypeInfo {
|
): KotlinTypeInfo {
|
||||||
val call = CallMaker.makeCallForCollectionLiteral(expression)
|
val call = CallMaker.makeCallForCollectionLiteral(expression)
|
||||||
val callName = getArrayFunctionCallName(context.expectedType)
|
val callName = getArrayFunctionCallName(context.expectedType)
|
||||||
val functionDescriptor = getFunctionDescriptorForCollectionLiteral(expression, callName)
|
val functionDescriptors = getFunctionDescriptorForCollectionLiteral(expression, callName)
|
||||||
if (functionDescriptor == null) {
|
if (functionDescriptors.isEmpty()) {
|
||||||
context.trace.report(MISSING_STDLIB.on(
|
context.trace.report(MISSING_STDLIB.on(
|
||||||
expression, "Collection literal call '$callName()' is unresolved"))
|
expression, "Collection literal call '$callName()' is unresolved"))
|
||||||
return noTypeInfo(context)
|
return noTypeInfo(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolutionResults = callResolver.resolveCollectionLiteralCallWithGivenDescriptor(context, expression, call, functionDescriptor)
|
val resolutionResults = callResolver.resolveCollectionLiteralCallWithGivenDescriptor(context, expression, call, functionDescriptors)
|
||||||
|
|
||||||
// No single result after resolving one candidate?
|
|
||||||
if (!resolutionResults.isSingleResult) {
|
if (!resolutionResults.isSingleResult) {
|
||||||
return noTypeInfo(context)
|
return noTypeInfo(context)
|
||||||
}
|
}
|
||||||
@@ -95,9 +94,9 @@ class CollectionLiteralResolver(val module: ModuleDescriptor, val callResolver:
|
|||||||
private fun getFunctionDescriptorForCollectionLiteral(
|
private fun getFunctionDescriptorForCollectionLiteral(
|
||||||
expression: KtCollectionLiteralExpression,
|
expression: KtCollectionLiteralExpression,
|
||||||
callName: Name
|
callName: Name
|
||||||
): SimpleFunctionDescriptor? {
|
): Collection<SimpleFunctionDescriptor> {
|
||||||
val memberScopeOfKotlinPackage = module.getPackage(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME).memberScope
|
val memberScopeOfKotlinPackage = module.getPackage(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME).memberScope
|
||||||
return memberScopeOfKotlinPackage.getContributedFunctions(callName, KotlinLookupLocation(expression)).singleOrNull()
|
return memberScopeOfKotlinPackage.getContributedFunctions(callName, KotlinLookupLocation(expression))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkSupportsArrayLiterals(expression: KtCollectionLiteralExpression, context: ExpressionTypingContext) {
|
private fun checkSupportsArrayLiterals(expression: KtCollectionLiteralExpression, context: ExpressionTypingContext) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import kotlin.Pair;
|
import kotlin.Pair;
|
||||||
|
import kotlin.collections.CollectionsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
||||||
@@ -247,14 +248,19 @@ public class CallResolver {
|
|||||||
@NotNull ExpressionTypingContext context,
|
@NotNull ExpressionTypingContext context,
|
||||||
@NotNull KtCollectionLiteralExpression expression,
|
@NotNull KtCollectionLiteralExpression expression,
|
||||||
@NotNull Call call,
|
@NotNull Call call,
|
||||||
@NotNull FunctionDescriptor functionDescriptor
|
@NotNull Collection<FunctionDescriptor> functionDescriptors
|
||||||
) {
|
) {
|
||||||
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS);
|
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS);
|
||||||
ResolutionCandidate<FunctionDescriptor> candidate = ResolutionCandidate.create(
|
List<ResolutionCandidate<FunctionDescriptor>> candidates = CollectionsKt.map(functionDescriptors, descriptor ->
|
||||||
call, functionDescriptor, null, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, null);
|
ResolutionCandidate.create(
|
||||||
|
call,
|
||||||
|
descriptor,
|
||||||
|
null,
|
||||||
|
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER,
|
||||||
|
null));
|
||||||
|
|
||||||
return computeTasksFromCandidatesAndResolvedCall(
|
return computeTasksFromCandidatesAndResolvedCall(
|
||||||
callResolutionContext, Collections.singleton(candidate), TracingStrategyImpl.create(expression, call));
|
callResolutionContext, candidates, TracingStrategyImpl.create(expression, call));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Vendored
+32
@@ -0,0 +1,32 @@
|
|||||||
|
OUT:
|
||||||
|
Buildfile: [TestData]/build.xml
|
||||||
|
|
||||||
|
build:
|
||||||
|
[mkdir] Created dir: [Temp]/classes
|
||||||
|
[javac] Compiling 2 source files to [Temp]/classes
|
||||||
|
[javac] Compiling [[TestData]] => [[Temp]/classes]
|
||||||
|
[javac] [TestData]/literals.kt:6:9: error: overload resolution ambiguity:
|
||||||
|
[javac] public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt
|
||||||
|
[javac] public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt
|
||||||
|
[javac] @AnnInt([1, 2])
|
||||||
|
[javac] ^
|
||||||
|
[javac] [TestData]/literals.kt:9:9: error: overload resolution ambiguity:
|
||||||
|
[javac] public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt
|
||||||
|
[javac] public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt
|
||||||
|
[javac] @AnnInt(intArrayOf(1, 2))
|
||||||
|
[javac] ^
|
||||||
|
[javac] [TestData]/myArrayOf.kt:3:1: error: conflicting overloads: public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt, public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt
|
||||||
|
[javac] public fun intArrayOf(vararg elements: Int): IntArray = TODO()
|
||||||
|
[javac] ^
|
||||||
|
[javac] [TestData]/myArrayOf.kt:4:1: error: conflicting overloads: public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt, public fun intArrayOf(vararg elements: Int): IntArray defined in kotlin in file myArrayOf.kt
|
||||||
|
[javac] public fun intArrayOf(vararg elements: Int): IntArray = TODO()
|
||||||
|
[javac] ^
|
||||||
|
|
||||||
|
ERR:
|
||||||
|
|
||||||
|
BUILD FAILED
|
||||||
|
[TestData]/build.xml:6: Compile failed; see the compiler error output for details.
|
||||||
|
|
||||||
|
Total time: [time]
|
||||||
|
|
||||||
|
Return code: 1
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<project name="Ant Task Test" default="build">
|
||||||
|
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||||
|
|
||||||
|
<target name="build">
|
||||||
|
<mkdir dir="${temp}/classes"/>
|
||||||
|
<javac srcdir="${test.data}" destdir="${temp}/classes" includeantruntime="false">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${kotlin.runtime.jar}"/>
|
||||||
|
</classpath>
|
||||||
|
<withKotlin>
|
||||||
|
<compilerarg value="-Xallow-kotlin-package"/>
|
||||||
|
</withKotlin>
|
||||||
|
</javac>
|
||||||
|
<jar destfile="${temp}/literals.jar">
|
||||||
|
<fileset dir="${temp}/classes"/>
|
||||||
|
</jar>
|
||||||
|
|
||||||
|
<java classname="lit.LiteralsKt" fork="true">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${temp}/literals.jar"/>
|
||||||
|
<pathelement location="${kotlin.runtime.jar}"/>
|
||||||
|
</classpath>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
</project>
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package lit
|
||||||
|
|
||||||
|
annotation class AnnInt(val a: IntArray)
|
||||||
|
|
||||||
|
@Suppress("UNSUPPORTED_FEATURE")
|
||||||
|
@AnnInt([1, 2])
|
||||||
|
fun foo() {}
|
||||||
|
|
||||||
|
@AnnInt(intArrayOf(1, 2))
|
||||||
|
fun bar() {}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
foo()
|
||||||
|
bar()
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package kotlin
|
||||||
|
|
||||||
|
public fun intArrayOf(vararg elements: Int): IntArray = TODO()
|
||||||
|
public fun intArrayOf(vararg elements: Int): IntArray = TODO()
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
OUT:
|
||||||
|
Buildfile: [TestData]/build.xml
|
||||||
|
|
||||||
|
build:
|
||||||
|
[mkdir] Created dir: [Temp]/classes
|
||||||
|
[javac] Compiling 2 source files to [Temp]/classes
|
||||||
|
[javac] Compiling [[TestData]] => [[Temp]/classes]
|
||||||
|
[javac] [TestData]/myArrayOf.kt:3:30: warning: parameter 'elements' is never used
|
||||||
|
[javac] public fun intArrayOf(vararg elements: Int): IntArray = TODO()
|
||||||
|
[javac] ^
|
||||||
|
[javac] Running javac...
|
||||||
|
[jar] Building jar: [Temp]/literals.jar
|
||||||
|
|
||||||
|
BUILD SUCCESSFUL
|
||||||
|
Total time: [time]
|
||||||
|
|
||||||
|
Return code: 0
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<project name="Ant Task Test" default="build">
|
||||||
|
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||||
|
|
||||||
|
<target name="build">
|
||||||
|
<mkdir dir="${temp}/classes"/>
|
||||||
|
<javac srcdir="${test.data}" destdir="${temp}/classes" includeantruntime="false">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${kotlin.runtime.jar}"/>
|
||||||
|
</classpath>
|
||||||
|
<withKotlin>
|
||||||
|
<compilerarg value="-Xallow-kotlin-package"/>
|
||||||
|
</withKotlin>
|
||||||
|
</javac>
|
||||||
|
<jar destfile="${temp}/literals.jar">
|
||||||
|
<fileset dir="${temp}/classes"/>
|
||||||
|
</jar>
|
||||||
|
|
||||||
|
<java classname="lit.LiteralsKt" fork="true">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${temp}/literals.jar"/>
|
||||||
|
<pathelement location="${kotlin.runtime.jar}"/>
|
||||||
|
</classpath>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
</project>
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package lit
|
||||||
|
|
||||||
|
annotation class AnnInt(val a: IntArray)
|
||||||
|
|
||||||
|
@Suppress("UNSUPPORTED_FEATURE")
|
||||||
|
@AnnInt([1, 2])
|
||||||
|
fun foo() {}
|
||||||
|
|
||||||
|
@AnnInt(intArrayOf(1, 2))
|
||||||
|
fun bar() {}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
foo()
|
||||||
|
bar()
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package kotlin
|
||||||
|
|
||||||
|
public fun intArrayOf(vararg elements: Int): IntArray = TODO()
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
OUT:
|
||||||
|
Buildfile: [TestData]/build.xml
|
||||||
|
|
||||||
|
build:
|
||||||
|
[mkdir] Created dir: [Temp]/classes
|
||||||
|
[javac] Compiling 2 source files to [Temp]/classes
|
||||||
|
[javac] Compiling [[TestData]] => [[Temp]/classes]
|
||||||
|
[javac] [TestData]/literals.kt:6:9: error: type mismatch: inferred type is FloatArray but IntArray was expected
|
||||||
|
[javac] @AnnInt([1, 2])
|
||||||
|
[javac] ^
|
||||||
|
[javac] [TestData]/literals.kt:9:9: error: type mismatch: inferred type is FloatArray but IntArray was expected
|
||||||
|
[javac] @AnnInt(intArrayOf(1, 2))
|
||||||
|
[javac] ^
|
||||||
|
|
||||||
|
ERR:
|
||||||
|
|
||||||
|
BUILD FAILED
|
||||||
|
[TestData]/build.xml:6: Compile failed; see the compiler error output for details.
|
||||||
|
|
||||||
|
Total time: [time]
|
||||||
|
|
||||||
|
Return code: 1
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<project name="Ant Task Test" default="build">
|
||||||
|
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||||
|
|
||||||
|
<target name="build">
|
||||||
|
<mkdir dir="${temp}/classes"/>
|
||||||
|
<javac srcdir="${test.data}" destdir="${temp}/classes" includeantruntime="false">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${kotlin.runtime.jar}"/>
|
||||||
|
</classpath>
|
||||||
|
<withKotlin>
|
||||||
|
<compilerarg value="-Xallow-kotlin-package"/>
|
||||||
|
</withKotlin>
|
||||||
|
</javac>
|
||||||
|
<jar destfile="${temp}/literals.jar">
|
||||||
|
<fileset dir="${temp}/classes"/>
|
||||||
|
</jar>
|
||||||
|
|
||||||
|
<java classname="lit.LiteralsKt" fork="true">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${temp}/literals.jar"/>
|
||||||
|
<pathelement location="${kotlin.runtime.jar}"/>
|
||||||
|
</classpath>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
</project>
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package lit
|
||||||
|
|
||||||
|
annotation class AnnInt(val a: IntArray)
|
||||||
|
|
||||||
|
@Suppress("UNSUPPORTED_FEATURE")
|
||||||
|
@AnnInt([1, 2])
|
||||||
|
fun foo() {}
|
||||||
|
|
||||||
|
@AnnInt(intArrayOf(1, 2))
|
||||||
|
fun bar() {}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
foo()
|
||||||
|
bar()
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package kotlin
|
||||||
|
|
||||||
|
public fun intArrayOf(vararg elements: Int): FloatArray = TODO()
|
||||||
@@ -120,6 +120,12 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("overloadResolutionOnCollectionLiteral")
|
||||||
|
public void testOverloadResolutionOnCollectionLiteral() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/overloadResolutionOnCollectionLiteral/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("stdlibForJavacWithNoKotlin")
|
@TestMetadata("stdlibForJavacWithNoKotlin")
|
||||||
public void testStdlibForJavacWithNoKotlin() throws Exception {
|
public void testStdlibForJavacWithNoKotlin() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/stdlibForJavacWithNoKotlin/");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/stdlibForJavacWithNoKotlin/");
|
||||||
@@ -132,6 +138,12 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("twoStdlibForCollectionLiterals")
|
||||||
|
public void testTwoStdlibForCollectionLiterals() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/twoStdlibForCollectionLiterals/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("valWithInvoke")
|
@TestMetadata("valWithInvoke")
|
||||||
public void testValWithInvoke() throws Exception {
|
public void testValWithInvoke() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/valWithInvoke/");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/valWithInvoke/");
|
||||||
@@ -161,4 +173,10 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/withKotlinNoJavaSources/");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/withKotlinNoJavaSources/");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("wrongCallForCollectionLiteral")
|
||||||
|
public void testWrongCallForCollectionLiteral() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/wrongCallForCollectionLiteral/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user