Skip to content

Fewer braces and lambda: incorrect indentation region detection #22193

Closed
@kitbellew

Description

@kitbellew

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions