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

Change indentation rules to allow copy-paste #7114

Merged
merged 11 commits into from
Aug 30, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 27, 2019

Change significant indentation rules so that indented code can appear inside braces.

@odersky odersky force-pushed the change-indent branch 3 times, most recently from 0605327 to dab226c Compare August 28, 2019 15:58
@odersky odersky marked this pull request as ready for review August 28, 2019 16:07
@odersky odersky force-pushed the change-indent branch 6 times, most recently from 3dc3ccb to 956e99e Compare August 29, 2019 12:36
@odersky odersky force-pushed the change-indent branch 2 times, most recently from 40b550c to c802c4e Compare August 29, 2019 13:10
@odersky
Copy link
Contributor Author

odersky commented Aug 29, 2019

To bring this over the finish line, we still need to do two things

  • fix the error message diagnostics (the messages look OK, the tests need to be updated, but
    their architecture does not make it easy).
  • fix the community build so that dotc is invoked with option noindent.

@odersky
Copy link
Contributor Author

odersky commented Aug 29, 2019

The following fixes had to be done to the community build to make this pass:

  • compile ScalaTest and SemanticDB with -noindent. ScalaTest had multiple errors with significant indentation on, SemanticDB only one.
  • comment out a line in FasterParserParser.scala, which is a fastparse test. The change in Don't interpolate downwards to Nothing #7130 broke the type inference at that line. We should follow up to see how to fix this. I opened an issue in Fix problem in fastparse test #7133.

Also: fix indentation in Implicits
Also:

 - Make indentation opt in, controlled by -indent.
   indent is set as a default option when testing.
 - Allow rewritings under constructs that could not be rewritten
 - More systematic checking of conflicting rewrite options
 - Don't insert an <outdent> where a statement is logically continued

The last item fixes a case observed in SJSCodeGen, which was basically like this:

```scala
    if (x) {
      ...
    } else /*
      bla
      bla
    } else */ {
```
The problem is that the commented out `}` in front of the uncommented `{` caused
an <outdent> to be inserte between `else` and `{`.
If the result of a covariant type variable interpolation would be a bottom type,
wait instead. This could make the variable be inferred to its upper bound after all,
if we do not need a fully instantiated type right away.

This makes a difference for indentation whereever we have a situation like this:
```
  def foo: T =
    bla.asInstanceOf
```
With indentation on, this is now equivalent to
```
  def foo: T = {
    bla.asInstanceof
  }
```
This means there is now an added opportunity for an interpolation step, of
the asInstanceOf, which would go downwards to Nothing. So indentation changes
the inferred type, which is very bad. With the commit the problem is
avoided.

Two tests are reclassified:

i536.scala previously compiled since the type argument was inferred to be Nothing.
But that inference is useless; it just hides a runtime failure. The issue scala#536
only complained that the compiler crashed, so having a negative outcome
is permissible.

enum-interop is similar except that the example makes even less sense and compiles only
because Nothing was inferred by accedient.
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

This still breaks on -rewrite -noindent and no newline on the end. What I am doing is building a vanilla sbt project with version 0.18.1-bin-SNAPSHOT after running community-build/prepareCommunityBuild

object ifexample:
  if true then
    println
    println
  else
    println
    println

This needs to be done only if the partial if is followed by `else`.

Change all dotc code to be stable under the new rewrite scheme.
@odersky
Copy link
Contributor Author

odersky commented Aug 29, 2019

@bishabosha I found it. I'll add a fix.

This fixes a crash when trying to compile pos/indent2.scala with -rewrite -noindent.
Ideally we should have a test for this. However, I am not sure whether our current
test infrastructure supports rewrite tests.
@anatoliykmetyuk anatoliykmetyuk added this to the 0.18 Tech Preview milestone Aug 29, 2019
@odersky odersky merged commit 96b0854 into scala:master Aug 30, 2019
@odersky odersky deleted the change-indent branch August 30, 2019 06:38
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

3 participants