Skip to content

Java source dependency with inner class type is incorrectly typed as static selection #19619

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

Closed
bishabosha opened this issue Feb 5, 2024 · 0 comments · Fixed by #19747
Closed

Comments

@bishabosha
Copy link
Member

bishabosha commented Feb 5, 2024

Compiler version

3.4.0-RC4

Minimized code

cs launch scalac:3.4.0-RC4 -- InnerClass.java RawTypes.java TestInnerClasses.scala TestRawTypes.scala

// InnerClass.java

package lib;

public class InnerClass {

  public class Inner<U> {
    public U innerField;

    public Inner(U innerField) {
      this.innerField = innerField;
    }

    public U getInnerField() { return innerField; }
  }

  public <U> Inner<U> createInner(U innerField) {
    return new Inner<>(innerField);
  }

  public static <U> InnerClass.Inner<U> createInnerStatic(U innerField) {
    var innerClass = new InnerClass();
    return innerClass.new Inner<>(innerField);
  }

}
// RawTypes.java

package lib;

public class RawTypes {

  public class C<T> {
    public class D<U> {}
  }

  public static void mii_Raw_Raw(C.D d) {}

}
// TestInnerClasses.scala

import lib.InnerClass

object testInnerClasses extends scala.App {
  val ici: InnerClass = new InnerClass()
  val ici_inner1: ici.Inner[Long] = ici.createInner[Long](47L) // ok, but should error
  val ici_inner2: InnerClass#Inner[Long] = ici.createInner[Long](47L)
  val ici_inner3: InnerClass#Inner[Long] = InnerClass.createInnerStatic[Long](47L) // error
}
// TestRawTypes.scala

package tastytest

import lib.RawTypes

object TestRawTypes extends scala.App {
  val rt: RawTypes = new RawTypes()
  val c: RawTypes#C[String] = new rt.C[String]()

  val cd_ii: RawTypes#C[String]#D[String] = new c.D[String]()

  RawTypes.mii_Raw_Raw(cd_ii) // error
}

Output

-- [E007] Type Mismatch Error: TestInnerClasses.scala:7:77 ---------------------
4 |  val ici_inner3: InnerClass#Inner[Long] = InnerClass.createInnerStatic[Long](47L)  // error
  |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                                      Found:    lib.InnerClass.Inner[Long]
  |                                      Required: lib.InnerClass#Inner[Long]
  |
  | longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: TestRawTypes.scala:11:23 ------------------------
11 |  RawTypes.mii_Raw_Raw(cd_ii)
   |                       ^^^^^
   |Found:    (tastytest.TestRawTypes.cd_ii : lib.RawTypes#C[String]#D[String])
   |Required: lib.RawTypes.C.D[?]
   |
   | longer explanation available when compiling with `-explain`
2 errors found

Expectation

ici_inner1 should fail to type because from java classfiles it doesn't work. (more forgivable because scala 2 has same behavior)

ici_inner3 should be correctly typed (as when reading from class files), It is incorrectly typed as a static selection of lib.InnerClass.Inner[Long] when it should be lib.InnerClass#Inner[Long] as when reading from class files

mii_Raw_Raw(cd_ii) should be correctly typed (as when reading from class files), It is incorrectly typed as a static selection of lib.RawTypes.C.D[?] when it should be lib.RawTypes#C#D[?] as when reading from class files

@bishabosha bishabosha added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label compat:java area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 5, 2024
@bishabosha bishabosha self-assigned this Feb 5, 2024
@bishabosha bishabosha changed the title Java source dependency with inner class in signature is incorrect Java source dependency with inner class type is incorrectly typed as static selection Feb 7, 2024
bishabosha added a commit that referenced this issue Feb 22, 2024
…9747)

Tests changes against source dependency, Tasty dependency, and class
dependency.

fixes #19619
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants