Deprecated procedure syntax: def with a body but no '=' and no result type
ID |
scala.maintainability.procedure_syntax |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Deprecated Api |
Language |
Scala |
Description
Reports a method declared as def name(args) { … }, the procedure syntax that omits both the result type and the =. It was deprecated in Scala 2.13 and removed in Scala 3.
Rationale
The form does not survive a move to Scala 3, so every occurrence is migration work waiting to happen. It also hides an easy mistake: the body’s value is discarded and the method returns Unit, so a body that ends in a useful expression silently throws that value away, and the omitted = is a single character away from a method that would have returned it.
The following code illustrates the pattern detected by this rule:
class Sink {
def write(line: String): Unit = ()
def count: Int = 0
}
class Reporter(sink: Sink) {
// FLAGGED: Deprecated procedure syntax: def with a body but no '=' and no result type
def flush() {
sink.write("flush")
}
}