Skip to content

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

@felixmulder

Description

@felixmulder
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):? }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions