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

Don't create block on indentation with a single statement #2183

Merged
merged 1 commit into from Dec 1, 2020

Conversation

tgodzik
Copy link
Collaborator

@tgodzik tgodzik commented Nov 30, 2020

After working a bit on scalafmt it seems that most problematic is the case with a single statement, which now is sometimes be treated as an indented block. So reformatting could sometimes cause a new block to be created even if there was none before.

@@ -2087,42 +2087,55 @@ class ScalametaParser(input: Input, dialect: Dialect) { parser =>
atPos(t, auto)(Term.Match(t, inBracesOrNil(caseClauses())))
}
}

def ifClause(isInline: Boolean = false) = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is moved out from expr

// FIXME: when parsing `(2 + 3)`, do we want the ApplyInfix's position to include parentheses?
// if yes, then nothing has to change here
// if no, we need eschew autoPos here, because it forces those parentheses on the result of calling prefixExpr
// see https://github.com/scalameta/scalameta/issues/1083 and https://github.com/scalameta/scalameta/issues/1223
def expr(location: Location, allowRepeated: Boolean): Term =
autoPos(token match {
case SkInline() if ahead(token.is[KwIf]) =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Turns out there was one more issue with ifs, so a much safer place to check it is here.

The problem was with
def a = inline if cond then a

}
case KwIf() if mods.size > 0 =>
syntaxError("If can only contain inline modifier", at = token.pos)
ifClause(isInline = true)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed the additional case with non-inline mods - it will be reported anyway as error.

Copy link
Collaborator

@kpbochenek kpbochenek left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@tgodzik tgodzik merged commit c5c2879 into scalameta:master Dec 1, 2020
@tgodzik tgodzik deleted the indent-fix branch December 1, 2020 09:56
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.

None yet

2 participants