Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable type results in StackOverflowError #121

Open
czterocyty opened this issue Sep 16, 2019 · 1 comment
Open

Nullable type results in StackOverflowError #121

czterocyty opened this issue Sep 16, 2019 · 1 comment

Comments

@czterocyty
Copy link

Hi,

We play with nullable types, eg: val a: String? inside our data class. However generated code as well as simple test snippet results in StackOverflowError:

    "Nullable String element" {
      val str: String? = "abc"

      val js: Json = NullableEncoderInstance<String>(String.encoder()).run {
        str.encode()
      }

      println(js)
    }

It looks like NullableEncoderInstance cannot see encode extension function of the enclosed encoder:

override fun A?.encode(): Json =
    this?.let { a -> encoderA().let { a.encode() } } ?: JsNull
@pakoito
Copy link
Contributor

pakoito commented Sep 16, 2019

This looks like a shadowing error. It may be trying to get another extfun in a different context. It needs to be imported with a name such as import bla.encode as blaEncode, and then use a.blaEncode()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants