Skip to content

Wrong prefix of java inner class parsed from java signature #5655

Closed
@panacekcz

Description

@panacekcz

A method in the following Java code returns an inner class of a generic class. In scalac, the type is J_1#A[String]#B[String], in dotty it is j.A[T]#B[String]:

  • the type argument of A is lost,
  • the prefix depends on the receiver of the method.

J_1.java:

public class J_1{
    public class A<T>{
        public class B<U>{}
    }
    A<String>.B<String> m(){
        J_1 j = new J_1();
        A<String> a = j.new A<>();
        A<String>.B<String> b = a.new B<>();
        return b;
    }
}

S_2.scala:

object O{
  def main(args: Array[String]) = {
    val j = new J_1
    val ab: J_1#A[String]#B[String] = j.m()
  }
}

Output:

-- [E007] Type Mismatch Error: S_2.scala:4:41 --------------
4 |    val ab: J_1#A[String]#B[String] = j.m()
  |                                      ^^^^^
  |                                      Found:    j.A[T]#B[String]
  |                                      Required: J_1#A[String]#B[String]

There seems to be a simple fix so I intend to post a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions