Type aliases.
This commit is contained in:
committed by
Dmitry Petrov
parent
1b5dd50359
commit
264c8afc78
+5
-7
@@ -135,7 +135,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
|||||||
getterDescriptor, getterBody)
|
getterDescriptor, getterBody)
|
||||||
|
|
||||||
if (propertyDescriptor.isVar) {
|
if (propertyDescriptor.isVar) {
|
||||||
val setterDescriptor = propertyDescriptor.setter ?: throw AssertionError("Delegated property should have setter: $propertyDescriptor")
|
val setterDescriptor = propertyDescriptor.setter ?: throw AssertionError("Delegated var should have setter: $propertyDescriptor")
|
||||||
val setterBody = createBodyGenerator(setterDescriptor).generateDelegatedPropertySetter(ktDelegate, delegateDescriptor, setterDescriptor)
|
val setterBody = createBodyGenerator(setterDescriptor).generateDelegatedPropertySetter(ktDelegate, delegateDescriptor, setterDescriptor)
|
||||||
irProperty.setter = IrPropertySetterImpl(ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
|
irProperty.setter = IrPropertySetterImpl(ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
|
||||||
setterDescriptor, setterBody)
|
setterDescriptor, setterBody)
|
||||||
@@ -153,18 +153,16 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
|||||||
val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktGetter)
|
val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktGetter)
|
||||||
val getterDescriptor = accessorDescriptor as? PropertyGetterDescriptor ?: TODO("not a getter?")
|
val getterDescriptor = accessorDescriptor as? PropertyGetterDescriptor ?: TODO("not a getter?")
|
||||||
val irGetterBody = generateFunctionBody(getterDescriptor, ktGetter.bodyExpression ?: TODO("default getter"))
|
val irGetterBody = generateFunctionBody(getterDescriptor, ktGetter.bodyExpression ?: TODO("default getter"))
|
||||||
val irGetter = IrPropertyGetterImpl(ktGetter.startOffset, ktGetter.endOffset, IrDeclarationOrigin.DEFINED,
|
IrPropertyGetterImpl(ktGetter.startOffset, ktGetter.endOffset, IrDeclarationOrigin.DEFINED,
|
||||||
getterDescriptor, irGetterBody)
|
getterDescriptor, irGetterBody)
|
||||||
irGetter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
irProperty.setter = ktProperty.setter?.let { ktSetter ->
|
irProperty.setter = ktProperty.setter?.let { ktSetter ->
|
||||||
val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktSetter)
|
val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktSetter)
|
||||||
val setterDescriptor = accessorDescriptor as? PropertySetterDescriptor ?: TODO("not a setter?")
|
val setterDescriptor = accessorDescriptor as? PropertySetterDescriptor ?: TODO("not a setter?")
|
||||||
val irSetterBody = generateFunctionBody(setterDescriptor, ktSetter.bodyExpression ?: TODO("default setter"))
|
val irSetterBody = generateFunctionBody(setterDescriptor, ktSetter.bodyExpression ?: TODO("default setter"))
|
||||||
val irSetter = IrPropertySetterImpl(ktSetter.startOffset, ktSetter.endOffset, IrDeclarationOrigin.DEFINED,
|
IrPropertySetterImpl(ktSetter.startOffset, ktSetter.endOffset, IrDeclarationOrigin.DEFINED,
|
||||||
setterDescriptor, irSetterBody)
|
setterDescriptor, irSetterBody)
|
||||||
irSetter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return irProperty
|
return irProperty
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ fun Generator.getInferredTypeWithImplicitCasts(key: KtExpression): KotlinType? =
|
|||||||
context.bindingContext.getType(key)
|
context.bindingContext.getType(key)
|
||||||
|
|
||||||
fun Generator.getInferredTypeWithImplicitCastsOrFail(key: KtExpression): KotlinType =
|
fun Generator.getInferredTypeWithImplicitCastsOrFail(key: KtExpression): KotlinType =
|
||||||
getInferredTypeWithImplicitCasts(key) ?: throw AssertionError("No type for expression: ${key.text}")
|
getInferredTypeWithImplicitCasts(key) ?: throw RuntimeException("No type for expression: ${key.text}")
|
||||||
|
|
||||||
fun Generator.getResolvedCall(key: KtElement): ResolvedCall<out CallableDescriptor>? =
|
fun Generator.getResolvedCall(key: KtElement): ResolvedCall<out CallableDescriptor>? =
|
||||||
key.getResolvedCall(context.bindingContext)
|
key.getResolvedCall(context.bindingContext)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.assertCast
|
import org.jetbrains.kotlin.ir.assertCast
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrTypeAliasImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrVariableImpl
|
import org.jetbrains.kotlin.ir.declarations.IrVariableImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -345,6 +346,10 @@ class StatementGenerator(
|
|||||||
|
|
||||||
override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Nothing?): IrStatement =
|
override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Nothing?): IrStatement =
|
||||||
LocalClassGenerator(this).generateLocalClass(classOrObject)
|
LocalClassGenerator(this).generateLocalClass(classOrObject)
|
||||||
|
|
||||||
|
override fun visitTypeAlias(typeAlias: KtTypeAlias, data: Nothing?): IrStatement =
|
||||||
|
IrTypeAliasImpl(typeAlias.startOffset, typeAlias.endOffset, IrDeclarationOrigin.DEFINED,
|
||||||
|
getOrFail(BindingContext.TYPE_ALIAS, typeAlias))
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class StatementGeneratorExtension(val statementGenerator: StatementGenerator) : GeneratorWithScope {
|
abstract class StatementGeneratorExtension(val statementGenerator: StatementGenerator) : GeneratorWithScope {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
typealias Test1 = String
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
typealias TestLocal = String
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
typealias TestNested = String
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
FILE /typeAlias.kt
|
||||||
|
TYPEALIAS Test1 type=kotlin.String
|
||||||
|
FUN public fun foo(): kotlin.Unit
|
||||||
|
BLOCK_BODY
|
||||||
|
TYPEALIAS TestLocal type=kotlin.String
|
||||||
|
CLASS CLASS C
|
||||||
|
CONSTRUCTOR public constructor C()
|
||||||
|
BLOCK_BODY
|
||||||
|
INSTANCE_INITIALIZER_CALL classDescriptor=C
|
||||||
|
TYPEALIAS TestNested type=kotlin.String
|
||||||
@@ -171,6 +171,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/delegatedProperties.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/delegatedProperties.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeAlias.kt")
|
||||||
|
public void testTypeAlias() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/typeAlias.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/ir/irText/expressions")
|
@TestMetadata("compiler/testData/ir/irText/expressions")
|
||||||
|
|||||||
Reference in New Issue
Block a user