scalafix
scalafix copied to clipboard
ExplicitResultTypes generate invalid code when use type lambda
step
project/build.properties
sbt.version=1.3.10
project/scalafix.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.15")
build.sbt
scalaVersion := "2.12.11"
Main.scala
trait Functor[F[_]]
object Main {
def foo[A] = new Functor[({type l[x] = Either[A, x]})#l]{}
}
run sbt scalafixEnable "scalafix ExplicitResultTypes" compile
result
trait Functor[F[_]]
object Main {
- def foo[A] = new Functor[({type l[x] = Either[A, x]})#l]{}
+ def foo[A]: Functor[Either[A,x]] = new Functor[({type l[x] = Either[A, x]})#l]{}
}
[error] /Users/kenji/type-lambda-scalafix/Main.scala:4:32: not found: type x
[error] def foo[A]: Functor[Either[A,x]] = new Functor[({type l[x] = Either[A, x]})#l]{}
[error] ^
[error] /Users/kenji/type-lambda-scalafix/Main.scala:4:23: Either[A,<error>] takes no type parameters, expected: one
[error] def foo[A]: Functor[Either[A,x]] = new Functor[({type l[x] = Either[A, x]})#l]{}
[error] ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
I think most people running into this will be using kind-projector - would be be out of scope for this project to have an option of using kind-projector syntax for type lambdas?
I think most people running into this will be using kind-projector
scalacOptions
are exposed to the rule implementation, so i believe it's possible to implement a decent heuristic to know whether kind-projector is available in the project.
would be be out of scope for this project to have an option of using kind-projector syntax for type lambdas?
Provided the potential heuristic mentioned above works, I am not sure a flag (no matter if it's opt-in or opt-out) is even necessary. When a partially-applied type is detected, we would either use kind-projector, or fallback to the anonymous type projection.