Skip to content

Java and Scala compilers treat records differently, Scala compiler not exposing accessor methods #19386

Closed
@ek-gh

Description

@ek-gh

Compiler version

3.3.1

Minimized code

MyRecord.java:

public record MyJavaRecord(String name, Integer age) {}

MyTest.scala

object MyScalaObject {
  @main def test(): Unit = {
    val javaRecord = new MyJavaRecord("Name", 50)
    println(javaRecord.name())
    println(javaRecord.age)
  }
}

If MyJavaRecord is compiled with java compiler, and MyScalaObject is compiled with scala compiler using class file generated by Java compiler for the record, you'd get no syntax errors from scala compiler.

If MyJavaRecord & MyScalaObject are both compiled with scala compiler, first println would give you syntax error.

Expectation

When record is compiled via Scala compiler, it exposes accessor methods to the fields just like Java compiler. We should get no errors compiling both with scala compiler. Scala compiler should not enforce a syntax for java data type that is illegal by java compiler.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions