JVM_IR: Serialization: do not mess with return types of call expressions
If return type of IrConstructor is different from containing class, we will generate call to wrong <init> method, leading to VerifyError. If we do not specify the type of irNull, it, by default, will be Nothing?, when really we need Any?. This leads to CCE: cannot cast to Void at runtime.
This commit is contained in:
+4
-3
@@ -499,7 +499,8 @@ interface IrBuilderExtension {
|
|||||||
null, compilerContext.symbolTable.referenceConstructor(nullableSerializerClass.descriptor.constructors.toList().first()),
|
null, compilerContext.symbolTable.referenceConstructor(nullableSerializerClass.descriptor.constructors.toList().first()),
|
||||||
typeArguments = listOf(type.makeNotNullable().toIrType()),
|
typeArguments = listOf(type.makeNotNullable().toIrType()),
|
||||||
valueArguments = listOf(expression),
|
valueArguments = listOf(expression),
|
||||||
returnTypeHint = wrapIrTypeIntoKSerializerIrType(module, type.toIrType())
|
// Return type should not be different from declared class, otherwise, we will call wrong <init> method on runtime.
|
||||||
|
returnTypeHint = null
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
expression
|
expression
|
||||||
@@ -656,8 +657,8 @@ interface IrBuilderExtension {
|
|||||||
} else {
|
} else {
|
||||||
compilerContext.symbolTable.referenceConstructor(serializerClass.unsubstitutedPrimaryConstructor!!)
|
compilerContext.symbolTable.referenceConstructor(serializerClass.unsubstitutedPrimaryConstructor!!)
|
||||||
}
|
}
|
||||||
val returnType = wrapIrTypeIntoKSerializerIrType(module, thisIrType)
|
// Return type should not be different from declared class, otherwise, we will call wrong <init> method on runtime.
|
||||||
return irInvoke(null, ctor, typeArguments = typeArgs, valueArguments = args, returnTypeHint = returnType)
|
return irInvoke(null, ctor, typeArguments = typeArgs, valueArguments = args, returnTypeHint = null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -311,7 +311,7 @@ open class SerializerIrGenerator(val irClass: IrClass, final override val compil
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
return if (defaultPrimitive == null)
|
return if (defaultPrimitive == null)
|
||||||
irNull() to (compilerContext.builtIns.nullableAnyType)
|
irNull(compilerContext.irBuiltIns.anyNType) to (compilerContext.builtIns.nullableAnyType)
|
||||||
else
|
else
|
||||||
defaultPrimitive to kType
|
defaultPrimitive to kType
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user