Update to origin/master.
IrReturn should return 'Unit' for "return without value".
This commit is contained in:
+2
-2
@@ -31,7 +31,7 @@ class FileClassDescriptorImpl(
|
|||||||
private val sourceElement: SourceElement
|
private val sourceElement: SourceElement
|
||||||
) : FileClassDescriptor {
|
) : FileClassDescriptor {
|
||||||
override fun getCompanionObjectDescriptor(): ClassDescriptor? = null
|
override fun getCompanionObjectDescriptor(): ClassDescriptor? = null
|
||||||
override fun getConstructors(): Collection<ConstructorDescriptor> = emptyList()
|
override fun getConstructors(): Collection<ClassConstructorDescriptor> = emptyList()
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclarationImpl
|
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclarationImpl
|
||||||
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> = emptyList()
|
override fun getDeclaredTypeParameters(): List<TypeParameterDescriptor> = emptyList()
|
||||||
override fun getDefaultType(): SimpleType = ErrorUtils.createErrorType("File class type for $nameImpl")
|
override fun getDefaultType(): SimpleType = ErrorUtils.createErrorType("File class type for $nameImpl")
|
||||||
@@ -45,7 +45,7 @@ class FileClassDescriptorImpl(
|
|||||||
override fun getThisAsReceiverParameter(): ReceiverParameterDescriptor = error("File class has no instances")
|
override fun getThisAsReceiverParameter(): ReceiverParameterDescriptor = error("File class has no instances")
|
||||||
override fun getUnsubstitutedInnerClassesScope(): MemberScope = error("File class has no inner classes scope")
|
override fun getUnsubstitutedInnerClassesScope(): MemberScope = error("File class has no inner classes scope")
|
||||||
override fun getUnsubstitutedMemberScope(): MemberScope = error("File class has no member scope")
|
override fun getUnsubstitutedMemberScope(): MemberScope = error("File class has no member scope")
|
||||||
override fun getUnsubstitutedPrimaryConstructor(): ConstructorDescriptor? = null
|
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = null
|
||||||
override fun getVisibility(): Visibility = Visibilities.PUBLIC
|
override fun getVisibility(): Visibility = Visibilities.PUBLIC
|
||||||
override fun isCompanionObject(): Boolean = false
|
override fun isCompanionObject(): Boolean = false
|
||||||
override fun isData(): Boolean = false
|
override fun isData(): Boolean = false
|
||||||
|
|||||||
+1
-1
@@ -163,7 +163,7 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen
|
|||||||
private fun getThisClass(): ClassDescriptor {
|
private fun getThisClass(): ClassDescriptor {
|
||||||
val scopeOwner = statementGenerator.scopeOwner
|
val scopeOwner = statementGenerator.scopeOwner
|
||||||
return when (scopeOwner) {
|
return when (scopeOwner) {
|
||||||
is ConstructorDescriptor -> scopeOwner.containingDeclaration
|
is ClassConstructorDescriptor -> scopeOwner.containingDeclaration
|
||||||
is ClassDescriptor -> scopeOwner
|
is ClassDescriptor -> scopeOwner
|
||||||
else -> scopeOwner.containingDeclaration as ClassDescriptor
|
else -> scopeOwner.containingDeclaration as ClassDescriptor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,9 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
|
|||||||
statementGenerator.generateReturnExpression(ktReturnedValue, irBlockBody)
|
statementGenerator.generateReturnExpression(ktReturnedValue, irBlockBody)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
irBlockBody.statements.add(generateReturnExpression(ktBody.startOffset, ktBody.endOffset, null))
|
irBlockBody.statements.add(generateReturnExpression(
|
||||||
|
ktBody.startOffset, ktBody.endOffset,
|
||||||
|
IrGetObjectValueImpl(ktBody.startOffset, ktBody.endOffset, context.builtIns.unitType, context.builtIns.unit)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +112,7 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
|
|||||||
generateReturnExpression(startOffset, endOffset, this)
|
generateReturnExpression(startOffset, endOffset, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateReturnExpression(startOffset: Int, endOffset: Int, returnValue: IrExpression?): IrReturnImpl {
|
private fun generateReturnExpression(startOffset: Int, endOffset: Int, returnValue: IrExpression): IrReturnImpl {
|
||||||
val returnTarget = (scopeOwner as? CallableDescriptor) ?:
|
val returnTarget = (scopeOwner as? CallableDescriptor) ?:
|
||||||
throw AssertionError("'return' in a non-callable: $scopeOwner")
|
throw AssertionError("'return' in a non-callable: $scopeOwner")
|
||||||
return IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, returnTarget, returnValue)
|
return IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, returnTarget, returnValue)
|
||||||
@@ -130,7 +132,7 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDelegatingConstructorCall(irBlockBody: IrBlockBodyImpl, ktConstructor: KtSecondaryConstructor) {
|
private fun generateDelegatingConstructorCall(irBlockBody: IrBlockBodyImpl, ktConstructor: KtSecondaryConstructor) {
|
||||||
val constructorDescriptor = scopeOwner as ConstructorDescriptor
|
val constructorDescriptor = scopeOwner as ClassConstructorDescriptor
|
||||||
|
|
||||||
val statementGenerator = createStatementGenerator()
|
val statementGenerator = createStatementGenerator()
|
||||||
val ktDelegatingConstructorCall = ktConstructor.getDelegationCall()
|
val ktDelegatingConstructorCall = ktConstructor.getDelegationCall()
|
||||||
@@ -167,7 +169,7 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
|
|||||||
|
|
||||||
generateSuperConstructorCall(irBlockBody, ktClassOrObject)
|
generateSuperConstructorCall(irBlockBody, ktClassOrObject)
|
||||||
|
|
||||||
val classDescriptor = (scopeOwner as ConstructorDescriptor).containingDeclaration
|
val classDescriptor = (scopeOwner as ClassConstructorDescriptor).containingDeclaration
|
||||||
irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktClassOrObject.startOffset, ktClassOrObject.endOffset, classDescriptor))
|
irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktClassOrObject.startOffset, ktClassOrObject.endOffset, classDescriptor))
|
||||||
|
|
||||||
return irBlockBody
|
return irBlockBody
|
||||||
@@ -178,7 +180,7 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
|
|||||||
|
|
||||||
generateDelegatingConstructorCall(irBlockBody, ktConstructor)
|
generateDelegatingConstructorCall(irBlockBody, ktConstructor)
|
||||||
|
|
||||||
val classDescriptor = getOrFail(BindingContext.CONSTRUCTOR, ktConstructor).containingDeclaration
|
val classDescriptor = getOrFail(BindingContext.CONSTRUCTOR, ktConstructor).containingDeclaration as ClassDescriptor
|
||||||
irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktConstructor.startOffset, ktConstructor.endOffset, classDescriptor))
|
irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktConstructor.startOffset, ktConstructor.endOffset, classDescriptor))
|
||||||
|
|
||||||
ktConstructor.bodyExpression?.let { ktBody ->
|
ktConstructor.bodyExpression?.let { ktBody ->
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE
|
|||||||
fun generateEnumConstructorSuperCall(startOffset: Int, endOffset: Int, call: CallBuilder,
|
fun generateEnumConstructorSuperCall(startOffset: Int, endOffset: Int, call: CallBuilder,
|
||||||
enumEntryDescriptor: ClassDescriptor?) : IrExpression {
|
enumEntryDescriptor: ClassDescriptor?) : IrExpression {
|
||||||
val constructorDescriptor = call.descriptor
|
val constructorDescriptor = call.descriptor
|
||||||
if (constructorDescriptor !is ConstructorDescriptor) throw AssertionError("Constructor expected: $constructorDescriptor")
|
if (constructorDescriptor !is ClassConstructorDescriptor) throw AssertionError("Constructor expected: $constructorDescriptor")
|
||||||
val classDescriptor = constructorDescriptor.containingDeclaration
|
val classDescriptor = constructorDescriptor.containingDeclaration
|
||||||
if (classDescriptor.kind != ClassKind.ENUM_CLASS) throw AssertionError("Enum class constructor expected: $classDescriptor")
|
if (classDescriptor.kind != ClassKind.ENUM_CLASS) throw AssertionError("Enum class constructor expected: $classDescriptor")
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -136,7 +136,8 @@ class StatementGenerator(
|
|||||||
|
|
||||||
override fun visitReturnExpression(expression: KtReturnExpression, data: Nothing?): IrStatement {
|
override fun visitReturnExpression(expression: KtReturnExpression, data: Nothing?): IrStatement {
|
||||||
val returnTarget = getReturnExpressionTarget(expression)
|
val returnTarget = getReturnExpressionTarget(expression)
|
||||||
val irReturnedExpression = expression.returnedExpression?.genExpr()
|
val irReturnedExpression = expression.returnedExpression?.genExpr() ?:
|
||||||
|
IrGetObjectValueImpl(expression.startOffset, expression.endOffset, context.builtIns.unitType, context.builtIns.unit)
|
||||||
return IrReturnImpl(expression.startOffset, expression.endOffset, context.builtIns.nothingType, returnTarget, irReturnedExpression)
|
return IrReturnImpl(expression.startOffset, expression.endOffset, context.builtIns.nothingType, returnTarget, irReturnedExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|||||||
|
|
||||||
|
|
||||||
interface IrReturn : IrExpression {
|
interface IrReturn : IrExpression {
|
||||||
var value: IrExpression?
|
var value: IrExpression
|
||||||
val returnTarget: CallableDescriptor
|
val returnTarget: CallableDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,28 +27,17 @@ class IrReturnImpl(
|
|||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
type: KotlinType,
|
type: KotlinType,
|
||||||
override val returnTarget: CallableDescriptor
|
override val returnTarget: CallableDescriptor,
|
||||||
|
override var value: IrExpression
|
||||||
) : IrExpressionBase(startOffset, endOffset, type), IrReturn {
|
) : IrExpressionBase(startOffset, endOffset, type), IrReturn {
|
||||||
constructor(
|
|
||||||
startOffset: Int,
|
|
||||||
endOffset: Int,
|
|
||||||
type: KotlinType,
|
|
||||||
returnTarget: CallableDescriptor,
|
|
||||||
value: IrExpression?
|
|
||||||
) : this(startOffset, endOffset, type, returnTarget) {
|
|
||||||
this.value = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override var value: IrExpression? = null
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitReturn(this, data)
|
visitor.visitReturn(this, data)
|
||||||
|
|
||||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
value?.accept(visitor, data)
|
value.accept(visitor, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
value = value?.transform(transformer, data)
|
value = value.transform(transformer, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@ FILE /smartCasts.kt
|
|||||||
if: TYPE_OP origin=NOT_INSTANCEOF typeOperand=kotlin.String
|
if: TYPE_OP origin=NOT_INSTANCEOF typeOperand=kotlin.String
|
||||||
GET_VAR 'value-parameter x: Any' type=kotlin.Any origin=null
|
GET_VAR 'value-parameter x: Any' type=kotlin.Any origin=null
|
||||||
then: RETURN type=kotlin.Nothing from='test1(Any): Unit'
|
then: RETURN type=kotlin.Nothing from='test1(Any): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
CALL 'println(Int): Unit' type=kotlin.Unit origin=null
|
CALL 'println(Int): Unit' type=kotlin.Unit origin=null
|
||||||
message: CALL '<get-length>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
message: CALL '<get-length>(): Int' type=kotlin.Int origin=GET_PROPERTY
|
||||||
$this: TYPE_OP origin=IMPLICIT_CAST typeOperand=kotlin.String
|
$this: TYPE_OP origin=IMPLICIT_CAST typeOperand=kotlin.String
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ FILE /smartCastsWithDestructuring.kt
|
|||||||
if: TYPE_OP origin=NOT_INSTANCEOF typeOperand=I2
|
if: TYPE_OP origin=NOT_INSTANCEOF typeOperand=I2
|
||||||
GET_VAR 'value-parameter x: I1' type=I1 origin=null
|
GET_VAR 'value-parameter x: I1' type=I1 origin=null
|
||||||
then: RETURN type=kotlin.Nothing from='test(I1): Unit'
|
then: RETURN type=kotlin.Nothing from='test(I1): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
COMPOSITE type=kotlin.Unit origin=DESTRUCTURING_DECLARATION
|
COMPOSITE type=kotlin.Unit origin=DESTRUCTURING_DECLARATION
|
||||||
VAR IR_TEMPORARY_VARIABLE val tmp0_container: I1
|
VAR IR_TEMPORARY_VARIABLE val tmp0_container: I1
|
||||||
GET_VAR 'value-parameter x: I1' type=I1 origin=null
|
GET_VAR 'value-parameter x: I1' type=I1 origin=null
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ FILE /tryCatchWithImplicitCast.kt
|
|||||||
if: TYPE_OP origin=NOT_INSTANCEOF typeOperand=kotlin.String
|
if: TYPE_OP origin=NOT_INSTANCEOF typeOperand=kotlin.String
|
||||||
GET_VAR 'value-parameter a: Any' type=kotlin.Any origin=null
|
GET_VAR 'value-parameter a: Any' type=kotlin.Any origin=null
|
||||||
then: RETURN type=kotlin.Nothing from='testImplicitCast(Any): Unit'
|
then: RETURN type=kotlin.Nothing from='testImplicitCast(Any): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
VAR val t: kotlin.String
|
VAR val t: kotlin.String
|
||||||
TRY type=kotlin.String
|
TRY type=kotlin.String
|
||||||
try: BLOCK type=kotlin.String origin=null
|
try: BLOCK type=kotlin.String origin=null
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ FILE /justLambda.kt
|
|||||||
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Unit
|
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='<anonymous>(): Unit'
|
RETURN type=kotlin.Nothing from='<anonymous>(): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
CALLABLE_REFERENCE '<anonymous>(): Unit' type=() -> kotlin.Unit origin=LAMBDA
|
CALLABLE_REFERENCE '<anonymous>(): Unit' type=() -> kotlin.Unit origin=LAMBDA
|
||||||
FUN DEFAULT_PROPERTY_ACCESSOR public fun <get-test2>(): () -> kotlin.Unit
|
FUN DEFAULT_PROPERTY_ACCESSOR public fun <get-test2>(): () -> kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ FILE /nonLocalReturn.kt
|
|||||||
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Nothing
|
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Nothing
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='test0(): Unit'
|
RETURN type=kotlin.Nothing from='test0(): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
CALLABLE_REFERENCE '<anonymous>(): Nothing' type=() -> kotlin.Nothing origin=LAMBDA
|
CALLABLE_REFERENCE '<anonymous>(): Nothing' type=() -> kotlin.Nothing origin=LAMBDA
|
||||||
FUN public fun test1(): kotlin.Unit
|
FUN public fun test1(): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
@@ -16,6 +17,7 @@ FILE /nonLocalReturn.kt
|
|||||||
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Unit
|
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='<anonymous>(): Unit'
|
RETURN type=kotlin.Nothing from='<anonymous>(): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
CALLABLE_REFERENCE '<anonymous>(): Unit' type=() -> kotlin.Unit origin=LAMBDA
|
CALLABLE_REFERENCE '<anonymous>(): Unit' type=() -> kotlin.Unit origin=LAMBDA
|
||||||
FUN public fun test2(): kotlin.Unit
|
FUN public fun test2(): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
@@ -25,6 +27,7 @@ FILE /nonLocalReturn.kt
|
|||||||
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Unit
|
FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun <anonymous>(): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
RETURN type=kotlin.Nothing from='<anonymous>(): Unit'
|
RETURN type=kotlin.Nothing from='<anonymous>(): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
CALLABLE_REFERENCE '<anonymous>(): Unit' type=() -> kotlin.Unit origin=LAMBDA
|
CALLABLE_REFERENCE '<anonymous>(): Unit' type=() -> kotlin.Unit origin=LAMBDA
|
||||||
FUN public fun testLrmFoo1(ints: kotlin.collections.List<kotlin.Int>): kotlin.Unit
|
FUN public fun testLrmFoo1(ints: kotlin.collections.List<kotlin.Int>): kotlin.Unit
|
||||||
BLOCK_BODY
|
BLOCK_BODY
|
||||||
@@ -40,6 +43,7 @@ FILE /nonLocalReturn.kt
|
|||||||
arg0: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
arg0: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
||||||
arg1: CONST Int type=kotlin.Int value='0'
|
arg1: CONST Int type=kotlin.Int value='0'
|
||||||
then: RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
then: RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
||||||
CALL 'print(Int): Unit' type=kotlin.Unit origin=null
|
CALL 'print(Int): Unit' type=kotlin.Unit origin=null
|
||||||
message: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
message: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
||||||
@@ -58,6 +62,7 @@ FILE /nonLocalReturn.kt
|
|||||||
arg0: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
arg0: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
||||||
arg1: CONST Int type=kotlin.Int value='0'
|
arg1: CONST Int type=kotlin.Int value='0'
|
||||||
then: RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
then: RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
||||||
|
GET_OBJECT 'Unit' type=kotlin.Unit
|
||||||
RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
RETURN type=kotlin.Nothing from='<anonymous>(Int): Unit'
|
||||||
CALL 'print(Int): Unit' type=kotlin.Unit origin=null
|
CALL 'print(Int): Unit' type=kotlin.Unit origin=null
|
||||||
message: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
message: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null
|
||||||
|
|||||||
Reference in New Issue
Block a user