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

Restrict outdent in parens for certain region prefixes #22530

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Feb 6, 2025

Possible fix requires comma at end of line if the indented region was introduced by a colon (and similar prefix tokens).

Fixes #22527

@som-snytt
Copy link
Contributor Author

That breaks sudoku!

      fold((accu: Int, n: Int) =>
           if (invalid(0, x, y, (n + 48).toChar)) accu else {
             m(y)(x) = (n + 48).toChar;
             val newaccu = search(x + 1, y, f, accu);
             m(y)(x) = '0';
             newaccu}, accu, 1, 10)}

which is hard to read and misleading indentation, but is it illegal.

The intuition here would be that if you indent the body of your function literal, you intend it to look like a block, and not mashed together with trailing args.

Restricting the restriction to COLONeol might be intuitive enough, or may be just ad hoc.

-              // For some region prefixes (COLONeol, EQUALS) only OUTDENT if COMMA at EOL
-              if canStartIndentTokens.contains(r.prefix) && !statCtdTokens.contains(r.prefix) then
+              // For region prefix COLONeol, only OUTDENT if COMMA at EOL
+              if r.prefix == COLONeol then

Maybe that is OK, because the colon is special.

I noticed that we wanted templates defined with =, and we wanted = to be :=, and wound up at :.

@som-snytt som-snytt force-pushed the issue/22527-comma-vs-indent branch from dceeef7 to 4362c32 Compare February 6, 2025 17:42
@som-snytt
Copy link
Contributor Author

That breaks scalaz!

  def applyLens[A, B](k: B => A)(implicit e: Equal[A]): Store[A, B] @> B =
    lens(q => {
      val x = Need(q.pos)
      val y = Need(q put x.value)
      Store(b =>
        Store(w => if(e.equal(x.value, w)) b else y.value, x.value), y.value)
    })

where it looks like Store(b => body) because of the indentation.

@som-snytt som-snytt marked this pull request as ready for review February 8, 2025 14:17
@som-snytt som-snytt force-pushed the issue/22527-comma-vs-indent branch from 4362c32 to 17d360e Compare February 8, 2025 14:37
@som-snytt
Copy link
Contributor Author

The spurious timeout.

@som-snytt som-snytt force-pushed the issue/22527-comma-vs-indent branch from b20e6a2 to dc46f94 Compare February 10, 2025 01:55
@som-snytt som-snytt marked this pull request as draft February 13, 2025 03:55
@som-snytt
Copy link
Contributor Author

unindented args complains about

            addParamssText(
              addParamssText(keywordStr("extension "), leadingParamss)
              ~~ (defKeyword ~~ valDefText(nameIdText(tree))).close,
             trailingParamss)

That blocks other corpus tests. Probably it is too opinionated, but I'll try unblocking just to collect the data.

@som-snytt som-snytt force-pushed the issue/22527-comma-vs-indent branch from dc46f94 to b4a4319 Compare February 13, 2025 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comma in extends or derives clause treated as parameter separator in indentation blocks
1 participant