realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

Vague "Cannot find Primary Constructor" compile error

Open cmelchior opened this issue 3 years ago • 3 comments

Got this error:

e: java.lang.IllegalStateException: Can not find primary constructor
	at io.realm.compiler.RealmModelSyntheticPropertiesGeneration$addNewInstanceMethodBody$1.invoke(RealmModelSyntheticPropertiesGeneration.kt:477)
	at io.realm.compiler.RealmModelSyntheticPropertiesGeneration$addNewInstanceMethodBody$1.invoke(RealmModelSyntheticPropertiesGeneration.kt:475)
	at io.realm.compiler.IrUtilsKt.blockBody(IrUtils.kt:98)
	at io.realm.compiler.RealmModelSyntheticPropertiesGeneration.addNewInstanceMethodBody(RealmModelSyntheticPropertiesGeneration.kt:475)
	at io.realm.compiler.RealmModelLowering.lower(RealmModelLoweringExtension.kt:77)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitClass(Lower.kt:82)

Kinda hard to debug without more information. We should also add the Class being modified to the exception message.

cmelchior avatar Nov 21 '21 14:11 cmelchior

The cause is this code like this:

class Person : RealmObject {
  constructor() { } 
  constructor(input: String) { }
}

We still require a no-op constructor in order to create objects on the user's behalf, but forcing the no-op to be the primary constructor seems a bit odd.... Instead we should probably search all viable constructors and only then report the error?

cmelchior avatar Nov 21 '21 14:11 cmelchior

Verify if this is fixed

cmelchior avatar Aug 19 '22 09:08 cmelchior

Not fully on top of this, but seems like the work that I thought fixed this (#184/#673) was done prior to this issue being reported so assume there is still something to do.

rorbech avatar Aug 19 '22 10:08 rorbech