Skip to content

Compiler should not allow to define @volatile val  #19416

Closed
@WojciechMazur

Description

@WojciechMazur

@volatile annotation only makes sense on variables. The compiler should not allow to use this annotation on immutable val field.

Compiler version

All Scala 3 versions

Minimized code

class Foo:
  @volatile val x: Int = ???

Output

No warnings

Expectation

Give the same error as Scala 2:

./main.scala:2: error: values cannot be volatile
  @volatile val x: Int = ???
                ^

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions