Skip to content

No generic signature emitted for def in object #8631

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

Closed
ohze opened this issue Mar 29, 2020 · 2 comments
Closed

No generic signature emitted for def in object #8631

ohze opened this issue Mar 29, 2020 · 2 comments

Comments

@ohze
Copy link

ohze commented Mar 29, 2020

minimized code

  • scala
import java.util.function.{Function => JFunction}

class Behavior[T]
class BehaviorBuilder[T] {
  def onMessage(handler: JFunction[T, Behavior[T]]): BehaviorBuilder[T] = ???
}
object Behaviors {
  def same[T]: Behavior[T] = ???
}
  • BehaviorTestKitTest.java
class BehaviorTestKitTest {
    static class X {
        void foo(){}
    }
    void test() {
        BehaviorBuilder<X> b = null;
        b.onMessage(
            x -> {
                x.foo();
                return Behaviors.same();
            })
        .onMessage(
            x -> {
                x.foo(); // error here
                return Behaviors.same();
            });
    }
}

Compilation output

[error] /dotty-example/src/main/java/BehaviorTestKitTest.java:14:1: cannot find symbol
[error]   symbol:   method foo()
[error]   location: variable x of type java.lang.Object
[error] x.foo
[info] /dotty-example/src/main/java/BehaviorTestKitTest.java: /dotty-example/src/main/java/BehaviorTestKitTest.java uses unchecked or unsafe operations.

expectation

compile successfully as in scala 2

inspect

Decompile Behaviors.class using Procyon v0.5.36:

  • dotty's output:
public final class Behaviors {
    public static Behavior same() {
        return Behaviors$.MODULE$.same();
    }
}
  • scala 2.13.1 output:
public final class Behaviors {
    public static <T> Behavior<T> same() {
        return Behaviors$.MODULE$.same();
    }
}

Notice the lack of generic signature on same() method.

maybe relate: #6350

@ohze ohze added the itype:bug label Mar 29, 2020
giabao added a commit to ohze/akka that referenced this issue Mar 31, 2020
giabao added a commit to ohze/akka that referenced this issue Mar 31, 2020
giabao added a commit to ohze/akka that referenced this issue Apr 2, 2020
giabao added a commit to ohze/akka that referenced this issue Apr 5, 2020
@odersky
Copy link
Contributor

odersky commented Apr 5, 2020

The issue here is that the Dotty backend does not demand a generic signature for forwarders. Both scalac and dotc generate a static signature for same in the object class Bahavior$. But only scalac generates a static signature for the static forwarder of same in class Bahavior.

I verified that the BCode backend simply never makes the call to demand a signature for the forwarder. Hopefully this will be fixed once we switch to scalac's backend. Assigning to @lrytz for tracking this.

giabao added a commit to ohze/akka that referenced this issue Apr 6, 2020
giabao added a commit to ohze/akka that referenced this issue Apr 7, 2020
giabao added a commit to ohze/akka that referenced this issue Apr 7, 2020
giabao added a commit to ohze/akka that referenced this issue Apr 9, 2020
giabao added a commit to ohze/akka that referenced this issue Apr 9, 2020
@smarter
Copy link
Member

smarter commented Nov 16, 2020

Closing as a duplicate of #10347 where I provided a workaround: #10347 (comment)

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

5 participants