Skip to content

SAM types don't support type bounds #2732

Closed
@Arthurm1

Description

@Arthurm1

The following compiles in Scala but fails in Dotty (using Scastie)

object Foo {
  val map = new java.util.HashMap[String, String]
  map.computeIfAbsent("hello", foo => "world")
}
-- Error: /tmp/scastie5756006742801572629/src/main/scala/main.scala:5:31 -------
5 |  map.computeIfAbsent("hello", foo => "world")
  |                               ^^^
  |                    missing parameter type for parameter foo, expected = ?
-- [E007] Type Mismatch Error: /tmp/scastie5756006742801572629/src/main/scala/main.scala:5:38 
5 |  map.computeIfAbsent("hello", foo => "world")
  |                                      ^^^^^^^
  |         found:    String("world")
  |         required: java.util.function.Function[_ >: String, _ <: String]#R         

trying

object Foo {
  val map = new java.util.HashMap[String, String]
  map.computeIfAbsent("hello", (foo: String) => "world")
}

still results in the second error

-- [E007] Type Mismatch Error: /tmp/scastie5756006742801572629/src/main/scala/main.scala:5:48 
5 |  map.computeIfAbsent("hello", (foo: String) => "world")
  |                                                ^^^^^^^
  |         found:    String("world")
  |         required: java.util.function.Function[_ >: String, _ <: String]#R
  |         

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions