typelevel/kind-projector

Type Alias Bug

Closed this issue · 3 comments

The following code compiles just fine:

trait AAAA {
  type L[T] = T => T

  def foo(): Lambda[L[String]] = ??? 
  def bar(): Lambda[String => String][Int] = ???
  def fooType: String = foo()
  def barType: Int = bar()
}

In case of foo(), String is treated as java.lang.String and in case of bar() String is treated as an identifier.
I am curious what type does Kind Projector generate for foo(). Is it ({type Λ$ = String})#Λ$?

Is this intended behavior? This definitely doesn't look right.

non commented

Hi @ilinum,

I think this is a case where the documentation/errors are not as clear as they should be. The type argument to Lambda[...] is supposed to be a literal function type. Since the plugin runs before the typer, it has no idea that L[T] is really T => T. I think what should be happening is an error message, requiring you to rewrite foo as Lambda[String => String] (or Lambda[T => T]).

I'll leave this bug open try to fix this issue.

non commented

I'm also impressed that Lambda[T => T][Int] works, and is equivalent to Int. Scala doesn't normally support curried type applications, but I guess it makes sense that the plugin rewrites the first application, so the type becomes ({type Λ$[T] = T})#Λ$[Int].

non commented

Finally, to answer your question, bar's behavior is correct -- any name (including String) that is in the function argument position of a type lambda is treated as an identifier.