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

Incomplete substitution of type parameters in extension methods #11383

Open
joroKr21 opened this Issue Jan 29, 2019 · 1 comment

Comments

Projects
None yet
4 participants
@joroKr21
Copy link

joroKr21 commented Jan 29, 2019

This occurs when combining AnyVal extension methods and the Aux pattern for dependent types.

trait DepFn[A] { type B; def apply(a: A): B }
object DepFn { type Aux[A, C] = DepFn[A] { type B = C } }
class Syntax(val i: Int) extends AnyVal {
  def foo[A](e: Either[Int => A, DepFn.Aux[Int, A]]) = e.fold(_(i), _(i))
}

// Exiting paste mode, now interpreting.

  def foo[A](e: Either[Int => A, DepFn.Aux[Int, A]]) = e.fold(_(i), _(i))
                                                                     ^
<pastie>:4: error: type mismatch;
 found   : A
 required: A(in method foo$extension)

Note that surprisingly this compiles (the only difference is a type ascription):

class Syntax(val i: Int) extends AnyVal {
  def foo[A](e: Either[Int => A, DepFn.Aux[Int, A]]) = e.fold(_(i), _(i): A)
}

// Exiting paste mode, now interpreting.

defined class Syntax

And now the punchline (try it with a List[A]):

class Syntax(val i: Int) extends AnyVal {
  def foo[A](e: Either[Int => List[A], DepFn.Aux[Int, List[A]]]) = e.fold(_(i), _(i))
}

// Exiting paste mode, now interpreting.

  def foo[A](e: Either[Int => List[A], DepFn.Aux[Int, List[A]]]) = e.fold(_(i), _(i))
                                                                                 ^
<pastie>:4: error: type mismatch;
 found   : List[A]
 required: List[A]

huh? At this point the compiler looks silly 😆

@milessabin

This comment has been minimized.

Copy link

milessabin commented Jan 29, 2019

Works in Dotty.

@SethTisue SethTisue added this to the Backlog milestone Jan 29, 2019

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