Coder Social home page Coder Social logo

Comments (6)

evant avatar evant commented on September 7, 2024

Got a couple of thoughts here, we could either:

  1. Be strict like ksp is (I think the metadata is there in the kapt backend to do this)
  2. Allow types to be 'upgraded' when compatible. This would be similar to how you can do both foo: Foo = javaMethodThatReturnsFoo() and foo: Foo? = javaMethodThatReturnsFoo() in kotlin.

I'm leaning towards 1 for fewer surprises but it does mean you may have to explicitly declare the return type on a @Provides in some cases. Maybe an explicit warning/error message here could help?

from kotlin-inject.

sunian avatar sunian commented on September 7, 2024

I'd prefer option 1 as well.

from kotlin-inject.

rf43 avatar rf43 commented on September 7, 2024

I agree with @sunian that as a consumer, option 1 seems to be the safest, most forward looking solution.

Also, may have to explicitly declare the return type on a @Provides in some cases while slightly inconvenient I wouldn't think that's too bad.

from kotlin-inject.

evant avatar evant commented on September 7, 2024

It's not inconvenient no, but it did take me a bit to figure out what was happening. I had

@Provides fun retrofit(client: OkHttpClient) = Retrofit.Builder().build()
@Provides fun myService(retrofit: Retrofit): MyService = retrofit.create()

and it was complaining that it couldn't find retrofit. Again a targeted warning/error might be good enough though.

from kotlin-inject.

evant avatar evant commented on September 7, 2024

Fixed so the behavior in both back-ends matched. Keeping this open until we can get a better error for this case.

from kotlin-inject.

evant avatar evant commented on September 7, 2024

Ended up disallowing platform types in @Provides methods. You get a helpful error telling you to declare the return type explicitly. This not only better documents your intent, but means you if you get it wrong (say fun foo(): Foo = javaMethodThatCanReturnNull() you get a NPE in your code instead of deep in the generated code.

from kotlin-inject.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.