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

ExplicitResultTypes generate invalid code when use type lambda #1129

Open
xuwei-k opened this issue May 24, 2020 · 2 comments
Open

ExplicitResultTypes generate invalid code when use type lambda #1129

xuwei-k opened this issue May 24, 2020 · 2 comments

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented May 24, 2020

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
@bplommer
Copy link
Contributor

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?

@bjaglin
Copy link
Collaborator

bjaglin commented Nov 13, 2021

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.

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

No branches or pull requests

3 participants