Skip to content

Companion object cannot be found from Java in Scala 3, but it compiles in Scala 2.x. #17255

Closed
@i10416

Description

@i10416

Compiler version

3.0.2, 3.1.3, 3.2.2, 3.3.0-RC3

Minimized code

https://github.com/i10416/reproduce-missing-symbol-error-in-scala-3

The following code compiles in Scala 2.x, but won't compile in Scala 3.x for "Not found: type Foo".

src/main/java/Bar.java

package example;

import example.Foo$;

public class Bar {
	// this compiles in Scala 2.x, but won't compile in Scala 3
	private static final Foo$ MOD = Foo$.MODULE$;
}

src/main/scala/Foo.scala

package example

case class Foo(i: Int)

object Foo

Output

error] -- [E006] Not Found Error: /path/to/src/main/java/Bar.java:7:21 
[error] 7 |     private static final Foo$ MOD = Foo$.MODULE$;
[error]   |                          ^^^^
[error]   |                          Not found: type Foo
[error]   |

Expectation

It should compile. Or is this expected behavior?

Note

It compiles in Scala 3 when you explicitly specify compileOrder := CompileOrder.ScalaThenJava. However, if there are both Scala code depending on Java and Java code depending Scala, you have no choice but CompileOrder.Mixed.

Notably, even if there are both Scala code depending on Java and Java code depending Scala, Scala 2.x can compile them (in CompileOrder.Mixed mode).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions