augustjune / context-applied

Compiler plugin for intuitive tagless final
MIT License
128 stars 8 forks source link

Strange compiler error on mixin algebras #1

Closed gvolpe closed 4 years ago

gvolpe commented 4 years ago

I'm just trying out this plugin in Redis4Cats and stumbled upon the following issue:

[info] Compiling 16 Scala sources to /workspace/oss/redis4cats/modules/effects/target/scala-2.13/classes ...
[error] /workspace/oss/redis4cats/modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/sortedsets.scala:24:35: type mismatch;
[error]  found   : <notype>
[error]  required: F[List[V]]
[error] trait SortedSetGetter[F[_], K, V] {
[error]                                   ^
[info] <notype> <: F[List[V]]?
[info] false
[info] <notype> <: F[List[dev.profunktor.redis4cats.effects.ScoreWithValue[V]]]?
[info] false
[info] <notype> <: F[List[V]]?
[info] false
[info] <notype> <: F[List[dev.profunktor.redis4cats.effects.ScoreWithValue[V]]]?
[info] false
[error] one error found
[error] (redis4cats-effects / Compile / compileIncremental) Compilation failed
[error] Total time: 5 s, completed Dec 31, 2019 3:32:32 PM

This happens with the following algebra, which is a mixin:

trait SortedSetCommands[F[_], K, V] extends SortedSetGetter[F, K, V] with SortedSetSetter[F, K, V]

trait SortedSetGetter[F[_], K, V] {
  def zCard(key: K): F[Option[Long]]
  def zCount(key: K, range: ZRange[V])(implicit ev: Numeric[V]): F[Option[Long]]
  def zLexCount(key: K, range: ZRange[V]): F[Option[Long]]
  def zRange(key: K, start: Long, stop: Long): F[List[V]]
  def zRangeByLex(key: K, range: ZRange[V], limit: Option[RangeLimit]): F[List[V]]
  def zRangeByScore[T: Numeric](key: K, range: ZRange[T], limit: Option[RangeLimit]): F[List[V]]
  def zRangeByScoreWithScores[T: Numeric](key: K,
                                          range: ZRange[T],
                                          limit: Option[RangeLimit]): F[List[ScoreWithValue[V]]]
  def zRangeWithScores(key: K, start: Long, stop: Long): F[List[ScoreWithValue[V]]]
  def zRank(key: K, value: V): F[Option[Long]]
  def zRevRange(key: K, start: Long, stop: Long): F[List[V]]
  def zRevRangeByLex(key: K, range: ZRange[V], limit: Option[RangeLimit]): F[List[V]]
  def zRevRangeByScore[T: Numeric](key: K, range: ZRange[T], limit: Option[RangeLimit]): F[List[V]]
  def zRevRangeByScoreWithScores[T: Numeric](key: K,
                                             range: ZRange[T],
                                             limit: Option[RangeLimit]): F[List[ScoreWithValue[V]]]
  def zRevRangeWithScores(key: K, start: Long, stop: Long): F[List[ScoreWithValue[V]]]
  def zRevRank(key: K, value: V): F[Option[Long]]
  def zScore(key: K, value: V): F[Option[Double]]
}

trait SortedSetSetter[F[_], K, V] {
  def zAdd(key: K, args: Option[ZAddArgs], values: ScoreWithValue[V]*): F[Unit]
  def zAddIncr(key: K, args: Option[ZAddArgs], value: ScoreWithValue[V]): F[Unit]
  def zIncrBy(key: K, member: V, amount: Double): F[Unit]
  def zInterStore(destination: K, args: Option[ZStoreArgs], keys: K*): F[Unit]
  def zRem(key: K, values: V*): F[Unit]
  def zRemRangeByLex(key: K, range: ZRange[V]): F[Unit]
  def zRemRangeByRank(key: K, start: Long, stop: Long): F[Unit]
  def zRemRangeByScore(key: K, range: ZRange[V])(implicit ev: Numeric[V]): F[Unit]
  def zUnionStore(destination: K, args: Option[ZStoreArgs], keys: K*): F[Unit]
}

There are many other algebras like this but I only get a compiler error with this one. Maybe because the compiler didn't reach out to the other algebras I guess?

Here's the corresponding PR for more details: https://github.com/profunktor/redis4cats/pull/205


EDIT: It happens the same if I make it a single algebra trait SortedSetCommands[F[_], K, V] without mixing any other trait but preserving all the methods.

augustjune commented 4 years ago

Cool, thanks a lot for trying the plugin out and raising the issue. I will take a closer look at this later (probably tomorrow) and let you know what I found.

gvolpe commented 4 years ago

No rush @augustjune, thanks for making it and happy new year :)

augustjune commented 4 years ago

The issue is actually caused by incorrect handling of trait methods declared with context bounds. PR link to redis4cats was very helpful. Thanks for improving the state of the project :)