Type aliases.

This commit is contained in:
Dmitry Petrov
2016-09-01 18:46:58 +03:00
committed by Dmitry Petrov
parent 1b5dd50359
commit 264c8afc78
6 changed files with 36 additions and 8 deletions
@@ -135,7 +135,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
getterDescriptor, getterBody)
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)
irProperty.setter = IrPropertySetterImpl(ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR,
setterDescriptor, setterBody)
@@ -153,18 +153,16 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktGetter)
val getterDescriptor = accessorDescriptor as? PropertyGetterDescriptor ?: TODO("not a getter?")
val irGetterBody = generateFunctionBody(getterDescriptor, ktGetter.bodyExpression ?: TODO("default getter"))
val irGetter = IrPropertyGetterImpl(ktGetter.startOffset, ktGetter.endOffset, IrDeclarationOrigin.DEFINED,
getterDescriptor, irGetterBody)
irGetter
IrPropertyGetterImpl(ktGetter.startOffset, ktGetter.endOffset, IrDeclarationOrigin.DEFINED,
getterDescriptor, irGetterBody)
}
irProperty.setter = ktProperty.setter?.let { ktSetter ->
val accessorDescriptor = getOrFail(BindingContext.PROPERTY_ACCESSOR, ktSetter)
val setterDescriptor = accessorDescriptor as? PropertySetterDescriptor ?: TODO("not a setter?")
val irSetterBody = generateFunctionBody(setterDescriptor, ktSetter.bodyExpression ?: TODO("default setter"))
val irSetter = IrPropertySetterImpl(ktSetter.startOffset, ktSetter.endOffset, IrDeclarationOrigin.DEFINED,
setterDescriptor, irSetterBody)
irSetter
IrPropertySetterImpl(ktSetter.startOffset, ktSetter.endOffset, IrDeclarationOrigin.DEFINED,
setterDescriptor, irSetterBody)
}
return irProperty
@@ -52,7 +52,7 @@ fun Generator.getInferredTypeWithImplicitCasts(key: KtExpression): KotlinType? =
context.bindingContext.getType(key)
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>? =
key.getResolvedCall(context.bindingContext)
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.assertCast
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.expressions.*
import org.jetbrains.kotlin.psi.*
@@ -345,6 +346,10 @@ class StatementGenerator(
override fun visitClassOrObject(classOrObject: KtClassOrObject, data: Nothing?): IrStatement =
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 {
+9
View File
@@ -0,0 +1,9 @@
typealias Test1 = String
fun foo() {
typealias TestLocal = String
}
class C {
typealias TestNested = String
}
+10
View File
@@ -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");
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")