arrow icon indicating copy to clipboard operation
arrow copied to clipboard

["Request"] Investigate providing type hints using DeprecationLevel.ERROR

Open nomisRev opened this issue 3 years ago • 2 comments

What version are you currently using?

1.x.x

What would you like to see?

Sometimes it's not clear why Either<Throwable, Int> cannot be bind inside either<String, A> { }, and similarly with other data types that don't match the logical failure channel type.

Based on some discussions on Twitter, and Slack we discovered that you can leverage DeprecationLevel.ERROR to provide hints to the user, to clarify why the signature results in a ERROR.

We can on a per type/signature basis provide better error messages to the user. I.e.

  • "Option.bind() cannot be called with different error type, use mapLeft to transform None into the same error type"
  • "Either.bind() can only be called with the Left type, or subtype. Use mapLeft to transform the error type.
  • ...
Screenshot 2022-10-06 at 17 41 17

https://twitter.com/vergauwen_simon/status/1578047840227557379?s=20&t=REup7C6kEet76dtI66gUIQ https://kotlinlang.slack.com/archives/C5UPMM0A0/p1665068590923969

nomisRev avatar Oct 07 '22 07:10 nomisRev

I'll take a stab at this in arrow-context, since I think contexts could make implementing this pattern a lot easier. My only fear is that collisions could happen where the inner context binds stronger to such an erroneous declaration than an outer context, but I'll test out and see if that's the case.

kyay10 avatar Feb 06 '24 13:02 kyay10

My only fear is that collisions could happen where the inner context binds stronger to such an erroneous declaration than an outer context, but I'll test out and see if that's the case.

Yes, that is most likely going to occur but in those case need to explicitly call implicit<OutScope>().function(), right? Perhaps clarifying in the message is enough? Ideally, this would be done with fully flexed IDEA support but looks like that won't ever happen from Kotlin plugins.

nomisRev avatar Feb 07 '24 08:02 nomisRev