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

Fewer braces and lambda: incorrect indentation region detection #22193

Open
kitbellew opened this issue Dec 11, 2024 · 0 comments
Open

Fewer braces and lambda: incorrect indentation region detection #22193

kitbellew opened this issue Dec 11, 2024 · 0 comments

Comments

@kitbellew
Copy link

kitbellew commented Dec 11, 2024

Compiler version

  • 3.3.3
  • 3.3.4 LTS
  • 3.5.2 Next

Minimized code

  def fn2(arg: String, arg2: String)(f: String => Unit): Unit =
    f(arg)

  // doesn't compile
  fn2(
      arg = "blue sleeps faster than tuesday",
      arg2 = "the quick brown fox jumped over the lazy dog"): env =>
      val x = env
      println(x)

  // does compile
  fn2(
      arg = "blue sleeps faster than tuesday",
      arg2 = "the quick brown fox jumped over the lazy dog"):
    env =>
      val x = env
      println(x)

  // does compile
  fn2(
      arg = "blue sleeps faster than tuesday",
      arg2 = "the quick brown fox jumped over the lazy dog"
  ): env =>
      val x = env
      println(x)

Output

scastie marks two errors:

  • fn2 line with not a legal formal parameter for a function literal
  • val x = env line with Not found: env

Expectation

According to the documentation, the first argument clause (with arg and arg2) does not start an indentation region, hence as long as the lambda body is indented relative to fn2 invocation, it should work.

P.S. The problem was first reported in scalameta/scalafmt#4569.

@kitbellew kitbellew added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 11, 2024
@Gedochao Gedochao added area:optional-braces and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 11, 2024
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

2 participants