Skip to content

Java parser/typer rejects import of Java inner class #7675

Open
@scabug

Description

@scabug

If you have Scala code with an inner class and attempt to use a wildcard import in Java so that you can use that class name unqualified, the Scala compiler will give an error when reading in that Java source.

Here is an example:

// scalapkg/Main.scala
package scalapkg

import javapkg.JavaClass

object Main extends App {
  println(new JavaClass().num)
}

class SomeScala {
  class InnerClass
}
// javapkg/JavaClass.java
package javapkg;

import scalapkg.SomeScala.*;

public class JavaClass {
    public int num = 1;
    InnerClass inner = null;
}

Compile with:

dnadolny@donny-desktop:~/tools/scala-2.10.2/bin$ ./scalac  javapkg/*.java scalapkg/*.scala
javapkg/JavaClass.java:3: error: object SomeScala is not a member of package scalapkg
Note: class SomeScala exists, but it has no companion object.
import scalapkg.SomeScala.*;
       ^
one error found

This is valid Java code, and would work if SomeScala was compiled first, then JavaClass compiled depending on the SomeScala*.class files.

A workaround is using the partially qualified name "SomeScala.Inner" rather than "Inner"

(This came up on the mailing list, https://groups.google.com/forum/#!topic/scala-ide-user/zkGaA_-uig8 )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions