Closed
Description
Compiler version
3.2.2
Minimized code
@main
def main() = {
class DoubleOps(d: Double) {
def unary_~(): Double = scala.math.ceil(d)
}
implicit def doubleOps(d: Double): DoubleOps = new DoubleOps(
d
)
println {
~(0.5) // compilation error
}
}
Output
sbt:scala3playground> compile;
[info] compiling 1 Scala source to /Users/tobita_yoshiki/work/tmp/scala3playground/target/scala-3.2.2/classes ...
[error] -- [E100] Syntax Error: /Users/tobita_yoshiki/work/tmp/scala3playground/src/main/scala/Main.scala:11:4
[error] 11 | ~(0.5)
[error] | ^^^^^^
[error] | method unary_~ in class DoubleOps must be called with () argument
[error] |
[error] | longer explanation available when compiling with `-explain`
[warn] there was 1 feature warning; re-run with -feature for details
[warn] one warning found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed 2023/04/21 23:43:07
Expectation
The compilation is successful and the following output is expected to be printed to standard output:
1.0
It has been confirmed to work with Scala 2.13.10.
// Scala 2.13.10
object Main extends App {
class DoubleOps(d: Double) {
def unary_~(): Double = scala.math.ceil(d)
}
implicit def doubleOps(d: Double): DoubleOps = new DoubleOps(
d
)
println {
~(0.5) // 1.0
}
}