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

Comma in extends or derives clause treated as parameter separator in indentation blocks #22527

Open
s5bug opened this issue Feb 5, 2025 · 3 comments · May be fixed by #22530
Open

Comma in extends or derives clause treated as parameter separator in indentation blocks #22527

s5bug opened this issue Feb 5, 2025 · 3 comments · May be fixed by #22530

Comments

@s5bug
Copy link

s5bug commented Feb 5, 2025

Compiler version

3.3.5
3.6.3
3.6.4-RC1

Minimized code

identity(
  identity:
    class X extends AnyRef, Serializable
    ???
)

Output

',' or ')' expected, but identifier found

Expectation

With braces, this code compiles:

identity(
  identity {
    class X extends AnyRef, Serializable
    ???
  }
)
@som-snytt
Copy link
Contributor

som-snytt commented Feb 6, 2025

The useful outdent supports (from the unit test)

  assert(
    if x > 0 then
      true
    else
      false, "fail")

The syntax does not distinguish "term commas" from "type commas".

Similar

  assert(
    identity:
      true, "ok"
  )

@som-snytt
Copy link
Contributor

som-snytt commented Feb 6, 2025

The provisional proposal is to require the comma at EOL if the indent has a colon prefix. So the example would have to be written:

  assert(
    identity:
      true,
    "ok"
  )

That preserves the comma and the spirit of indents in parens.

Certain other tokens work similarly:

  identity(
    x =
      class X extends AnyRef, Serializable // ok, not at EOL and follows =
      27
  )

@som-snytt
Copy link
Contributor

I marked the PR ready for review, to mean discussion.

It is dialed back to only consider colon (as prefix of indented region) for the "comma at EOL" tweak.

The PR shows examples of misleading indentation after => which remain acceptable.

Added a test to show that "arrow eol" is not equivalent to "colon eol" with parameter on next line:

  def test =
    f(
      g: x =>
        x + 1, 42 // ok f(g(_ + 1), 42)
    )

as opposed to

    f(g:
        x =>
          x + 1, 42 // error, arg to f must be on next line
    )

but it is agnostic about the indentation of the arg to f:

    f(g:
        x =>
          x + 1,
          42
    )

which is the same as

    f(g(_ + 1),
          42
    )

The arg to k must be indented wrt g not k (3.6.3):

    f(
      g(_ + 1),
k:
        println(s"calculating...")
        42
    )

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

4 participants