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 · 5 comments
Open

ExplicitResultTypes breaks compilation when using symbolic methods #2166

dhalilov opened this issue Jan 14, 2025 · 5 comments

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.

@bjaglin
Copy link
Collaborator

bjaglin commented Jan 31, 2025

Supposedly fixed in the latest dotty snapshot thanks to scala/scala3#22485. It won't be backported to 3.5.x since it's EOL (and we follow the minor version of the sources to pick the presentation compiler), so I am afraid you will have to bump to 3.6.4 (assuming it does get in there - I am not familiar with the release/branching strategy).

@dhalilov
Copy link
Author

dhalilov commented Feb 2, 2025

Supposedly fixed in the latest dotty snapshot thanks to scala/scala3#22485. It won't be backported to 3.5.x since it's EOL (and we follow the minor version of the sources to pick the presentation compiler), so I am afraid you will have to bump to 3.6.4 (assuming it does get in there - I am not familiar with the release/branching strategy).

No worries, thank you all for the quick fix!

@tgodzik
Copy link
Contributor

tgodzik commented Feb 2, 2025

It should be ported back to 3.3.6.

@bjaglin
Copy link
Collaborator

bjaglin commented Feb 2, 2025

It should albo be ported back to 3.3.6.

Right 👍 I didn't mention it because the report mentioned a Scala version after LTS, but I certainly hope we can backport that to LTS!

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