diff --git a/libraries/tools/idl2k/src/main/kotlin/gen.kt b/libraries/tools/idl2k/src/main/kotlin/gen.kt index caff0f75737..f891a57ecf5 100644 --- a/libraries/tools/idl2k/src/main/kotlin/gen.kt +++ b/libraries/tools/idl2k/src/main/kotlin/gen.kt @@ -133,8 +133,6 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT } assert(superClasses.size <= 1) { "Type ${iface.name} should have one or zero super classes but found ${superClasses.map { it.name }}" } - val superClass = superClasses.singleOrNull() - val superConstructor = superClass?.findConstructors()?.firstOrNull() ?: EMPTY_CONSTRUCTOR val declaredConstructors = iface.findConstructors() val entityKind = resolveDefinitionKind(repository, iface, declaredConstructors) @@ -149,23 +147,14 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT val primaryConstructorWithCall = primaryConstructor?.let { constructor -> val constructorAsFunction = generateConstructorAsFunction(repository, constructor) - val superCall = when { - superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, superClass.name, superConstructor) - else -> null - } - ConstructorWithSuperTypeCall(constructorAsFunction, constructor, superCall) + ConstructorWithSuperTypeCall(constructorAsFunction, constructor) } val secondaryConstructorsWithCall = secondaryConstructors.map { secondaryConstructor -> val constructorAsFunction = generateConstructorAsFunction(repository, secondaryConstructor) - val initCall = when { - primaryConstructorWithCall != null -> superOrPrimaryConstructorCall(constructorAsFunction, "this", primaryConstructorWithCall.constructorAttribute) - superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, "super", superConstructor) - else -> null - } - ConstructorWithSuperTypeCall(constructorAsFunction, secondaryConstructor, initCall) + ConstructorWithSuperTypeCall(constructorAsFunction, secondaryConstructor) } return GenerateTraitOrClass(iface.name, iface.namespace, entityKind, (iface.superTypes + extensions.map { it.name }).distinct(), @@ -184,15 +173,6 @@ fun generateConstructorAsFunction(repository: Repository, constructor: ExtendedA functionName = "constructor", nativeGetterOrSetter = NativeGetterOrSetter.NONE) -fun superOrPrimaryConstructorCall(constructorAsFunction: GenerateFunction, superClassName: String, superOrPrimaryConstructor: ExtendedAttribute): GenerateFunctionCall { - val constructorArgumentNames = constructorAsFunction.arguments.map { it.name }.toSet() - return GenerateFunctionCall( - name = superClassName, - arguments = superOrPrimaryConstructor.arguments.map { arg -> - if (arg.name in constructorArgumentNames) arg.name else "noImpl" - } - ) -} fun mapUnionType(it: UnionType) = GenerateTraitOrClass( name = it.name, diff --git a/libraries/tools/idl2k/src/main/kotlin/model.kt b/libraries/tools/idl2k/src/main/kotlin/model.kt index 2c2ae3aa610..05a90a0ceb4 100644 --- a/libraries/tools/idl2k/src/main/kotlin/model.kt +++ b/libraries/tools/idl2k/src/main/kotlin/model.kt @@ -73,7 +73,7 @@ data class GenerateFunction( val override: Boolean ) -data class ConstructorWithSuperTypeCall(val constructor: GenerateFunction, val constructorAttribute: ExtendedAttribute, val initTypeCall: GenerateFunctionCall?) +data class ConstructorWithSuperTypeCall(val constructor: GenerateFunction, val constructorAttribute: ExtendedAttribute) data class GenerateTraitOrClass( val name: String, val namespace: String, diff --git a/libraries/tools/idl2k/src/main/kotlin/render.kt b/libraries/tools/idl2k/src/main/kotlin/render.kt index 66a87cdc21d..62fcdefd4de 100644 --- a/libraries/tools/idl2k/src/main/kotlin/render.kt +++ b/libraries/tools/idl2k/src/main/kotlin/render.kt @@ -156,10 +156,8 @@ fun Appendable.render(allTypes: Map, typeNamesToUn } val superTypesExclude = inheritanceExclude[iface.name] ?: emptySet() - val superCallName = primary?.initTypeCall?.name val superTypesWithCalls = - (primary?.initTypeCall?.let { listOf(renderCall(it)) } ?: emptyList()) + - iface.superTypes.filter { it != superCallName && it in allSuperTypesNames }.filter { it !in superTypesExclude } + + iface.superTypes.filter { it in allSuperTypesNames }.filter { it !in superTypesExclude } + (typeNamesToUnions[iface.name] ?: emptyList()) if (superTypesWithCalls.isNotEmpty()) { @@ -173,11 +171,6 @@ fun Appendable.render(allTypes: Map, typeNamesToUn append("constructor") renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keys), false) - if (secondary.initTypeCall != null) { - append(" : ") - append(renderCall(secondary.initTypeCall)) - } - appendln() }