Skip to content
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

Scala compiler conflicts Java field names with class / package canonical names #11788

Open
fdaca opened this issue Oct 31, 2019 · 1 comment

Comments

@fdaca
Copy link

@fdaca fdaca commented Oct 31, 2019

Test example

Foo.java

public class Foo {
    private String java;

    public java.lang.Integer test() {
        return null;
    }
}

Bar.scala

class Bar {
  def main(): Unit = {
    val bug = new Foo()
    bug.test()
  }
}

compilation result:

[error] /Users/fdaca/git/scala-bug-test/src/main/java/Foo.java:4:17: value lang is not a member of String
[error]     public java.lang.Integer test() {
[error]                 ^

Bug description

Given a mixed Java / Scala project with a Java class having both:

  • a method declaration with a canonical name of return type (e.g. public java.lang.Integer test())
  • a field with name equal to the first package of declared method return type (e.g. private String java)

Scala compiler would conflict the field identifier with package name and yield an error trying to lookup a member as if the first package was the previously declared field: value lang is not a member of String.

The same problem occurs with different identifiers: private Foo org; + public org.apache.commons.lang.CharSet getSet() would try to lookup member apache in type Foo.

Affected versions

  • 2.13.1
  • 2.12.8
  • 2.11.8
@Jasper-M

This comment has been minimized.

Copy link
Member

@Jasper-M Jasper-M commented Oct 31, 2019

A workaround (other than adding imports in your Java files): if your Java files don't depend on your Scala files you can set compileOrder := CompileOrder.JavaThenScala in sbt.

@hrhino hrhino added this to the Backlog milestone Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.