Closed
Description
Hi folks,
ExplicitResultTypes
doesn't seem to work correctly when the def/val uses symbols, as it inserts :
right next to the symbol, which fools the Scala parser. Adding a space before the :
should resolve the issue.
I'm not sure if this is part of the known limitations mentionned in the documentation page, as I haven't found an issue describing the problem.
How to reproduce
Here is a minimal example, using Scala 3.5.2 and sbt 1.10.7.
src/main/scala/Main.scala
:
object A {
// Using the non-trivial example from the documentation to make sure that ExplicitResultsType kicks in
def ! = 1.to(10).map(i => i -> i.toString()).toMap
}
@main def main(): Unit =
println(A.!)
build.sbt
:
lazy val root = project
.in(file("."))
.settings(
scalaVersion := "3.5.2",
semanticdbEnabled := true
)
project/plugins.sbt
:
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")
.scalafix.conf
:
rules = [
ExplicitResultTypes
]
Running sbt scalafix
produces the following line:
def !: Map[Int, String] = 1.to(10).map(i => i -> i.toString()).toMap
which fails to compile. The following version:
def ! : Map[Int, String] = 1.to(10).map(i => i -> i.toString()).toMap
would compile correctly.