KT-16618 IMPLICIT_INTEGER_COERCION isn't generated for global properties and default parameters
This commit is contained in:
+25
@@ -18,6 +18,9 @@ package org.jetbrains.kotlin.psi2ir.transformations
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
|
||||
@@ -122,6 +125,24 @@ class InsertImplicitCasts(val builtIns: KotlinBuiltIns): IrElementTransformerVoi
|
||||
return declaration
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField): IrStatement {
|
||||
declaration.transformChildrenVoid(this)
|
||||
|
||||
declaration.initializer?.coerce(declaration.descriptor.type)
|
||||
|
||||
return declaration
|
||||
}
|
||||
|
||||
override fun visitFunction(declaration: IrFunction): IrStatement {
|
||||
declaration.transformChildrenVoid(this)
|
||||
|
||||
declaration.descriptor.valueParameters.forEach {
|
||||
declaration.getDefault(it)?.coerce(it.type)
|
||||
}
|
||||
|
||||
return declaration
|
||||
}
|
||||
|
||||
override fun visitWhen(expression: IrWhen): IrExpression {
|
||||
expression.transformChildrenVoid(this)
|
||||
|
||||
@@ -184,6 +205,10 @@ class InsertImplicitCasts(val builtIns: KotlinBuiltIns): IrElementTransformerVoi
|
||||
return expression
|
||||
}
|
||||
|
||||
private fun IrExpressionBody.coerce(expectedType: KotlinType) {
|
||||
expression = expression.cast(expectedType)
|
||||
}
|
||||
|
||||
private fun IrExpression.cast(expectedType: KotlinType?): IrExpression {
|
||||
if (expectedType == null) return this
|
||||
if (expectedType.isError) return this
|
||||
|
||||
@@ -28,7 +28,7 @@ interface IrFunction : IrDeclaration {
|
||||
override val declarationKind: IrDeclarationKind
|
||||
get() = IrDeclarationKind.FUNCTION
|
||||
|
||||
fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrBody)
|
||||
fun getDefault(parameter: ValueParameterDescriptor): IrBody?
|
||||
fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody)
|
||||
fun getDefault(parameter: ValueParameterDescriptor): IrExpressionBody?
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.ir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
|
||||
interface IrProperty : IrDeclaration {
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.ir.declarations.impl
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import java.util.*
|
||||
@@ -29,12 +29,12 @@ abstract class IrFunctionBase(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin
|
||||
) : IrGeneralFunctionBase(startOffset, endOffset, origin), IrFunction {
|
||||
private val defaults = LinkedHashMap<ValueParameterDescriptor, IrBody>()
|
||||
private val defaults = LinkedHashMap<ValueParameterDescriptor, IrExpressionBody>()
|
||||
|
||||
override fun getDefault(parameter: ValueParameterDescriptor): IrBody? =
|
||||
override fun getDefault(parameter: ValueParameterDescriptor): IrExpressionBody? =
|
||||
defaults[parameter]
|
||||
|
||||
override fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrBody) {
|
||||
override fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody) {
|
||||
defaults[parameter] = expressionBody
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ interface IrBody : IrElement {
|
||||
|
||||
interface IrExpressionBody : IrBody {
|
||||
var expression: IrExpression
|
||||
|
||||
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrExpressionBody =
|
||||
accept(transformer, data) as IrExpressionBody
|
||||
}
|
||||
|
||||
interface IrBlockBody : IrBody, IrStatementContainer
|
||||
|
||||
Reference in New Issue
Block a user