scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Adding instance method causes static forwarder to disappear

Open armanbilge opened this issue 1 year ago • 3 comments

Compiler version

3.6.0-RC1-bin-20241003-a672e05-NIGHTLY

Minimized code

class Foo {
//  def bar(baz: Int): Int = ???
}

object Foo {
  def bar(baz: String): String = ???
}

Output

Before

/*
 * Decompiled with CFR 0.151.
 */
public class Foo {
    public static String bar(String string) {
        return Foo$.MODULE$.bar(string);
    }
}

After

/*
 * Decompiled with CFR 0.151.
 * 
 * Could not load the following classes:
 *  scala.Predef$
 */
import scala.Predef$;

public class Foo {
    public int bar(int baz) {
        throw Predef$.MODULE$.$qmark$qmark$qmark();
    }
}

Expectation

As far as I know the instance method and static method should be able to co-exist.

armanbilge avatar Oct 05 '24 19:10 armanbilge

No they cannot coexist. It's a JVM limitation.

sjrd avatar Oct 05 '24 19:10 sjrd

Different signatures, however.

som-snytt avatar Oct 05 '24 20:10 som-snytt

No they cannot coexist. It's a JVM limitation.

This compiles for me.

class Foo {
    public int bar(int baz) {
        return 42;
    }

    public static String bar(String baz) {
        return "static";
    }
}

armanbilge avatar Oct 05 '24 21:10 armanbilge