Skip to content

ambiguous reference when importing overloaded functions #2551

@scabug

Description

@scabug

When importing overloaded functions from two different objects, the compiler generates error when trying to use a function which has the same name regardless of the argument type.

Example:

object DoubleMath {
    def sin(x: Double) = 1
}

object FloatMath {
    def sin(x: String) = 1
}

class A {
    def test() {
        import DoubleMath._
        import FloatMath._

        println(sin(1.0) + sin("1"))
    }
}

Tested on 2.7.7.final and 2.7.3.final with the same result.

error: reference to sin is ambiguous;
it is imported twice in the same scope by
import FloatMath._
and import DoubleMath._
        println(sin(1.0) + sin("1"))

It would be very helpful to import overloaded functions from different objects to enable splitting large libraries into separate files and possibly shipping them in separate jars.

An example of using mass import is when doing mathematics, as you can import all the trigonometric and other standard functions with one statement.

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