-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Change indentation rules to allow copy-paste #7114
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
Conversation
0605327
to
dab226c
Compare
3dc3ccb
to
956e99e
Compare
40b550c
to
c802c4e
Compare
To bring this over the finish line, we still need to do two things
|
The following fixes had to be done to the community build to make this pass:
|
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.
There was a problem hiding this 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.
@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.
Change significant indentation rules so that indented code can appear inside braces.