Skip to content

Unable to find class in inherited scope #12566

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
thesamet opened this issue May 22, 2021 · 7 comments
Closed

Unable to find class in inherited scope #12566

thesamet opened this issue May 22, 2021 · 7 comments

Comments

@thesamet
Copy link

thesamet commented May 22, 2021

Compiler version

Using Scala 3.0.0, I am unable to compile Java code that is generated by protoc (protobuf compiler). The following is a minimized version of the generated code to demonstrate the issue.

Minimized code

// src/main/java/mytest/Ex.java
package mytest;

public final class Ex {
  private Ex() {}

  public static final class Foo extends MyInterface {
    private Foo() {
    }

    @SuppressWarnings({"unused"})
    protected java.lang.Object newInstance(
        UnusedPrivateParameter unused) {
      return new Foo();
    }
  }
}
// src/main/java/mytest/MyInterface.java
package mytest;

public class MyInterface {
    public static final class UnusedPrivateParameter {};
}

The Scala code doesn't matter, but it needs to exist:

// src/main/scala/Main.scala
package foo

object Main {}

Output

sbt:ppp> compile
[info] compiling 1 Scala source and 2 Java sources to /tmp/ppp/target/scala-3.0.0/classes ...
[error] -- [E006] Not Found Error: /tmp/ppp/src/main/java/mytest/Ex.java:12:8 ----------
[error] 12 |        UnusedPrivateParameter unused) {
[error]    |        ^^^^^^^^^^^^^^^^^^^^^^
[error]    |        Not found: type UnusedPrivateParameter
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 3 s, completed May 22, 2021, 10:36:18 AM

Expectation

Should compile with no errors.

Workaround

Adding compileOrder := CompileOrder.JavaThenScala results in successful compilation.

@som-snytt
Copy link
Contributor

Scala 2 works, presumably due to fixes to looking up Java-defined members in Java sources.

The previous behavior was that statics belong to companions in the Scala language model and are not inherited.

@dylemma
Copy link
Contributor

dylemma commented May 23, 2021

(don't mind me, I typo'd the number of the issue I was trying to reference with that PR)

@odersky
Copy link
Contributor

odersky commented May 23, 2021

It would be good to know when and how this was fixed in Scala 2. The normal behavior is that UnusedPrivateMember is not visible, so there must be a hack to make it visible for Java compiled code.

@som-snytt
Copy link
Contributor

Perhaps

scala/scala#7671

with terms

is:pr author:retronym is:closed java lookup

@odersky
Copy link
Contributor

odersky commented May 23, 2021

@som-snytt That looks like the probaby fix, yes. Maybe we can get a volunteer to forward port it?

@smarter
Copy link
Member

smarter commented May 23, 2021

Closing as a duplicate of #6138 then

@smarter smarter closed this as completed May 23, 2021
@som-snytt
Copy link
Contributor

OK I see someone is already looking into the other ticket. Oh wait, that was 2019. OSS is hard.

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