Skip to content

Type inferencing fails for closure over view bound because of ETA expansion #2339

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
felixmulder opened this issue May 1, 2017 · 2 comments

Comments

@felixmulder
Copy link
Contributor

import scala.collection.mutable

case class Foo[K, V <% Ordered[V]]()
extends mutable.HashMap[K,V] {
  this.toSeq.sortWith(_._2 > _._2)
}

yields:

-- Error: local/priv.scala:5:22 ------------------------------------------------
5 |  this.toSeq.sortWith(_._2 > _._2)
  |                      ^
  |                    missing parameter type for parameter _$1, expected = ?
-- Error: local/priv.scala:5:29 ------------------------------------------------
5 |  this.toSeq.sortWith(_._2 > _._2)
  |                             ^
  |                    missing parameter type for parameter _$2, expected = ?

I think it's the ETA expansion, because when I change code so that it's annotated:

import scala.collection.mutable

case class Foo[K, V <% Ordered[V]]()
extends mutable.HashMap[K,V] {
  this.toSeq.sortWith { case ((_, v1), (_, v2) => v1 > v2 }
}

Dotty fails with:

-- Error: local/priv.scala:5:24 ------------------------------------------------
5 |  this.toSeq.sortWith { case ((_, v1), (_, v2)) => v1 > v2 }
  |                        ^
  |     missing parameter type for parameter x$1 of expanded function x$1 =>
  |       x$1 @unchecked match
  |         {
  |           case ((_, v1), (_, v2)) =>
  |             v1 > v2
  |         }, expected = ?
-- [E007] Type Mismatch Error: local/priv.scala:5:51 ---------------------------
5 |  this.toSeq.sortWith { case ((_, v1), (_, v2)) => v1 > v2 }
  |                                                   ^^
  |found:    Nothing(v1)
  |required: ?{ > : ? }
  |
  |
  |Note that implicit conversions cannot be applied because they are ambiguous;
  | both method Float2float in object Predef and method Byte2byte in object Predef convert from Nothing(v1) to ?{ > : FunProto(v2):? }
@nicolasstucki
Copy link
Contributor

Note that now we write it as

case class Foo[K, V]()(implicit conv: ImplicitConverter[V, Ordered[V]])

@smarter
Copy link
Member

smarter commented Jan 28, 2019

Already fixed, regression test in #5800.

@smarter smarter closed this as completed Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants