FutureMind/koru

MainScopeProvider needs @ SharedImmutable Annotation

Closed this issue · 7 comments

837 commented

Generated
public val exportedScopeProvider_mainScopeProvider: MainScopeProvider = MainScopeProvider()
Should be annotated with @SharedImmutable else it will throw

Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
It is considered unexpected and unhandled instead. Program will be terminated.
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
837 commented
  fun build(): PropertySpec = PropertySpec
        .builder(scopePropertyName, scopeProviderClassName, KModifier.PUBLIC)
        .initializer("%T()", scopeProviderClassName)
        .addAnnotation(SharedImmutable::class) // This is a native annotation though. So we can't just add it...
        .build()

Doesn't seem to be this easy to add, SharedImmutable is a native Annotation and can't be accessed in a jvm module..

Scope provider is not something that should be passed through different threads. I'm not sure if it's even possible to use scopes this way in kotlin native, afair they should remain mutable.

The idea is to prepare these classes on main thread and make them work on background thread.

837 commented

This happens when you call .subscribe(..) in anything but the main thread.

Can you retry your use case with 0.6.0? It introduced freeze param on ToNativeClass. I wonder if it fixes your issue concerning the scope provider as well.

837 commented

Same issue as it throws the moment it is accessed.

public class TEST_IOS(
  private val wrapped: TEST,
  private val scopeProvider: ScopeProvider?
) {
  init {
    this.freeze()
  }
  public constructor(wrapped: TEST) :
      this(wrapped,exportedScopeProvider_mainScopeProvider) //throws here

Can you show how you create it in your ios code?

It's not a problem to add a SharedImmutable annotation with expect/actual mechanism, I'm just not sure we should do it. I don't think scopes are immutable.

Closing as stale.