FIR: set constructor parameter scope correctly for designated transformer

This commit is contained in:
Mikhail Glukhikh
2019-07-11 20:20:18 +03:00
parent b8c3947827
commit 2d74dac4f2
5 changed files with 25 additions and 6 deletions
@@ -74,11 +74,6 @@ open class FirBodyResolveTransformer(
private var primaryConstructorParametersScope: FirLocalScope? = null
override fun transformConstructor(constructor: FirConstructor, data: Any?): CompositeTransformResult<FirDeclaration> {
if (constructor.isPrimary) {
primaryConstructorParametersScope = FirLocalScope().apply {
constructor.valueParameters.forEach { this.storeDeclaration(it) }
}
}
if (implicitTypeOnly) return constructor.compose()
return super.transformConstructor(constructor, data)
}
@@ -131,6 +126,12 @@ open class FirBodyResolveTransformer(
scopes.addIfNotNull(symbolProvider.getClassUseSiteMemberScope(companionObject.classId, session, scopeSession))
}
val result = withLabelAndReceiverType(regularClass.name, regularClass, type) {
val constructor = regularClass.declarations.firstOrNull() as? FirConstructor
if (constructor?.isPrimary == true) {
primaryConstructorParametersScope = FirLocalScope().apply {
constructor.valueParameters.forEach { this.storeDeclaration(it) }
}
}
super.transformRegularClass(regularClass, data)
}
primaryConstructorParametersScope = oldConstructorScope
@@ -0,0 +1,3 @@
class Bar(name: () -> String) {
val name = name()
}
@@ -0,0 +1,10 @@
FILE: propertyFromParameter.kt
public final class Bar : R|kotlin/Any| {
public constructor(name: R|kotlin/Function0<kotlin/String>|): R|Bar| {
super<R|kotlin/Any|>()
}
public final val name: <ERROR TYPE REF: cycle> = R|<local>/name|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/String|>|()
public get(): <ERROR TYPE REF: cycle>
}
@@ -372,6 +372,11 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/implicitTypeOrder.kt");
}
@TestMetadata("propertyFromParameter.kt")
public void testPropertyFromParameter() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/propertyFromParameter.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/expresssions/invoke/simple.kt");
@@ -83,7 +83,7 @@ FILE fqName:<root> fileName:/multipleThisReferences.kt
FIELD PROPERTY_BACKING_FIELD name:xx type:kotlin.String visibility:public [final]
EXPRESSION_BODY
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin' type=kotlin.String origin=null
other: CALL 'public final fun <get-y> (): kotlin.Int declared in <root>.Host' type=kotlin.Int origin=null
other: GET_VAR 'y: kotlin.Int declared in <root>.Host.<init>' type=kotlin.Int origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-xx> visibility:public modality:FINAL <> ($this:<root>.Host.test.<no name provided>) returnType:kotlin.String
correspondingProperty: PROPERTY name:xx visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Host.test.<no name provided>