psi2ir: support dynamic infix calls ('foo bar 42' is 'foo.bar(42)')
This commit is contained in:
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
|||||||
|
|
||||||
internal fun ResolvedCall<*>.isImplicitInvoke(): Boolean {
|
internal fun ResolvedCall<*>.isImplicitInvoke(): Boolean {
|
||||||
if (resultingDescriptor.name != OperatorNameConventions.INVOKE) return false
|
if (resultingDescriptor.name != OperatorNameConventions.INVOKE) return false
|
||||||
val callExpression = call.callElement as? KtCallExpression ?: return true
|
val callExpression = call.callElement as? KtCallExpression ?: return false
|
||||||
val calleeExpression = callExpression.calleeExpression as? KtSimpleNameExpression ?: return true
|
val calleeExpression = callExpression.calleeExpression as? KtSimpleNameExpression ?: return true
|
||||||
return calleeExpression.getReferencedName() != OperatorNameConventions.INVOKE.asString()
|
return calleeExpression.getReferencedName() != OperatorNameConventions.INVOKE.asString()
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-6
@@ -177,14 +177,17 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
|||||||
|
|
||||||
val kotlinType = context.bindingContext.getType(ktExpression) ?: throw AssertionError("No type for ${ktExpression.text}")
|
val kotlinType = context.bindingContext.getType(ktExpression) ?: throw AssertionError("No type for ${ktExpression.text}")
|
||||||
|
|
||||||
|
val startOffset = ktExpression.startOffsetSkippingComments
|
||||||
|
val endOffset = ktExpression.endOffset
|
||||||
|
val irType = kotlinType.toIrType()
|
||||||
|
|
||||||
|
if (ktExpression.operationToken == KtTokens.IDENTIFIER) {
|
||||||
|
return generateCall(getResolvedCall(ktExpression)!!, ktExpression, null)
|
||||||
|
}
|
||||||
|
|
||||||
val operator = ktExpression.getDynamicOperator()
|
val operator = ktExpression.getDynamicOperator()
|
||||||
|
|
||||||
return IrDynamicOperatorExpressionImpl(
|
return IrDynamicOperatorExpressionImpl(startOffset, endOffset, irType, operator).apply {
|
||||||
ktExpression.startOffsetSkippingComments,
|
|
||||||
ktExpression.endOffset,
|
|
||||||
kotlinType.toIrType(),
|
|
||||||
operator
|
|
||||||
).apply {
|
|
||||||
left = ktLeft.genExpr()
|
left = ktLeft.genExpr()
|
||||||
right = ktRight.genExpr()
|
right = ktRight.genExpr()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||||
// NO_CHECK_LAMBDA_INLINING
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
// FILE: 1.kt
|
// FILE: 1.kt
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun test1(d: dynamic) = d foo 123
|
||||||
|
|
||||||
|
fun test2(d: dynamic) = d invoke 123
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
FILE fqName:<root> fileName:/dynamicInfixCall.kt
|
||||||
|
FUN name:test1 visibility:public modality:FINAL <> (d:dynamic) returnType:dynamic flags:
|
||||||
|
VALUE_PARAMETER name:d index:0 type:dynamic flags:
|
||||||
|
BLOCK_BODY
|
||||||
|
RETURN type=kotlin.Nothing from='test1(dynamic): dynamic'
|
||||||
|
DYN_OP operator=INVOKE type=dynamic
|
||||||
|
receiver: DYN_MEMBER memberName='foo' type=dynamic
|
||||||
|
GET_VAR 'value-parameter d: dynamic' type=dynamic origin=null
|
||||||
|
0: CONST Int type=kotlin.Int value=123
|
||||||
|
FUN name:test2 visibility:public modality:FINAL <> (d:dynamic) returnType:dynamic flags:
|
||||||
|
VALUE_PARAMETER name:d index:0 type:dynamic flags:
|
||||||
|
BLOCK_BODY
|
||||||
|
RETURN type=kotlin.Nothing from='test2(dynamic): dynamic'
|
||||||
|
DYN_OP operator=INVOKE type=dynamic
|
||||||
|
receiver: DYN_MEMBER memberName='invoke' type=dynamic
|
||||||
|
GET_VAR 'value-parameter d: dynamic' type=dynamic origin=null
|
||||||
|
0: CONST Int type=kotlin.Int value=123
|
||||||
@@ -101,6 +101,11 @@ public class IrJsTextTestCaseGenerated extends AbstractIrJsTextTestCase {
|
|||||||
runTest("compiler/testData/ir/irJsText/dynamic/dynamicExclExclOperator.kt");
|
runTest("compiler/testData/ir/irJsText/dynamic/dynamicExclExclOperator.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dynamicInfixCall.kt")
|
||||||
|
public void testDynamicInfixCall() throws Exception {
|
||||||
|
runTest("compiler/testData/ir/irJsText/dynamic/dynamicInfixCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("dynamicMemberAccess.kt")
|
@TestMetadata("dynamicMemberAccess.kt")
|
||||||
public void testDynamicMemberAccess() throws Exception {
|
public void testDynamicMemberAccess() throws Exception {
|
||||||
runTest("compiler/testData/ir/irJsText/dynamic/dynamicMemberAccess.kt");
|
runTest("compiler/testData/ir/irJsText/dynamic/dynamicMemberAccess.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user