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

[Scala 3] - Wildcard derivation import not working #425

Closed
Tracked by #481
gvolpe opened this issue Jan 12, 2022 · 11 comments · Fixed by #516
Closed
Tracked by #481

[Scala 3] - Wildcard derivation import not working #425

gvolpe opened this issue Jan 12, 2022 · 11 comments · Fixed by #516
Milestone

Comments

@gvolpe
Copy link
Member

gvolpe commented Jan 12, 2022

Super simple reproduction:

import cats.Show
// import cats.derived.semiauto.{ derived, product } // this works
// import cats.derived.semiauto.{ given, * } // this works (as per the 3rd comment)
import cats.derived.semiauto.* // does not work

enum TradeAction derives Show:
  case Ask, Bid

It fails with the following error:

no implicit argument of type cats.Show[(Playground.TradeAction.Ask : Playground.TradeAction)] was found

The following import might fix the problem:

  import cats.derived.semiauto.product

https://scastie.scala-lang.org/0q4XaUbJTqibfe78MuyzAA


Not sure whether this has already been discussed or not but I figured it might be better to keep track of it right here.

@gvolpe
Copy link
Member Author

gvolpe commented Jan 12, 2022

Another example that adds Eq:

import cats.{ Eq, Show }
// import cats.derived.semiauto.{ derived, product, productOrder } // this works
import cats.derived.semiauto.* // does not work

enum ForecastTag derives Eq, Show:
  case Long, Short

Fails with the following error:

no implicit argument of type cats.kernel.Eq[(Playground.ForecastTag.Long : Playground.ForecastTag)] was found

The following import might fix the problem:

  import cats.derived.semiauto.productEq

no implicit argument of type cats.Show[(Playground.ForecastTag.Long : Playground.ForecastTag)] was found

https://scastie.scala-lang.org/HGVuAPc3TlmfGyirNlYVxw

@gvolpe
Copy link
Member Author

gvolpe commented Jan 12, 2022

There are a few other (probably related) issues with sealed trait as well, if it's useful, I can try to produce a minimal reproducible example of this: https://github.com/gvolpe/trading/blob/main/modules/domain/src/main/scala/trading/commands/ForecastCommand.scala#L8

@gvolpe
Copy link
Member Author

gvolpe commented Jan 12, 2022

Ok, the first one is simply fixed with this import

import cats.derived.semiauto.{ given, * }

The second and the latter still do not work, though.

@gvolpe gvolpe closed this as completed Jan 12, 2022
@gvolpe gvolpe reopened this Jan 12, 2022
@gvolpe
Copy link
Member Author

gvolpe commented Jan 12, 2022

Hmmm this for some reason does not compile locally:

import cats.{ Eq, Show }
import cats.derived.semiauto.{ given, * } 
import cats.syntax.all.*

enum TradingStatus derives Eq, Show:
  case On, Off

object TradingStatus:
  def from(str: String): Option[TradingStatus] =
    Either.catchNonFatal(valueOf(str)).toOption

Fails with this error:

[error] -- Error: /home/gvolpe/workspace/trading/modules/domain/src/main/scala/trading/domain/TradingStatus.scala:8:27
[error] 8 |enum TradingStatus derives Eq, Show:
[error]   |                           ^
[error]   |ambiguous implicit arguments: both given instance productOrder in trait OrderDerivation and given instance productHash in trait HashDerivation match type cats.kernel.Eq[(trading.domain.TradingStatus.On : trading.domain.TradingStatus)]
[error]   | This location contains code that was inlined from deriving.scala:35
[error]   | This location contains code that was inlined from deriving.scala:30
[error]   | This location contains code that was inlined from erased.scala:301
[error]   | This location contains code that was inlined from kinds.scala:149
[error]   | This location contains code that was inlined from eq.scala:24
[error] one error found
[error] one error found
[error] (domain / Compile / compileIncremental) Compilation failed

But it compiles just fine on Scastie: https://scastie.scala-lang.org/7Eqo9m1hRNCdhX55GTTBdw

I need to dig in more into this.

@joroKr21
Copy link
Member

joroKr21 commented Jan 13, 2022

Kittens for Scala 3 is not ready yet - I think some functionality is missing / implemented inconsistently in the released version.

But we are blocked by a Scala compiler issue: scala/scala3#13406
On the other hand we need a newer version that contains this fix: scala/scala3#14003

@gvolpe
Copy link
Member Author

gvolpe commented Jan 13, 2022

Thanks for the quick reply, @joroKr21 !

I understand it's not ready yet. Are you keeping track of the issues / limitations somewhere else? If not, it's probably a good idea to have them on this repo, no?

@joroKr21
Copy link
Member

I understand it's not ready yet. Are you keeping track of the issues / limitations somewhere else? If not, it's probably a good idea to have them on this repo, no?

Yeah, I'm just not sure if this is a limitation that applies in general or we just need to get unblocked by fixing that Scala bug and release 😄

@gvolpe
Copy link
Member Author

gvolpe commented Jan 13, 2022

Got you! Ok, if you don't mind, I'll leave this issue open but will refrain from opening new ones. I was aware of these issues for a while but I thought I should raise it here now that the project where I use Kittens is public 😄

@TimWSpence
Copy link
Member

Thanks @gvolpe! It's great to have feedback on what else we might need to fix once we're unblocked upstream 😅

@joroKr21
Copy link
Member

Let's just go for it and release what we can - even if it's not working perfectly at least people can use it.
#427 is the first step. We still have a around half the type classes to port.

@gvolpe
Copy link
Member Author

gvolpe commented Jan 14, 2022

That is awesome, thanks @joroKr21 🤩

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

Successfully merging a pull request may close this issue.

3 participants