Skip to content

JEP 390: Warnings for Value-Based Classes #13196

Description

@xuwei-k

Reproduction steps

Scala version: 2.13.18

Welcome to Scala 2.13.18 (OpenJDK 64-Bit Server VM, Java 21.0.12).
Type in expressions for evaluation. Or try :help.

scala> val a = java.time.LocalDate.now()
val a: java.time.LocalDate = 2026-09-20

scala> a.synchronized(a)
val res0: java.time.LocalDate = 2026-09-20

Problem

expect warning same as Java

$ jshell
|  Welcome to JShell -- Version 21.0.12
|  For an introduction type: /help intro

jshell> var a = java.time.LocalDate.now()
a ==> 2026-09-20

jshell> int b() { synchronized(a) { return 2; } }
|  Warning:
|  attempt to synchronize on an instance of a value-based class
|  int b() { synchronized(a) { return 2; } }
|            ^---------------------------^
|  created method b()

Note

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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