I cannot create a topic in Bugs category, so I just post it here.
Please look at the bottom class declaration.
OuterClass has a InnerClass.
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.20-Beta"
}
group = "zeroarst.com"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("io.reactivex.rxjava3:rxkotlin:3.0.1")
implementation(group= "org.hashids", name= "hashids", version= "1.0.3")
// https://mvnrepository.com/artifact/org.json/json
implementation("org.json:json:20220924")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.languageVersion = "1.8"
}
open class OuterClass {
open inner class InnerClass
}
object OuterClassInstance: OuterClass() {
object InnerClassInstance: InnerClass()
}
this block of code causes the error:
object OuterClassInstance: OuterClass() {
object InnerClassInstance: InnerClass()
}
error details:
Caused by: java.lang.RuntimeException: Error generating constructors of class InnerClassInstance with kind IMPLEMENTATION
at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateConstructors(ImplementationBodyCodegen.java:469)
at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateBody(ClassBodyCodegen.java:96)
at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:132)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:305)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:289)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:315)
at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateDeclaration(ClassBodyCodegen.java:176)
at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateBody(ClassBodyCodegen.java:80)
at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:132)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:305)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:289)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:315)
at org.jetbrains.kotlin.codegen.ScriptCodegen.genMembers(ScriptCodegen.kt:238)
at org.jetbrains.kotlin.codegen.ScriptCodegen.generateBody(ScriptCodegen.kt:58)
at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:132)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:111)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:138)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:70)
... 258 more
Caused by: java.lang.UnsupportedOperationException: Don't know how to generate outer expression for private constructor InnerClassInstance() defined in Build_gradle.OuterClassInstance.InnerClassInstance[DefaultClassConstructorDescriptor@6734384b]
at org.jetbrains.kotlin.codegen.context.ConstructorContext.getOuterExpression(ConstructorContext.java:65)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateThisOrOuterFromContext(ExpressionCodegen.java:3293)
at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateThisOrOuter(ExpressionCodegen.java:3251)
at org.jetbrains.kotlin.codegen.ConstructorCodegen.generateSuperCallImplicitArguments(ConstructorCodegen.java:429)
at org.jetbrains.kotlin.codegen.ConstructorCodegen.generateDelegationConstructorCall(ConstructorCodegen.java:337)
at org.jetbrains.kotlin.codegen.ConstructorCodegen.generateDelegatorToConstructorCall(ConstructorCodegen.java:178)
at org.jetbrains.kotlin.codegen.ConstructorCodegen.generatePrimaryConstructorImpl(ConstructorCodegen.java:205)
at org.jetbrains.kotlin.codegen.ConstructorCodegen.access$000(ConstructorCodegen.java:42)
at org.jetbrains.kotlin.codegen.ConstructorCodegen$1.doGenerateBody(ConstructorCodegen.java:98)
at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:86)
at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:649)
at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:484)
at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:260)
at org.jetbrains.kotlin.codegen.ConstructorCodegen.generatePrimaryConstructor(ConstructorCodegen.java:94)
at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateConstructors(ImplementationBodyCodegen.java:457)
... 275 more
It looks like related to this issue. But the state is fixed.
What I want to do is I want to limit InnerClass only be able to instantiate inside OuterClass…
My IDE: