Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExplicitResultTypes breaks compilation when using symbolic methods #2166

Open
dhalilov opened this issue Jan 14, 2025 · 1 comment
Open

ExplicitResultTypes breaks compilation when using symbolic methods #2166

dhalilov opened this issue Jan 14, 2025 · 1 comment

Comments

@dhalilov
Copy link

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.

@tgodzik
Copy link
Contributor

tgodzik commented Jan 14, 2025

Thanks for reporting, looks like an issue in the presentation compiler. We need to fix it upstream, but should be a quick fix.

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

No branches or pull requests

3 participants