Skip to content

Unexpected compilation error while calling Scala from Java #12556

Closed
@anthony-cros

Description

@anthony-cros

Reproduction steps

Scala version: 2.13.8 (also in 2.12.x)

// $ cat Bar.scala:

trait Bar[F] {
          def f  : F
    final def bar: F = f // the real life example is more involved here
}

// ==================================================
//$ cat Foo.scala:

class Foo() extends Bar[Foo] {
    override def f: Foo = this
}


// ==================================================
//$ cat Baz.java:

class Baz {
    public static void main(String args[]) {
    //  Foo foo =       new Foo().bar();  // compilation error: incompatible types: Object cannot be converted to Foo
        Foo foo = (Foo)(new Foo().bar()); // compiles
    }
}

Problem

See more details on Scala Users: https://users.scala-lang.org/t/issue-with-calling-scala-code-from-java/8321

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