scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Static forwarder suppressed by same-named instance method #10683

Open S11001001 opened 6 years ago

S11001001 commented 6 years ago

In the mixed Java/Scala below, foo’s static forwarder is created and can be invoked, but not bar, presumably because there is an instance method of the same name (though there is no ambiguity, and a similar mix of static/instance methods of same name in Java compiles).

Given source files:

// Callees.scala
package example

class Callees {
  def bar(q: Int) = 42
}

object Callees {
  def foo = ()
  def bar = ()
}
// Calls.java
package example;

class Calls {
    static {
        Callees.foo();
        Callees.bar();
    }
}

Yields on compile

[error] .../src/main/java/example/Calls.java:6:1: method bar in class example.Callees cannot be applied to given types;
[error]   required: int
[error]   found: no arguments
[error]   reason: actual and formal argument lists differ in length
[error]         Callees.bar();
[error] (compile:compileIncremental) javac returned non-zero exit code

And it compiles successfully after removing the bar instance method.

javac would not accept an instance and static method of same name like bar if they did not have different signatures as they do here, but does accept them when the signatures are different (FSVO different). This example is accepted by javac.

    static void baz() {}
    void baz(int i) {}

Here’s the javap run on the original Callees:

$ javap -cp target/scala-2.12/classes/ example.Callees
Compiled from "Callees.scala"
public class example.Callees {
  public static void foo();
  public int bar(int);
  public example.Callees();
}

Tested against Scala 2.12.4.

hrhino commented 6 years ago

I think this might be a duplicate of (or at least caused by the same underlying issue) as #7225.