KT-16669 Exception in PSI2IR on type alias constructor in supertypes list

This commit is contained in:
Dmitry Petrov
2017-03-06 16:46:22 +03:00
parent e4683a1e9f
commit 4ba8268a29
5 changed files with 55 additions and 5 deletions
@@ -154,7 +154,7 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
generateEnumSuperConstructorCall(irBlockBody, ktConstructor)
}
else {
generateAnySuperConstructorCAll(irBlockBody, ktConstructor)
generateAnySuperConstructorCall(irBlockBody, ktConstructor)
}
return
}
@@ -230,12 +230,12 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
// Thus, super class should be Any.
val superClass = classDescriptor.getSuperClassOrAny()
assert(KotlinBuiltIns.isAny(superClass)) { "$classDescriptor: Super class should be any: $superClass" }
generateAnySuperConstructorCAll(irBlockBody, ktClassOrObject)
generateAnySuperConstructorCall(irBlockBody, ktClassOrObject)
}
}
}
private fun generateAnySuperConstructorCAll(irBlockBody: IrBlockBodyImpl, ktElement: KtElement) {
private fun generateAnySuperConstructorCall(irBlockBody: IrBlockBodyImpl, ktElement: KtElement) {
val anyConstructor = context.builtIns.any.constructors.single()
irBlockBody.statements.add(IrDelegatingConstructorCallImpl(ktElement.startOffset, ktElement.endOffset, anyConstructor, null))
}
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
@@ -105,8 +106,13 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE
IrGetValueImpl(startOffset, endOffset, descriptor, origin)
fun generateDelegatingConstructorCall(startOffset: Int, endOffset: Int, call: CallBuilder) : IrExpression {
val descriptor = call.descriptor
if (descriptor !is ClassConstructorDescriptor) throw AssertionError("Class constructor expected: $descriptor")
val descriptor = call.descriptor.let { callDescriptor ->
when (callDescriptor) {
is ClassConstructorDescriptor -> callDescriptor
is TypeAliasConstructorDescriptor -> callDescriptor.underlyingConstructorDescriptor
else -> throw AssertionError("Unexpected constructor descriptor: $callDescriptor")
}
}
return call.callReceiver.call { dispatchReceiver, extensionReceiver ->
val irCall = IrDelegatingConstructorCallImpl(startOffset, endOffset, descriptor, getTypeArguments(call.original))
@@ -0,0 +1,7 @@
open class Cell<T>(val value: T)
typealias CT<T> = Cell<T>
typealias CStr = Cell<String>
class C1 : CT<String>("O")
class C2 : CStr("K")
@@ -0,0 +1,31 @@
FILE /delegatingConstructorCallToTypeAliasConstructor.kt
CLASS CLASS Cell
CONSTRUCTOR public constructor Cell<T>(value: T)
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'constructor Any()'
INSTANCE_INITIALIZER_CALL classDescriptor='Cell'
PROPERTY public final val value: T
FIELD PROPERTY_BACKING_FIELD public final val value: T
EXPRESSION_BODY
GET_VAR 'value-parameter value: T' type=T origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR public final fun <get-value>(): T
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-value>(): T'
GET_FIELD 'value: T' type=T origin=null
receiver: GET_VAR '<receiver: Cell>' type=Cell<T> origin=null
TYPEALIAS typealias CT = Cell<T> type=Cell<T>
TYPEALIAS typealias CStr = Cell<String> type=Cell<kotlin.String>
CLASS CLASS C1
CONSTRUCTOR public constructor C1()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'constructor Cell(T)'
value: TYPE_OP type=T origin=IMPLICIT_CAST typeOperand=T
CONST String type=kotlin.String value='O'
INSTANCE_INITIALIZER_CALL classDescriptor='C1'
CLASS CLASS C2
CONSTRUCTOR public constructor C2()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'constructor Cell(T)'
value: TYPE_OP type=T origin=IMPLICIT_CAST typeOperand=T
CONST String type=kotlin.String value='K'
INSTANCE_INITIALIZER_CALL classDescriptor='C2'
@@ -86,6 +86,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
doTest(fileName);
}
@TestMetadata("delegatingConstructorCallToTypeAliasConstructor.kt")
public void testDelegatingConstructorCallToTypeAliasConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.kt");
doTest(fileName);
}
@TestMetadata("delegatingConstructorCallsInSecondaryConstructors.kt")
public void testDelegatingConstructorCallsInSecondaryConstructors() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.kt");