how to add parameters to a class constructor? I wa...
# compiler
m
how to add parameters to a class constructor? I want to add parameters to a primary constructor in SyntheticResolveExtension, but it failed the code is: in SyntheticResolveExtension: override fun generateSyntheticClasses( thisDescriptor: ClassDescriptor, name: Name, ctx: LazyClassContext, declarationProvider: ClassMemberDeclarationProvider, result: MutableSet<ClassDescriptor> ) { if (!thisDescriptor.annotatedAsDeepCopiableDataClass()) { return } if(name.identifier=="sub") { result += trackableSubClass(thisDescriptor); } } private fun trackableSubClass( thisDescriptor: ClassDescriptor ): ClassDescriptorImpl = object : ClassDescriptorImpl( thisDescriptor, Name.identifier(SUBCLASS_NAME), Modality.FINAL, ClassKind.CLASS, emptyList<KotlinType>(), thisDescriptor.source, false, LockBasedStorageManager.NO_LOCKS ) { override fun getUnsubstitutedMemberScope(): MemberScope { return MemberScope.Empty } }.apply { val a = ClassConstructorDescriptorImpl.create( this, Annotations.EMPTY, true, this.source ) val b = ValueParameterDescriptorImpl( containingDeclaration = a, original = null, index = 0, annotations = Annotations.EMPTY, name = Name.identifier("d"), outType = thisDescriptor.builtIns.longType, declaresDefaultValue = true, isCrossinline = false, isNoinline = false, varargElementType = null, source = a.source, ) a.initialize( listOf(b), DescriptorVisibilities.PUBLIC, ) a.returnType = this.defaultType this.initialize( MemberScope.Empty, setOf(a), a ) } in IrElementTransformerVoidWithContext: fun IrClass.createSub(pluginContext: IrPluginContext){ val constructorOfAny = pluginContext.irBuiltIns.anyClass.owner.constructors.first() primaryConstructor!!.body=factory.createBlockBody( startOffset, endOffset, listOf( IrDelegatingConstructorCallImpl( startOffset, endOffset, pluginContext.irBuiltIns.unitType, constructorOfAny.symbol, 0, constructorOfAny.valueParameters.size ).apply { primaryConstructor!!.valueParameters.forEachIndexed { idx, parameter -> println(idx) println(parameter) putValueArgument(idx, IrGetValueImpl(startOffset, endOffset, parameter.type, parameter.symbol)) } }, IrInstanceInitializerCallImpl(startOffset, endOffset, symbol, pluginContext.irBuiltIns.unitType) ) ) } the error is : e: java.lang.AssertionError: org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl@2169d6d4: No such value argument slot: 0 at org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression.putValueArgument( )