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

scala3 named tuple style pattern matching is not working #4713

Closed
shuttie opened this issue Jan 3, 2025 · 4 comments · Fixed by #4715
Closed

scala3 named tuple style pattern matching is not working #4713

shuttie opened this issue Jan 3, 2025 · 4 comments · Fixed by #4715

Comments

@shuttie
Copy link

shuttie commented Jan 3, 2025

Steps

Given code like this:

import language.experimental.namedTuples

object Main {
  case class StringField(name: String, value: String)

  def test(field: StringField) = field match {
    case StringField(name=name) => name
  }
}

and a scalafmt.conf file:

version = 3.8.4-RC4
runner.dialect = Scala35

with a build.sbt:

version := "0.1.0-SNAPSHOT"
scalaVersion := "3.6.2"
name := "sca-namedtuple-bug"
scalacOptions ++= Seq("-experimental")

Problem

Scalafmt fails formatting the code, but compiling works:

[info] welcome to sbt 1.10.7 (Gentoo Java 17.0.13)
[info] loading global plugins from /home/shutty/.sbt/1.0/plugins
[info] loading settings for project sca-namedtuple-bug-build from plugins.sbt...
[info] loading project definition from /home/shutty/private/code/sca-namedtuple-bug/project
[info] loading settings for project sca-namedtuple-bug from build.sbt...
[info] set current project to sca-namedtuple-bug (in build file:/home/shutty/private/code/sca-namedtuple-bug/)
[info] scalafmt: Formatting 1 Scala sources (/home/shutty/private/code/sca-namedtuple-bug)...
[error] org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt: /home/shutty/private/code/sca-namedtuple-bug/src/main/scala/Main.scala:7: error: [dialect scala35] `)` expected but `=` found
[error]     case StringField(name=name) => name
[error]                          ^ [/home/shutty/private/code/sca-namedtuple-bug/src/main/scala/Main.scala]
[error] (Compile / scalafmt) org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt: /home/shutty/private/code/sca-namedtuple-bug/src/main/scala/Main.scala:7: error: [dialect scala35] `)` expected but `=` found
[error]     case StringField(name=name) => name
[error]                          ^ [/home/shutty/private/code/sca-namedtuple-bug/src/main/scala/Main.scala]
[error] Total time: 1 s, completed Jan 3, 2025, 4:44:15 PM

Expectation

The latest version of scalafmt does not yet support scala36 syntax, but AFAIK named tuples are also available in the 3.5. Is there a way to have both named tuples AND scalafmt in the same project?

@kitbellew
Copy link
Collaborator

@shuttie when you were submitting this issue, did you have a chance to read through the issue template, perhaps? the section entitled "do not submit if", specifically.

@tgodzik
Copy link
Contributor

tgodzik commented Jan 3, 2025

Btw. we are working on it currently in the scalameta parser, @Florian3k should have a PR ready soon.

@shuttie
Copy link
Author

shuttie commented Jan 3, 2025

@kitbellew yes I've read the issue template and saw the notice. But it's still unclear to me, if there's a way to triage beforehand to figure out if it's a scalameta or scalafmt issue? I have a reproducer for scalafmt, but not for scalameta, and I'm not using scalameta directly.

@kitbellew
Copy link
Collaborator

@kitbellew yes I've read the issue template and saw the notice. But it's still unclear to me, if there's a way to triage beforehand to figure out if it's a scalameta or scalafmt issue? I have a reproducer for scalafmt, but not for scalameta, and I'm not using scalameta directly.

the issue description explicitly emphasizes that anything related to your code (input) is a parser issue. so either you set your dialect incorrectly, or the parser has a bug.

also, you used sbt and not the scalafmt binary. also a requirement that was called out.

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

Successfully merging a pull request may close this issue.

3 participants