Skip to content

Issue with Type inference? #1036

Closed
Closed
@allanrenucci

Description

@allanrenucci

The following code snippet does not compile with Dotty but does with Scalac.

object Test {
  def second[A, B <: A](foo: A, bar: B): B = bar
  def expectString(s: String) = s

  def test = {
    second(Set.empty[String], Set.empty) map expectString
  }
}

It fails with the following error:

./tests/allan/Experiment.scala:7: error: type mismatch:
 found   : Any(s)
 required: String
    second(Set.empty[String], Set.empty) map expectString
                                             ^

It also fails to compile if second is defined as follow:

def second[A, B >: A](foo: A, bar: B): B = bar

with the following error:

./tests/allan/Experiment.scala:7: error: type mismatch:
 found   : (scala.collection.immutable.Set[String] | scala.collection.immutable.Set[Any]) @UnsafeNonvariant#A(s)
 required: String
    second(Set.empty[String], Set.empty) map expectString
                                             ^

Note that it does compile with second applied on List instead of Set:

second(List.empty[String], List.empty) map expectString

Not sure if it is a duplicate of #998

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