Skip to content

Fix #10080: Allow end marker immediately after : at eol #10095

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

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1282,9 +1282,11 @@ object Parsers {
def possibleTemplateStart(isNew: Boolean = false): Unit =
in.observeColonEOL()
if in.token == COLONEOL then
in.nextToken()
if in.token != INDENT then
syntaxErrorOrIncomplete(i"indented definitions expected")
if in.lookahead.isIdent(nme.end) then in.token = NEWLINE
else
in.nextToken()
if in.token != INDENT then
syntaxErrorOrIncomplete(i"indented definitions expected, ${in}")
else
newLineOptWhenFollowedBy(LBRACE)

Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i10080.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait Foo:
end Foo

trait Bar
end Bar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks confusing to me because I read trait Bar as a complete definition, so there is nothing to end. As I’ve mentioned in the linked issue, to me the “brace-significant” equivalent would be:

trait Bar
}

So, I’m not sure we should support it.

Also, it suggests that we could insert definitions between trait Bar and end Bar, like so:

trait Bar
  def quux: Quux
end Bar

But this would be rejected, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that one would be rejected.