Skip to content

IndexOutOfBoundsException and java.lang.Error: internal error in compiler while trying to merge implicit function signatures #4668

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

Closed
LPTK opened this issue Jun 15, 2018 · 3 comments

Comments

@LPTK
Copy link
Contributor

LPTK commented Jun 15, 2018

Discovered in #2500 (comment). This code:

trait Type { type T }
object Type { implicit def Type[S]: Type { type T = S } = new Type { type T = S } }

trait Type1 { type T[_] }
object Type1 { implicit def Type1[S[_]]: Type1 { type T[A] = S[A] } = new Type1 { type T[A] = S[A] } }

trait Functor[F[_]] { def map[A,B](x: F[A])(f: A => B): F[B] }
object Functor { implicit object listFun extends Functor[List] { def map[A,B](ls: List[A])(f: A => B) = ls.map(f) } }

val map: implicit (A:Type,B:Type,F:Type1) => implicit (Functor[F.T]) => (F.T[A.T]) => (A.T => B.T) => F.T[B.T] =
  implicit fun => x => f => fun.map(x)(f)

crashes the compiler with:

java.lang.IndexOutOfBoundsException: 2

Not sure if it should be in a separate issue, but this version:

val map: implicit (A:Type,B:Type,F:Type1,fun:Functor[F.T]) => (F.T[A.T]) => (A.T => B.T) => F.T[B.T] =
  implicit (A:Type,B:Type,F:Type1,fun:Functor[F.T]) => x => f => fun.map(x)(f)

crashes the compiler with:

java.lang.Error: internal error: cannot turn method type (implicit A: Type, B: Type, F: Type1, fun: Functor[F.T]): 
  <error missing parameter type
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type: ?
Missing type for parameter x>
 => Any => Any => F.T[Any] into closure
because it has internal parameter dependencies,
position = <1409..1409>, raw type = MethodType(List(A, B, F, fun), ...
@LPTK
Copy link
Contributor Author

LPTK commented Mar 9, 2020

@anatoliykmetyuk why is the test you added an error? The parameter types should be correctly inferred, since the full expected type is provided. Shouldn't an issue be open about that?

It does not work even when we fully specify the types of the givens:

val map: (A:Type,B:Type,F:Type1) ?=>  (Functor[F.T]) ?=> (F.T[A.T]) => (A.T => B.T) => F.T[B.T] =
  (A:Type,B:Type,F:Type1) ?=> (fun:Functor[F.T]) ?=> x => f => fun.map(x)(f)

@anatoliykmetyuk
Copy link
Contributor

@anatoliykmetyuk why is the test you added an error? The parameter types should be correctly inferred, since the full expected type is provided. Shouldn't an issue be open about that? It does not work even when we fully specify the types of the givens:

/cc @nicolasstucki

@nicolasstucki
Copy link
Contributor

The issue was a bug in the comiler internals which is fixed. If you want better inference create another issue for it. Though we might already have some issues that cover this.

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

4 participants