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");