From 4718ae418672a3e1927f29403fd4a8c916bc08ff Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 25 Sep 2019 15:35:12 +0300 Subject: [PATCH] FIR: don't perform argument check for callable references This fixes failing FIR2IR test --- .../kotlin/fir/resolve/calls/Arguments.kt | 5 ++-- .../expresssions/extensionPropertyInLambda.kt | 14 ++++++++++ .../extensionPropertyInLambda.txt | 27 +++++++++++++++++++ .../fir/FirResolveTestCaseGenerated.java | 5 ++++ .../genericPropertyReferenceType.fir.txt | 17 ++++++------ 5 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.kt create mode 100644 compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.txt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index 7e99306ebea..6c3de7c035c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -48,6 +48,9 @@ fun resolveArgumentExpression( isSafeCall, typeProvider ) + // TODO:! + is FirCallableReferenceAccess -> Unit + // NB: FirCallableReferenceAccess should be checked earlier is FirQualifiedAccessExpression -> resolvePlainExpressionArgument( csBuilder, argument, @@ -60,8 +63,6 @@ fun resolveArgumentExpression( // TODO:! is FirAnonymousFunction -> preprocessLambdaArgument(csBuilder, argument, expectedType, expectedTypeRef, acceptLambdaAtoms) // TODO:! - is FirCallableReferenceAccess -> Unit - // TODO:! //TODO: Collection literal is FirWrappedArgumentExpression -> resolveArgumentExpression( csBuilder, diff --git a/compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.kt b/compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.kt new file mode 100644 index 00000000000..198eb9cbab5 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.kt @@ -0,0 +1,14 @@ +class C(var x: T) + +var C.y + get() = x + set(v) { + x = v + } + +fun use(f: () -> String) {} + +fun test1() { + use { C("abc").y } + use(C("abc")::y) +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.txt b/compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.txt new file mode 100644 index 00000000000..eeb69f431ff --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.txt @@ -0,0 +1,27 @@ +FILE: extensionPropertyInLambda.kt + public final class C : R|kotlin/Any| { + public constructor(x: R|T|): R|C| { + super() + } + + public final var x: R|T| = R|/x| + public get(): R|T| + public set(value: R|T|): R|kotlin/Unit| + + } + public final var R|C|.y: R|T| + public get(): R|T| { + ^ this@R|/C|.R|/C.x| + } + public set(v: R|T|): R|kotlin/Unit| { + this@R|/C|.R|/C.x| = R|/v| + } + public final fun use(f: R|kotlin/Function0|): R|kotlin/Unit| { + } + public final fun test1(): R|kotlin/Unit| { + R|/use|( = use@fun (): R|kotlin/String| { + R|/C.C|(String(abc)).R|/y| + } + ) + R|/use|(R|/C.C|(String(abc))::R|/y|) + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java index 11c93a1224d..edc6f4879ae 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirResolveTestCaseGenerated.java @@ -292,6 +292,11 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase { runTest("compiler/fir/resolve/testData/resolve/expresssions/dispatchReceiver.kt"); } + @TestMetadata("extensionPropertyInLambda.kt") + public void testExtensionPropertyInLambda() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/expresssions/extensionPropertyInLambda.kt"); + } + @TestMetadata("genericPropertyAccess.kt") public void testGenericPropertyAccess() throws Exception { runTest("compiler/fir/resolve/testData/resolve/expresssions/genericPropertyAccess.kt"); diff --git a/compiler/testData/ir/irText/types/genericPropertyReferenceType.fir.txt b/compiler/testData/ir/irText/types/genericPropertyReferenceType.fir.txt index 25e5de0622c..53dd159e780 100644 --- a/compiler/testData/ir/irText/types/genericPropertyReferenceType.fir.txt +++ b/compiler/testData/ir/irText/types/genericPropertyReferenceType.fir.txt @@ -40,27 +40,28 @@ FILE fqName: fileName:/genericPropertyReferenceType.kt public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any PROPERTY name:y visibility:public modality:FINAL [var] - FUN name: visibility:public modality:FINAL <> () returnType:IrErrorType + FUN name: visibility:public modality:FINAL <> () returnType:T of correspondingProperty: PROPERTY name:y visibility:public modality:FINAL [var] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - FUN name: visibility:public modality:FINAL <> (v:IrErrorType) returnType:kotlin.Unit + RETURN type=kotlin.Nothing from='public final fun (): T of declared in ' + CALL 'public final fun (): T of declared in .C' type=T of origin=null + $this: GET_VAR ': .C declared in .C' type=.C<*> origin=null + FUN name: visibility:public modality:FINAL <> (v:T of ) returnType:kotlin.Unit correspondingProperty: PROPERTY name:y visibility:public modality:FINAL [var] - VALUE_PARAMETER name:v index:0 type:IrErrorType + VALUE_PARAMETER name:v index:0 type:T of BLOCK_BODY - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + ERROR_CALL 'Unresolved reference: R|/C.x|' type=IrErrorType FUN name:use visibility:public modality:FINAL <> (p:kotlin.reflect.KMutableProperty) returnType:kotlin.Unit VALUE_PARAMETER name:p index:0 type:kotlin.reflect.KMutableProperty BLOCK_BODY FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public final fun use (p: kotlin.reflect.KMutableProperty): kotlin.Unit declared in ' type=kotlin.Unit origin=null - p: PROPERTY_REFERENCE 'public final y: IrErrorType [var]' field=null getter='public final fun (): IrErrorType declared in ' setter='public final fun (v: IrErrorType): kotlin.Unit declared in ' type=IrErrorType origin=null + p: PROPERTY_REFERENCE 'public final y: T of [var]' field=null getter='public final fun (): T of declared in ' setter='public final fun (v: T of ): kotlin.Unit declared in ' type=T of origin=null FUN name:test2 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Any BLOCK_BODY TYPE_OP type=.C origin=CAST typeOperand=.C GET_VAR 'a: kotlin.Any declared in .test2' type=kotlin.Any origin=null CALL 'public final fun use (p: kotlin.reflect.KMutableProperty): kotlin.Unit declared in ' type=kotlin.Unit origin=null - p: PROPERTY_REFERENCE 'public final y: IrErrorType [var]' field=null getter='public final fun (): IrErrorType declared in ' setter='public final fun (v: IrErrorType): kotlin.Unit declared in ' type=IrErrorType origin=null + p: PROPERTY_REFERENCE 'public final y: T of [var]' field=null getter='public final fun (): T of declared in ' setter='public final fun (v: T of ): kotlin.Unit declared in ' type=T of origin=null