Fixed exception AssertionError: Illegal resolved call to variable with invoke

#KT-13330 Fixed
#KT-13349 Fixed
This commit is contained in:
Stanislav Erokhin
2016-08-03 17:11:40 +03:00
parent 926deebff5
commit 85a951db52
6 changed files with 49 additions and 2 deletions
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry
import org.jetbrains.kotlin.psi.KtOperationReferenceExpression
@@ -42,9 +43,10 @@ class OperatorCallChecker : CallChecker {
if (resolvedCall is VariableAsFunctionResolvedCall &&
call is CallTransformer.CallForImplicitInvoke && call.itIsVariableAsFunctionCall) {
val outerCall = call.outerCall
if (isConventionCall(outerCall) || outerCall.typeArguments.isNotEmpty()) {
if (isConventionCall(outerCall) || isWrongCallWithExplicitTypeArguments(resolvedCall, outerCall)) {
throw AssertionError("Illegal resolved call to variable with invoke for $outerCall. " +
"Variable: ${resolvedCall.variableCall.resultingDescriptor}")
"Variable: ${resolvedCall.variableCall.resultingDescriptor}" +
"Invoke: ${resolvedCall.functionCall.resultingDescriptor}")
}
}
@@ -75,5 +77,14 @@ class OperatorCallChecker : CallChecker {
private fun checkNotErrorOrDynamic(functionDescriptor: FunctionDescriptor): Boolean {
return !functionDescriptor.isDynamic() && !ErrorUtils.isError(functionDescriptor)
}
private fun isWrongCallWithExplicitTypeArguments(
resolvedCall: VariableAsFunctionResolvedCall,
outerCall: Call
): Boolean {
val passedTypeArgumentsToInvoke = outerCall.typeArguments.isNotEmpty() &&
resolvedCall.functionCall.candidateDescriptor.typeParameters.isNotEmpty()
return passedTypeArgumentsToInvoke && resolvedCall.variableCall.candidateDescriptor.typeParameters.isNotEmpty()
}
}
}
@@ -0,0 +1,3 @@
//KT-13330 AssertionError: Illegal resolved call to variable with invoke
fun foo(exec: (String.() -> Unit)?) = "".<!UNSAFE_IMPLICIT_INVOKE_CALL!>exec<!><!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><<!UNRESOLVED_REFERENCE!>caret<!>><!>() // <caret> is test data tag here
@@ -0,0 +1,3 @@
package
public fun foo(/*0*/ exec: (kotlin.String.() -> kotlin.Unit)?): kotlin.Unit
@@ -0,0 +1,7 @@
object Foo {
operator fun <T> invoke() {}
}
fun main(args: Array<String>) {
Foo<Int>()
}
@@ -0,0 +1,11 @@
package
public fun main(/*0*/ args: kotlin.Array<kotlin.String>): kotlin.Unit
public object Foo {
private constructor Foo()
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 final operator fun </*0*/ T> invoke(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -12567,6 +12567,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt13330.kt")
public void testKt13330() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/kt13330.kt");
doTest(fileName);
}
@TestMetadata("kt13349.kt")
public void testKt13349() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/kt13349.kt");
doTest(fileName);
}
@TestMetadata("kt3450.kt")
public void testKt3450() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/operatorsOverloading/kt3450.kt");