Repository: scalameta/scalameta (scala)

Issue:
3.8.0 breaks lambda functions
The latest scalafmt 3.8.0 break lila code:

https://github.com/lichess-org/lila/pull/14717

## Steps

Given code like this:
```scala
  val top10NbGame = mongoCache.unit[List[User.LightCount]](
    "user:top:nbGame",
    74 minutes
  ): loader =>
    _.refreshAfterWrite(75 minutes).buildAsyncFuture:
      loader: _ => 
        userRepo topNbGame 10 dmap (_.map(_.lightCount))
```

## Problem

Scalafmt formats code like this:
```scala
  val top10NbGame = mongoCache.unit[List[User.LightCount]](
    "user:top:nbGame",
    74 minutes
  ): loader =>
    _.refreshAfterWrite(75 minutes).buildAsyncFuture:
      loader: _ => userRepo topNbGame 10 dmap (_.map(_.lightCount))
```

## Expectation

I would like scalafmt doesn't change the code as it breaks the build

## Notes

I breaks other similar code as well, please check the PR link for more details.

Pull request:
Fixes scalameta/scalafmt#3785.

Patch:
diff --git a/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/ScalametaParser.scala b/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/ScalametaParser.scala
index 1cc9fe3c3e..251ff5ae17 100644
--- a/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/ScalametaParser.scala
+++ b/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/ScalametaParser.scala
@@ -2435,8 +2435,10 @@ class ScalametaParser(input: Input)(implicit dialect: Dialect) { parser =>
       autoPos(getParam(mods, fullTypeOK))
     @tailrec
     def getParam(mods: List[Mod], fullTypeOK: Boolean): Term.Param = {
-      def afterName(name: Name) =
-        Term.Param(mods, name, getDeclTpeOpt(fullTypeOK = fullTypeOK), None)
+      def afterName(name: Name) = {
+        val tpe = if (fullTypeOK || mods.nonEmpty) getDeclTpeOpt(fullTypeOK = fullTypeOK) else None
+        Term.Param(mods, name, tpe, None)
+      }
       token match {
         case t: Ellipsis => ellipsis[Term.Param](t, 1)
         case t: Ident =>


Test patch:
diff --git a/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FewerBracesSuite.scala b/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FewerBracesSuite.scala
index c7b7c69a79..b24c6b7f16 100644
--- a/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FewerBracesSuite.scala
+++ b/tests/shared/src/test/scala/scala/meta/tests/parsers/dotty/FewerBracesSuite.scala
@@ -2409,4 +2409,33 @@ class FewerBracesSuite extends BaseDottySuite {
     runTestAssert[Stat](code, layout)(tree)
   }
 
+  test("scalafmt #3785") {
+    val code =
+      """|val foo = bar(): loader =>
+         |  baz:
+         |    loader: _ => 
+         |      qux
+         |""".stripMargin
+    val layout = "val foo = bar()(loader => baz(loader(_ => qux)))"
+    val tree = Defn.Val(
+      Nil,
+      List(Pat.Var(tname("foo"))),
+      None,
+      Term.Apply(
+        Term.Apply(tname("bar"), Nil),
+        Term.Function(
+          List(tparam("loader")),
+          Term.Apply(
+            tname("baz"),
+            Term.Apply(
+              tname("loader"),
+              Term.Function(List(tparam("_")), tname("qux")) :: Nil
+            ) :: Nil
+          )
+        ) :: Nil
+      )
+    )
+    runTestAssert[Stat](code, layout)(tree)
+  }
+
 }