Skip to content

Static forwarder suppressed by same-named instance method #10683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
S11001001 opened this issue Jan 8, 2018 · 1 comment
Open

Static forwarder suppressed by same-named instance method #10683

S11001001 opened this issue Jan 8, 2018 · 1 comment
Assignees
Milestone

Comments

@S11001001
Copy link

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
Copy link

hrhino commented Jan 8, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants