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

Incomplete substitution of type parameters in extension methods #11383

Open
joroKr21 opened this issue Jan 29, 2019 · 5 comments · Fixed by scala/scala#9172
Open

Incomplete substitution of type parameters in extension methods #11383

joroKr21 opened this issue Jan 29, 2019 · 5 comments · Fixed by scala/scala#9172
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer valueclass
Milestone

Comments

@joroKr21
Copy link
Member

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
Copy link

Works in Dotty.

@smarter smarter added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Jan 29, 2019
@SethTisue SethTisue added this to the Backlog milestone Jan 29, 2019
@joroKr21
Copy link
Member Author

The problem is that the second _(i) is typed as B where B is a type alias to A in foo. substituteSymbols is supposed to substitute A in foo with A in foo$extension but it does not follow the type alias. What should happen?

@joroKr21
Copy link
Member Author

Maybe same issue as #9222?

@hrhino
Copy link

hrhino commented May 3, 2019

Found this today, which I suspect is a similar cause:

trait R[T] { def toX[U >: T]: X[U] }
trait X[A]
class Lose(val dumbo: Int) extends AnyVal {
  def fail[Q](foo: R[_ <: Q]): X[Q] = foo.toX
}

in which the Q in foo's type in fail$extension apparently doesn't get updated to point at the extension method's type parameter.

@dwijnand
Copy link
Member

Reverted

@dwijnand dwijnand reopened this Oct 14, 2020
@SethTisue SethTisue modified the milestones: 2.13.4, Backlog Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer valueclass
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants