dotty-feature-requests icon indicating copy to clipboard operation
dotty-feature-requests copied to clipboard

Several imports of the same name should form an overloaded definition

Open rjolly opened this issue 5 years ago • 2 comments

Minimized code + Output

object A:
  def f(s: Int) = s

object B:
  def f(s: String) = s

import A.f
import B.f

println(f(1))
        ^
        Reference to f is ambiguous,
        it is both imported by name by import A.f
        and imported by name subsequently by import B.f

Expectation

The compiler should behave the same as in the code below, that is, as if the definitions above is overloaded.

object C:
  def f(s: Int) = s
  def f(s: String) = s

import C.f

println(f(1))
//1

See https://docs.oracle.com/javase/specs/jls/se15/html/jls-15.html#jls-15.12.1 for how member methods that are imported by static-import declarations are processed in Java.

rjolly avatar Oct 05 '20 08:10 rjolly

The corresponding (ambiguity) error message has been fixed in lampepfl/dotty#9834, but this did not change the overloading behavior.

b-studios avatar Oct 05 '20 09:10 b-studios

This a feature request, not a bug.

smarter avatar Oct 05 '20 09:10 smarter