Skip to content

Structural types which specify concrete versions of generic methods can lead to runtime failures #2672

@scabug

Description

@scabug

This is extracted from the later comments of ticket #2144, which was otherwise addressed.

object Test {
  class MyGraph[V <: Any] {
    def addVertex(v: V): Boolean = true
  }

  type DuckGraph = {
    def addVertex(vertex: Int): Boolean
  }
  
  def fail(graph: DuckGraph) = graph addVertex 1

  def main(args: Array[String]): Unit = {
    fail(new MyGraph[Int])
  }
}
$$ scala Test
java.lang.NoSuchMethodException: Test$$MyGraph.addVertex(int)

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)help wantedstructural types

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions