Skip to content

Argument identity lost preventing follow-up dependently-typed argument #11955

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
japgolly opened this issue Mar 31, 2021 · 2 comments · Fixed by #12159
Closed

Argument identity lost preventing follow-up dependently-typed argument #11955

japgolly opened this issue Mar 31, 2021 · 2 comments · Fixed by #12159

Comments

@japgolly
Copy link
Contributor

Compiler version

3.0.0-RC1

Minimized code

object Hello {

  sealed abstract class X[+A] {
    type This[+A] <: X[A]
    def asThis: This[A]
  }

  class Y[+A] extends X[A] {
    override type This[+AA] = Y[AA]
    override def asThis: This[A] = this
  }

  def hackBackToSelf[F[+u] <: X[u], A](f: F[Any])(f2: f.This[A]): F[A] =
    f2.asInstanceOf[F[A]]

  case class G[F[+u] <: X[u], A](wrapped: F[A]) {

    def mapF[F2[+u] <: X[u]](f: F[A] => F2[A]): G[F2, A] =
      G[F2, A](f(wrapped))

    def test_ko_1: G[F, A] = mapF(ct => hackBackToSelf(ct)(ct.asThis)) // error
    def test_ko_2: G[F, A] = mapF[F](ct => hackBackToSelf(ct)(ct.asThis)) // error
    def test_ok  : G[F, A] = mapF(ct => hackBackToSelf[F, A](ct)(ct.asThis)) // ok
  }
}

Output

-- [E007] Type Mismatch Error: x.scala:21:62 -----------------------------------
21 |    def test_ko_1: G[F, A] = mapF(ct => hackBackToSelf(ct)(ct.asThis)) // error
   |                                                           ^^^^^^^^^
   |                         Found:    ct.This[A]
   |                         Required: ?1.This[A]
   |
   |                         where:    ?1 is an unknown value of type F[Any]
-- [E007] Type Mismatch Error: x.scala:22:65 -----------------------------------
22 |    def test_ko_2: G[F, A] = mapF[F](ct => hackBackToSelf(ct)(ct.asThis)) // error
   |                                                              ^^^^^^^^^
   |                         Found:    ct.This[A]
   |                         Required: ?2.This[A]
   |
   |                         where:    ?2 is an unknown value of type F[Any]
2 errors found

Expectation

It should compile. It does with Scala 2.x.

@abgruszecki
Copy link
Contributor

Possibly related to #11220?

@odersky
Copy link
Contributor

odersky commented Apr 3, 2021

It does look related. There's an asInstanceOf[F[Any]] inserted before it goes wrong.

odersky added a commit to dotty-staging/dotty that referenced this issue Apr 5, 2021
 - keep the singleton type in the cast target
 - assert cast target stability if original was stable
 - fix isStable test for TypeParamRefs
 - double check if GADT logic is really needed before inserting a cast

Fixes scala#11220
Fixes scala#11955
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants