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

regression in type inference #7226

Closed
scabug opened this issue Mar 7, 2013 · 8 comments
Closed

regression in type inference #7226

scabug opened this issue Mar 7, 2013 · 8 comments

Comments

@scabug
Copy link

@scabug scabug commented Mar 7, 2013

Compiles in 2.9.2, not in 2.10.0.

trait HK {
  type Rep[A]
  def unzip1[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[A]], Rep[C[B]])
  def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1(ps)
}
./a.scala:7: error: type mismatch;
 found   : HK.this.Rep[List[(A, B(in method doUnzip1))]]
 required: HK.this.Rep[List[((A, B(in method doUnzip1)), B(in method unzip1))]]
  def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1(ps)
                                                     ^
one error found

The commit in which it regressed is scala/scala@0cde930 ; I don't yet see how.

@scabug
Copy link
Author

@scabug scabug commented Mar 7, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7226?orig=1
Reporter: @paulp
Affected Versions: 2.10.0

@scabug
Copy link
Author

@scabug scabug commented Mar 8, 2013

@retronym said:
Some variations:

trait HK {
  type Rep[X]

  // okay
  def unzip2[A, B](ps: Rep[List[(A, B)]])
  unzip2(null.asInstanceOf[Rep[List[(Int, String)]]])

  // okay
  def unzipHK[A, B, C[_]](ps: Rep[C[(A, B)]])
  unzipHK(null.asInstanceOf[Rep[List[(Int, String)]]])

  // fail
  def unzipHKRet[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[A]], Rep[C[B]])
  unzipHKRet(null.asInstanceOf[Rep[List[(Int, String)]]])
}

@scabug
Copy link
Author

@scabug scabug commented Mar 8, 2013

@adriaanm said:
As alluded by Jason's okay<>fail/unzipHK<>unzipHKRet, it looks like unzip1's return type is driving inference:

defining (note the existentials in the return type)

  def unzip1[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[_]], Rep[C[_]])

results in the inferred:

    def doUnzip1[T1 >: Nothing <: Any, T2 >: Nothing <: Any](ps: HK.this.Rep[List[(T1, T2)]]): (HK.this.Rep[List[_]], HK.this.Rep[List[_]]) = HK.this.unzip1[T1, T2, List](ps)

@scabug
Copy link
Author

@scabug scabug commented Mar 9, 2013

@paulp said (edited on Mar 9, 2013 4:20:15 AM UTC):
Before the commit in question:

% ./working/bin/scalac -Yinfer-debug -d /tmp /scala/trunk/test/files/pos/t7226.scala 
[solve types] solving for A, B, C in ?A, ?B, ?C
[infer method] solving for A, B, C in (ps: HK.this.Rep[C[(A, B)]])(HK.this.Rep[C[A]], HK.this.Rep[C[B]])
  based on (HK.this.Rep[List[(T1, T2)]])(HK.this.Rep[C[A]], HK.this.Rep[C[B]])
  (solved: A=T1, B=T2, C=List)

After:

% scalac3 -Yinfer-debug -d /tmp /scala/trunk/test/files/pos/t7226.scala 
[solve types] solving for A, B, C in ?A, ?B, ?C
[infer method] solving for A, B, C in (ps: HK.this.Rep[C[(A, B)]])(HK.this.Rep[C[A]], HK.this.Rep[C[B]])
  based on (HK.this.Rep[List[(T1, T2)]])(HK.this.Rep[C[A]], HK.this.Rep[C[B]])
  (solved: A=(T1, T2), C=List)

@scabug
Copy link
Author

@scabug scabug commented Mar 9, 2013

@retronym said:
The bug stems from making (the mutable) TypeVar a case class. Seems a pretty serious regression, I'd consider this for 2.10.1.

@scabug
Copy link
Author

@scabug scabug commented Mar 9, 2013

@scabug
Copy link
Author

@scabug scabug commented Mar 9, 2013

@paulp said:
Oh, because it picked up case class equality. Shoot, I didn't think of that.

I believe 2.10.2 is the earliest which can be considered. This has been in there 7 months, and it's in 2.10.0 - and it's not a risk-free fix.

@scabug
Copy link
Author

@scabug scabug commented Mar 12, 2013

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

Successfully merging a pull request may close this issue.

None yet
2 participants