Skip to content

Redundant end markers #11581

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
sake92 opened this issue Mar 3, 2021 · 3 comments · Fixed by #11602
Closed

Redundant end markers #11581

sake92 opened this issue Mar 3, 2021 · 3 comments · Fixed by #11602

Comments

@sake92
Copy link

sake92 commented Mar 3, 2021

Compiler version

3.0.0-RC1

Minimized code

class Abc {
}
end Abc
end Abc

Output

Compiles.

Expectation

Does not compile.
First end Abc is redundant since definition of Abc is closed with braces.
Then I added another end Abc and it compiles too...

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Mar 3, 2021

It might be good to support the following one

class Abc {
} 
end Abc

It has the combined advantage to be explicit and collapsible by most IDEs

@som-snytt
Copy link
Contributor

Docs say: "Braces are not much better since a brace by itself also contains no information about what region is closed."

An end marker is not redundant with right brace, even where the brace is a template body and not a block.

def f = {
  42
}
end f

Here it's clear that the end marker is not redundant because "we opted for optional braces".

def debug = println {
  42
}
end debug

I suggest moving the doc for end marker out of "optional braces" and into "optional line comment saying where something ends". Because really the feature replaces:

def f = {
   // long body
} // end f

Real-world example } // end checkAllOverrides.

FSR I loathe the comment but love the end marker. (Perhaps because the comment means: I know this method is too big, so good luck trying to refactor it. End marker means: this method is bigger than a simple expression, thanks for reading my code.)

Someone should start a thread on contributors forum as to whether there is a use case for redundant end.

end checkAllOverrides // should be over by now, adding this to make sure because a merge conflict broke my change

Easy use case for checking end marker is that more than one symbol may be in play.

scala> def f =
     |   def f =
     |     println("inner")
     |     42
     |   println("outer")
     |   f
     | end f
def f: Int

@Kordyjan
Copy link
Contributor

Kordyjan commented Mar 4, 2021

I've created PR solving the issue with multiple consecutive end markers. It is not touching anything related to the question if an end marker should be allowed after a right brace. Personally, I would love to be able to write something like this:

class A {
    def a = ???
} end A

It is much better than comment, as it is checked by the compiler. Nevertheless, it is probably much too late for a change like this.

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