Closed
Description
Issue found when applying automatic rewrites for sagifogel/proptics
in Open CB
Compiler version
All Scala 3.4+ versions
Minimized code
//> using options -Ykind-projector
import scala.collection.SortedMap
trait NonEmptyMap[K, +A]:
def toSortedMap: SortedMap[K, A]
trait FoldableWithIndex[F[_], I]:
def test[K] = new FoldableWithIndex[NonEmptyMap[K, *], K] {
def foldLeftWithIndex[A, B](f: (B, (A, K)) => B)(fa: NonEmptyMap[K, A], b: B): B =
mapLikeFoldLeftWithIndex((fa.toSortedMap.foldLeft[B] _))(f)(b)
}
def mapLikeFoldLeftWithIndex[A, B, K](foldLeft: B => ((B, (K, A)) => B) => B)(f: (B, (A, K)) => B)(b: B): B = ???
Output
//> using options -Ykind-projector
import scala.collection.SortedMap
trait NonEmptyMap[K, +A]:
def toSortedMap: SortedMap[K, A]
trait FoldableWithIndex[F[_], I]:
def test[K] = new FoldableWithIndex[NonEmptyMap[K, *], K] {
def foldLeftWithIndex[A, B](f: (B, (A, K)) => B)(fa: NonEmptyMap[K, A], b: B): B =
mapLikeFoldLeftWithIndex(((() => fa.toSortedMap.foldLeft[B])))(f)(b)
}
def mapLikeFoldLeftWithIndex[A, B, K](foldLeft: B => ((B, (K, A)) => B) => B)(f: (B, (A, K)) => B)(b: B): B = ???
-- [E007] Type Mismatch Error: /Users/wmazur/projects/sandbox/src/main/scala/schema.scala:10:39
10 | mapLikeFoldLeftWithIndex(((() => fa.toSortedMap.foldLeft[B])))(f)(b)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| Found: B => Any
| Required: ((Any, (Any, Any)) => Any) => Any
|
| longer explanation available when compiling with `-explain`
Expectation
The compiler should not suggest an automatic rewrite when the function is curried. Other cases for rewrite should be also considered