Skip to content

The inferred AppliedTypes from Java are not checked  #7494

Closed
@noti0na1

Description

@noti0na1

We could construct AppliedTypes from Java whose arguments do not conform to type bound. When the type is used in Dotty, it is not checked.

minimized code

S.scala

class A

class D[T >: A](v: T) {
  def getV(): T = v // ensure T is correctly inferred
}

object S {
  // J.getDS() : D[String] is inferred but not checked
  val dv: String = J.getDS().getV()
}

J.java

public class J {
  // for java, D is D<T extends Object>
  public static D<String> getDS() {
    return new D<String>("DS");
  }
}

expectation

I expected to see a type error at J.getDS() in S.scala, since String does not conform to lower bound A. However, this test passed. I also test the same code in scalac 2.13, and it also compiled.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions