Skip to content

Incorrect overloading resolution involving parameterless method #6705

Closed
@liufengyun

Description

@liufengyun

This is encountered when working with ScalaTest test set.

minimized code

trait StringTempl {
  def mkString: String
  def mkString(x: String): String
}


object Test {
  def (x: String) shouldBe(y: String): Boolean = ???

  def test(tmpl: StringTempl): Unit = {
    tmpl.mkString shouldBe "hello"                       // error
    tmpl.mkString(", world") shouldBe "hello, world"
  }
}

The compiler reports an error:

-- [E134] Type Mismatch Error: examples/apply.scala:11:9 -----------------------
11 |    tmpl.mkString shouldBe "hello"
   |    ^^^^^^^^^^^^^
   |None of the overloaded alternatives of method mkString in trait StringTempl with types
   | (x: String): String
   | => String
   |match expected type ?{ shouldBe: ? }

expectation

The compiler should accept the code without reporting an error.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions