Skip to content

Static forwarder suppressed by same-named instance method #10683

Open
@S11001001

Description

@S11001001

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions