Skip to content

Cannot access Scala companion object module from Java code #15608

Closed
@WojciechMazur

Description

@WojciechMazur

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions