Skip to content

Call to nullary method in generic java class is inferred as the generic type #24631

@mrdziuban

Description

@mrdziuban

Compiler version

3.8.0-RC1, 3.8.0-RC2, and latest nightly 3.8.1-RC1-bin-20251202-9eb843d-NIGHTLY

Minimized code

Put the two files below in a directory, cd into it, and run scala-cli compile .

TestJava.java

package example;

public abstract class TestJava<T> {
  public abstract T create(String foo);

  // Note that this is the method that's called from Scala code
  public T create() { return create(""); }

  public static class Concrete extends TestJava<String> {
    @Override public String create(String foo) { return foo; }
  }
}

TestScala.scala

//> using scala 3.8.1-RC1-bin-20251202-9eb843d-NIGHTLY

val s = new example.TestJava.Concrete().create
val s2: String = s

Output

[error] ./TestScala.scala:3:18
[error] Found:    (s : T)
[error] Required: String
[error] val s2: String = s

Expectation

val s should be typed as a String since Concrete#create returns one. Interesting things to note:

  1. If I call create as create(), then the type is inferred correctly as String
  2. If I annotate it as val s: String, then the type is correct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions