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

Uncurry setting the wrong type (projection instead of dependent type) #9442

Closed
scabug opened this issue Aug 22, 2015 · 5 comments
Closed

Uncurry setting the wrong type (projection instead of dependent type) #9442

scabug opened this issue Aug 22, 2015 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Aug 22, 2015

$ cat test.scala 
trait Ctx {
  trait Tree
}
trait Lst[+A] {
  def zip[A1 >: A, B](that: Lst[B]): Nothing
}
object Test {
  def foo(c: Ctx)(l: Lst[c.Tree]) = l zip l
}

$ scalac -version
Scala compiler version 2.11.8-20150821-135328-f8a6d21a49 -- Copyright 2002-2015, LAMP/EPFL

$ scalac test.scala -Xprint:uncurry
[[syntax trees at end of                   uncurry]] // test.scala
package <empty> {
  ...
  object Test extends Object {
    ...
    def foo(c: Ctx, l: Lst[Ctx#Tree]): Nothing = {
      <synthetic> val l$1: Lst[Ctx#Tree] = l.asInstanceOf[Lst[Ctx#Tree]]();
      l$1.zip[c.Tree, c.Tree](l$1)
    }
  }
}

If you look closely, the translation is incorrect:

  1. Intuitively, it should be:
<synthetic> val l$1: Lst[c.Tree] = l.asInstanceOf[Lst[c.Tree]]();

instead of

<synthetic> val l$1: Lst[Ctx#Tree] = l.asInstanceOf[Lst[Ctx#Tree]]();
  1. Then, the call to zip is incorrect. Thanks to the receiver, now of type Ctx#Tree, the first type argument should be A >: Ctx#Tree. But c.Tree <: Ctx#Tree, not the other way around.

The tree checkers don't seem to mind:

$ scalac test.scala -Ycheck:uncurry
[Now checking: uncurry]

But I can make the compiler crash with a bit of help from specialization:

$ cat test-spec.scala 
trait Ctx {
  trait Tree
}
trait Lst[+A] {
  def zip[A1 >: A, B](that: Lst[B]): Nothing
}
class C[@specialized(Int) T] {
  def moo(t: T) = {
    def foo(c: Ctx)(l: Lst[c.Tree]) = l zip l
    ???
  }
}

$ scalac test-spec.scala
test-spec.scala:9: error: type arguments [c.Tree,c.Tree] do not conform to method zip's type parameter bounds [A1 >: Ctx#Tree,B]
    def foo(c: Ctx)(l: Lst[c.Tree]) = l zip l
                                        ^
one error found

By the way, this is another one caught by the miniboxing plugin:
miniboxing/miniboxing-plugin#218

@scabug
Copy link
Author

scabug commented Aug 22, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9442?orig=1
Reporter: @VladUreche
Affected Versions: 2.10.5, 2.11.7, 2.12.0-M2
See #6443

@scabug
Copy link
Author

scabug commented Aug 22, 2015

@VladUreche said:
Related to the fix for #6443.

@scabug
Copy link
Author

scabug commented Aug 23, 2015

@paulp said:
You have the "it should be" and the "instead of" cases reversed.

@scabug
Copy link
Author

scabug commented Aug 26, 2015

@VladUreche said:
Done, thanks Paul.

@scabug
Copy link
Author

scabug commented Aug 26, 2015

@VladUreche said:
scala/scala#4704

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

2 participants