IR: make casts to nullable types in transformChildren stricter
This commit is contained in:
@@ -39,6 +39,6 @@ abstract class IrEnumEntry : IrDeclarationBase(), IrDeclarationWithName {
|
||||
|
||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||
initializerExpression = initializerExpression?.transform(transformer, data)
|
||||
correspondingClass = correspondingClass?.transform(transformer, data) as? IrClass
|
||||
correspondingClass = correspondingClass?.transform(transformer, data) as IrClass?
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,6 +48,6 @@ abstract class IrLocalDelegatedProperty : IrDeclarationBase(), IrDeclarationWith
|
||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||
delegate = delegate.transform(transformer, data) as IrVariable
|
||||
getter = getter.transform(transformer, data) as IrSimpleFunction
|
||||
setter = setter?.transform(transformer, data) as? IrSimpleFunction
|
||||
setter = setter?.transform(transformer, data) as IrSimpleFunction?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ abstract class IrProperty : IrDeclarationBase(), IrPossiblyExternalDeclaration,
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||
backingField = backingField?.transform(transformer, data) as? IrField
|
||||
backingField = backingField?.transform(transformer, data) as IrField?
|
||||
getter = getter?.transform(transformer, data) as IrSimpleFunction?
|
||||
setter = setter?.transform(transformer, data) as IrSimpleFunction?
|
||||
}
|
||||
|
||||
@@ -380,12 +380,8 @@ object IrTree : AbstractTreeBuilder() {
|
||||
+field("isExpect", boolean)
|
||||
+field("isFakeOverride", boolean)
|
||||
+field("backingField", field, mutable = true, nullable = true, isChild = true)
|
||||
+field("getter", simpleFunction, mutable = true, nullable = true, isChild = true) {
|
||||
strictCastInTransformChildren = true
|
||||
}
|
||||
+field("setter", simpleFunction, mutable = true, nullable = true, isChild = true) {
|
||||
strictCastInTransformChildren = true
|
||||
}
|
||||
+field("getter", simpleFunction, mutable = true, nullable = true, isChild = true)
|
||||
+field("setter", simpleFunction, mutable = true, nullable = true, isChild = true)
|
||||
}
|
||||
|
||||
//TODO: make IrScript as IrPackageFragment, because script is used as a file, not as a class
|
||||
|
||||
+2
-5
@@ -75,7 +75,6 @@ sealed class Field(
|
||||
val nullable: Boolean,
|
||||
val mutable: Boolean,
|
||||
val isChild: Boolean,
|
||||
val strictCastInTransformChildren: Boolean,
|
||||
) {
|
||||
abstract val type: TypeRef
|
||||
abstract val baseDefaultValue: CodeBlock?
|
||||
@@ -97,10 +96,9 @@ class SingleField(
|
||||
nullable: Boolean,
|
||||
mutable: Boolean,
|
||||
isChild: Boolean,
|
||||
strictCastInTransformChildren: Boolean,
|
||||
override val baseDefaultValue: CodeBlock?,
|
||||
override val baseGetter: CodeBlock?,
|
||||
) : Field(config, name, nullable, mutable, isChild, strictCastInTransformChildren) {
|
||||
) : Field(config, name, nullable, mutable, isChild) {
|
||||
override val transformable: Boolean
|
||||
get() = mutable
|
||||
}
|
||||
@@ -113,11 +111,10 @@ class ListField(
|
||||
nullable: Boolean,
|
||||
mutable: Boolean,
|
||||
isChild: Boolean,
|
||||
strictCastInTransformChildren: Boolean,
|
||||
override val transformable: Boolean,
|
||||
override val baseDefaultValue: CodeBlock?,
|
||||
override val baseGetter: CodeBlock?,
|
||||
) : Field(config, name, nullable, mutable, isChild, strictCastInTransformChildren) {
|
||||
) : Field(config, name, nullable, mutable, isChild) {
|
||||
override val type: TypeRef
|
||||
get() = listType.withArgs(elementType)
|
||||
}
|
||||
|
||||
-2
@@ -28,7 +28,6 @@ fun config2model(config: Config): Model {
|
||||
fc.nullable,
|
||||
fc.mutable,
|
||||
fc.isChild,
|
||||
fc.strictCastInTransformChildren,
|
||||
fc.baseDefaultValue,
|
||||
fc.baseGetter
|
||||
)
|
||||
@@ -45,7 +44,6 @@ fun config2model(config: Config): Model {
|
||||
fc.nullable,
|
||||
fc.mutability == ListFieldConfig.Mutability.Var,
|
||||
fc.isChild,
|
||||
fc.strictCastInTransformChildren,
|
||||
fc.mutability != ListFieldConfig.Mutability.Immutable,
|
||||
fc.baseDefaultValue,
|
||||
fc.baseGetter
|
||||
|
||||
+2
-8
@@ -157,14 +157,8 @@ fun printElements(generationPath: File, model: Model) = sequence {
|
||||
if (child is SingleField) {
|
||||
val elRef = child.type as ElementRef
|
||||
if (!elRef.element.transform) {
|
||||
append(" as")
|
||||
if (child.strictCastInTransformChildren) {
|
||||
append(" %T")
|
||||
if (child.nullable) append("?")
|
||||
} else {
|
||||
if (child.nullable) append("?")
|
||||
append(" %T")
|
||||
}
|
||||
append(" as %T")
|
||||
if (child.nullable) append("?")
|
||||
args.add(elRef.toPoet())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user