You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
False implicit not found error when searching for an implicit value defined in another module that directly references a higher-kinded type defined in a 3rd module that is a subtype of the sought type
#16183
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.
This bug seems to definitely require both an external library (cats) and a multi-module project. Attempts to minimize without these two failed for me. It could plausibly be an issue with the org.typelevelcats-core_32.6.0 artifact, since I cannot reproduce it with locally defined similar types.
To reproduce execute:
git clone https://github.com/7mind/no-more-orphans.git --branch bug/hkt-cats-type-failure
cd no-more-orphans/
sbt test
With the following setup:
packagemylibimportscala.math.OrderingfinalcaseclassMyIntSet(i: Set[Int])
objectMyIntSet {
implicitdefoptionalCatsBoundedSemilatticeForMyIntSet[F[_]:CatsBoundedSemilattice]:F[MyIntSet] = {
new cats.kernel.BoundedSemilattice[MyIntSet] {
overridedefempty:MyIntSet=MyIntSet(Set.empty)
overridedefcombine(x: MyIntSet, y: MyIntSet):MyIntSet=MyIntSet(x.i ++ y.i)
}.asInstanceOf[F[MyIntSet]]
}
implicitvalorderingMyIntSet:Ordering[MyIntSet] =null.asInstanceOf[Ordering[MyIntSet]]
}
privatesealedtraitCatsBoundedSemilattice[F[_]]
privateobjectCatsBoundedSemilattice {
// FIXME this misbehaves on Scala 3: generates false implicit-not-found errors when implicit search is in another moduleimplicitvalget:CatsBoundedSemilattice[cats.kernel.BoundedSemilattice] =null// these workarounds all work to pacify Scala 3// implicit val get: CatsBoundedSemilattice[[a] =>> cats.kernel.BoundedSemilattice[a]] = null// implicit def get[T[x] >: cats.kernel.BoundedSemilattice[x]]: CatsBoundedSemilattice[T] = null
}
Following implicit searches fail - only when done in another module - the same search succeeds inside the module that defines MyIntSet:
implicitly[BoundedSemilattice[MyIntSet]] // ok, searching for the same type
implicitly[CommutativeMonoid[MyIntSet]] // fails, when searching for a supertype
implicitly[Monoid[MyIntSet]] // fails, when searching for a supertype
[error] --Error:/private/tmp/no-more-orphans/test-cats/src/test/scala/CatsMyIntSetTest.scala:12:32
[error] 12| implicitly[Monoid[MyIntSet]]
[error] |^
[error] |Nogiveninstance of typecats.kernel.Monoid[mylib.MyIntSet] was found for parameter e of method implicitly in objectPredef.
[error] |Ifound:
[error] |
[error] | mylib.MyIntSet.optionalCatsBoundedSemilatticeForMyIntSet[F](
[error] |/* missing */summon[mylib.CatsBoundedSemilattice[F]]
[error] | )
[error] |
[error] |But no implicit values were found that matchtypemylib.CatsBoundedSemilattice[F].
Workaround
Replacing CatsBoundedSemilattice.get's type argument with a substantially identical type lambda fixes the issue.
- implicit val get: CatsBoundedSemilattice[cats.kernel.BoundedSemilattice] = null+ implicit val get: CatsBoundedSemilattice[[a] =>> cats.kernel.BoundedSemilattice[a]] = null
Expectation
Expected to work as in Scala 2.
NOTE: this bug only happens with an F[_] kinded type, examples in the same project with F[_[_]] kind work correctly.
The text was updated successfully, but these errors were encountered:
Compiler version
3.1.3 and 3.2.1-RC1
Minimized code
This bug seems to definitely require both an external library (cats) and a multi-module project. Attempts to minimize without these two failed for me. It could plausibly be an issue with the
org.typelevel
cats-core_3
2.6.0
artifact, since I cannot reproduce it with locally defined similar types.To reproduce execute:
With the following setup:
Following implicit searches fail - only when done in another module - the same search succeeds inside the module that defines MyIntSet:
Workaround
Replacing
CatsBoundedSemilattice.get
's type argument with a substantially identical type lambda fixes the issue.Expectation
Expected to work as in Scala 2.
NOTE: this bug only happens with an
F[_]
kinded type, examples in the same project withF[_[_]]
kind work correctly.The text was updated successfully, but these errors were encountered: