Skip to content

Cannot access Scala companion object module from Java code #15608

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
WojciechMazur opened this issue Jul 7, 2022 · 3 comments · Fixed by #15617
Closed

Cannot access Scala companion object module from Java code #15608

WojciechMazur opened this issue Jul 7, 2022 · 3 comments · Fixed by #15617
Labels
compat:java itype:bug prio:high regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Jul 7, 2022

Community build regression for https://github.com/outr/scribe (maintainer @darkfrog26)
Based on https://scala3.westeurope.cloudapp.azure.com/blue/organizations/jenkins/buildCommunityProject/detail/buildCommunityProject/572/pipeline/

Compiler version

Fails in 3.2.0-RC1
Fails with 3.2.1-RC1-bin-20220706-9d07d52-NIGHTLY
Works with 3.1.3

Minimized code

The snippet seems to be running correctly when using scalac + javac directly, however it fails in build-tools, eg. scala-cli used to reproduce this issue or sbt in the mentioned project

package bar.slf4j

trait MDCAdapter

object ScalaMDCAdapter extends MDCAdapter {
}
package foo.slf4j.impl;

import bar.slf4j.MDCAdapter;
import bar.slf4j.ScalaMDCAdapter;
import bar.slf4j.ScalaMDCAdapter$;

public class JavaMDCBinder {
    public static final JavaMDCBinder SINGLETON = new JavaMDCBinder();

    private JavaMDCBinder() {
    }

    public MDCAdapter getMDCA() {
        return ScalaMDCAdapter$.MODULE$;
    }

    public String getMDCAdapterClassStr() {
        return ScalaMDCAdapter.class.getName();
    }
}

Output

Compiling project (Scala 3.2.1-RC1-bin-20220706-9d07d52-NIGHTLY, JVM)
[error] ./JavaMDCBinder.java:5:18: value ScalaMDCAdapter is not a member of bar.slf4j - did you mean slf4j.ScalaMDCAdapter?
[error] import bar.slf4j.ScalaMDCAdapter$;
[error]                  ^
Error compiling project (Scala 3.2.1-RC1-bin-20220706-9d07d52-NIGHTLY, JVM)

Expectation

@WojciechMazur WojciechMazur added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 7, 2022
@rochala rochala added compat:java regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 7, 2022
@Kordyjan Kordyjan added this to the 3.2.0 backports milestone Jul 7, 2022
@darkfrog26
Copy link

Please let me know if there is a change that needs to be made to Scribe to support this.

@griggt
Copy link
Contributor

griggt commented Jul 7, 2022

Fails in 3.2.0-RC1

Hmmm, it works for me with 3.2.0-RC1, but fails on more recent nightlies.

The snippet seems to be running correctly when using scalac + javac directly, however it fails in build-tools, eg. scala-cli used to reproduce this issue or sbt in the mentioned project

I was able to reproduce without a build tool by running scalac JavaMDCBinder.java ScalaMDCAdapter.scala, javac not required.

@griggt
Copy link
Contributor

griggt commented Jul 7, 2022

Regressed in #15477

odersky added a commit to dotty-staging/dotty that referenced this issue Jul 8, 2022
Moving import selector checking from PostTyper to Typer had the
side-effect that they were also checked in Java code. But that does
not work since the Java files are compiled before the Scala files
so the selected reference has not been seen yet.

Fixed by disabling import selector checks for Java files.

Fixes scala#15608
@Kordyjan Kordyjan modified the milestones: 3.2.0 backports, 3.2.1 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat:java itype:bug prio:high regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants