Skip to content

Ambiguous overload with two structural methods with same name #11544

Closed
@bishabosha

Description

@bishabosha

Compiler version

3.0.0-RC1

Minimized code

import language.reflectiveCalls

object Foo {
  val m: ({ def foo(str: String, int: Int): Int }){ def foo(arg: Int): Int } = ???
  val m1 = m
  val n = m1.foo(23)
}

Output

-- [E051] Reference Error: tests/pos-tmp/overload-in-refined.scala:6:13 --------
6 |  val n = m1.foo(23)
  |          ^^^^^^
  |Ambiguous overload. The overloaded alternatives of method (str: String, int: Int): Int with types
  | (str: String, int: Int): Int
  | (arg: Int): Int
  |both match arguments ((23 : Int))
  |
  |Note: this happens because two or more alternatives have the same erasure,
  |      so they cannot be distinguished by overloading resolution

Explanation
===========
There are 2 methods that could be referenced as the compiler knows too little
about the expected type.
You may specify the expected type e.g. by
- assigning it to a value with a specified type, or
- adding a type ascription as in instance.myMethod: String => Int


1 error found

Expectation

edit: error with "refinements can't introduce overloads"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions