Skip to content

Make then optional at line end #7276

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 6 commits into from
Sep 25, 2019
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Sep 20, 2019

No description provided.

smarter added a commit to dotty-staging/dotty that referenced this pull request Sep 20, 2019
Also auto-indent after `if ...` as long as it doesn't match `if ... then
...` in anticipation of scala#7276

Also use lazy matching (`.*?` instead of `.*`) when possible to avoid
backtracking explosion.
smarter added a commit to dotty-staging/dotty that referenced this pull request Sep 20, 2019
- do not auto-indent after end marker (fixes scala#7274)
- auto-indent after `if ...` as long as it doesn't match `if ... then
  ...` in anticipation of scala#7276
- use lazy matching (`.*?` instead of `.*`) when possible to avoid
  backtracking explosion.
@odersky odersky force-pushed the change-then-opt branch 4 times, most recently from d431149 to d834abe Compare September 23, 2019 09:41
smarter added a commit to dotty-staging/dotty that referenced this pull request Sep 23, 2019
- do not auto-indent after end marker (fixes scala#7274)
- auto-indent after `if ...` as long as it doesn't match `if ... then
  ...` in anticipation of scala#7276
- use lazy matching (`.*?` instead of `.*`) when possible to avoid
  backtracking explosion.
`then` is treated like `;`: It is inferred at the end of a line, if

 - a new line would otherwise be inferred
 - the next line is indented

Disambiguation with Scala-2 syntax is as follows:

The question is whether to classify

   if (A) B
     C

as a condition A followed by a statement B (old-style), or
as a condition (A) B followed by a then part C, and an inferred
`then` in-between (new-style)

(new-style) is chosen if B cannot start a statement, or starts with a leading
infix operator. Otherwise put, (new-style) is chosen if in
```
(A)
B
```
no newline would be inserted. (old-style) is chosen otherwise.

This means that some otherwise legal conditions still need a `then` at the end of a line.
If (old-style) is eventually deprecated and removed, we can drop this restriction.
`do` can start an expression or a statement only under -language:Scala2.
Maintaining this distinction is important in order not to insert spurious
newlines in front of `do` in a `while` or `for`.
Issue "too far to the right" errors also at toplevel. Previously
this was done only inside braces.
 - Update current reference docs to what's implemented in 0.19.
 - Add links to new pages describing what will come in 0.20.
@odersky
Copy link
Contributor Author

odersky commented Sep 23, 2019

test performance please

@dottybot
Copy link
Member

performance test scheduled: 6 job(s) in queue, 1 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/7276/ to see the changes.

Benchmarks is based on merging with master (0d34bfb)

title: New Control Syntax
---

Scala 3 has a new "quiet" syntax for control expressions that does not rely in
Copy link

Choose a reason for hiding this comment

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

s/in/on

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

Regarding the indented syntax, currently the following program checks without problem:

def test = {
  var x = 10
  while x < 10 do
x+=1
  if x < 10 then
x+=1
}

I assume it's out of the scope of the current PR.

newLineOpt()
val newSyntax = toBeContinued(altToken)
if newSyntax then
t = inSepRegion(LBRACE, RBRACE) {
expr1Rest(postfixExprRest(simpleExprRest(t)), Location.ElseWhere)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: the name newSyntax is not informative nor accurate.

@odersky
Copy link
Contributor Author

odersky commented Sep 25, 2019

Regarding the indented syntax, currently the following program checks without problem:

Yes, and that's as specified.

@odersky odersky closed this Sep 25, 2019
@odersky odersky reopened this Sep 25, 2019
@odersky odersky merged commit bd9744d into scala:master Sep 25, 2019
@odersky odersky deleted the change-then-opt branch September 25, 2019 16:58
@anatoliykmetyuk anatoliykmetyuk added this to the 0.20 Tech Preview milestone Oct 31, 2019
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.

5 participants