Skip to content

Indented function params rules #12554

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

Closed
tgodzik opened this issue May 21, 2021 · 2 comments · Fixed by #14877
Closed

Indented function params rules #12554

tgodzik opened this issue May 21, 2021 · 2 comments · Fixed by #14877

Comments

@tgodzik
Copy link
Contributor

tgodzik commented May 21, 2021

Compiler version

3.0.0

Minimized code

This one compiles:

def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")

but:

def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
  ("Bar")

does not.

This looks like a feature/bug connected to optional braces and I am not sure if the exact rule is mentioned anywhere. It's not mentioned here https://dotty.epfl.ch/docs/reference/other-new-features/indentation.html as far as I can tell.

@odersky
Copy link
Contributor

odersky commented May 23, 2021

Yes, that's a separate tweak for newline insertion. A newline is inserted between ) and ( on the next line only if the next line is not indented relative to the previous line.

tgodzik added a commit to tgodzik/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
tgodzik added a commit to tgodzik/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
tgodzik added a commit to tgodzik/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
tgodzik added a commit to tgodzik/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
tgodzik added a commit to tgodzik/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
tgodzik added a commit to tgodzik/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
@tgodzik
Copy link
Contributor Author

tgodzik commented May 24, 2021

Just a follow up. It seems it's exactly the same situation with }, which changes the Scala 2 behaviour.

To quote example from @dos65 :

def fun(a: Int, b: Int, c: Int)(d: Int): String = ???
def method: String = 
  fun(1, 2, 3) 
    {4} // <- this  Term.Apply(Term.Apply("fun", ...), "d")
def method2: String = 
  fun(1, 2, 3)
  {4} // <- doesn't compile - `{4}` is not part of apply
      // but scalameta parses it the same way as above -  Term.Apply(Term.Apply("fun", ...), "d")

tgodzik added a commit to tgodzik/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
kitbellew pushed a commit to scalameta/scalameta that referenced this issue May 24, 2021
Related to scala/scala3#12554 and scalameta/scalafmt#2522

It is now possible to have the next apply in curried functions to start in the next line if there is an indentation:

```scala
def f(s: String)(t: String) = s"$t: $s"

def g =
  f("Foo")
    ("Bar")
```
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 7, 2022
Clarify and test rules for when to suppress a newline insertion
based on indentation.

Fixes scala#12554
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 25, 2022
Clarify and test rules for when to suppress a newline insertion
based on indentation.

Fixes scala#12554
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants