artist icon indicating copy to clipboard operation
artist copied to clipboard

Rx Kotlin Nulls

Open sanchezz93 opened this issue 3 years ago • 0 comments

  • When generating code in Artist from the KotlinApiHelper we get the following
public open override fun clicks(): Observable<Unit> {
    if (clicks == null) {
    	....
         rxview_longCl().map()
    		.doOnNext(UiChecks.checkClickableRequirementsAction(this))
    		.doOnNext(ViewAnalytics.logTapFor(this, getContext())).subscribe(clicks)
    	}
    }
   ....
  }

The Kotlin compiler assumes that the clicks in the subscribe method is null even though we set it a few lines prior. A possible fix for this is adding a let call before the rx chain. This way we will prevent the compiler from prompting

smart cast to 'PublishRelay<Unit>' is impossible, because 'clicks' is a mutable property that could have been changed by this time

How we're planning on solving it

public open override fun clicks(): Observable<Unit> {
    if (clicks == null) {
    	....
        clicks?.let {
         rxview_longCl().map()
    		.doOnNext(UiChecks.checkClickableRequirementsAction(this))
    		.doOnNext(ViewAnalytics.logTapFor(this, getContext())).subscribe(it)
    	 }
       }
    }
    ....
  }

sanchezz93 avatar Jun 23 '22 00:06 sanchezz93