Skip to content

Conversation

adpi2
Copy link
Member

@adpi2 adpi2 commented Apr 28, 2023

Fix #17187

The no-indent rewrite sometimes needs to add several } at the same position, to close nested constructs.

For example, it rewrites:

object A:
  object B:
    def foo = 42

Into:

object A {
  object B {
    def foo = 42
  }
}

We deal with end marker in the indentedToBraces method by checking the next token of the region. This also fixes the following error:

class A:
  def foo = 42

end A

Rewritten to

class A {
  def foo = 42
}

end A

Instead Of:

class A {
  def foo = 42

} // end A

@adpi2 adpi2 requested review from mbovel and som-snytt April 28, 2023 12:46
@mbovel
Copy link
Member

mbovel commented Apr 28, 2023

Cool!

i2340.check should be updated:

diff --git a/tests/rewrites/i12340.check b/tests/rewrites/i12340.check
index c6cb9af8bb5..3ee2867f3e6 100644
--- a/tests/rewrites/i12340.check
+++ b/tests/rewrites/i12340.check
@@ -3,6 +3,15 @@ class C {
   def f = 42
 } // end C
 
+class A {
+  class B {
+    class C {
+      def foo = 42
+    }
+
+  } // end B
+}
+
 def f(i: Int) = {
   if i < 42 then
     println(i)

@som-snytt
Copy link
Contributor

I think I verified that you can also delete

--- a/compiler/src/dotty/tools/dotc/util/Spans.scala
+++ b/compiler/src/dotty/tools/dotc/util/Spans.scala
@@ -86,7 +86,7 @@ object Spans {
       || containsInner(this, that.end)
       || containsInner(that, this.start)
       || containsInner(that, this.end)
-      || this.start == that.start && this.end == that.end   // exact match in one point
+      //|| this.start == that.start && this.end == that.end   // exact match in one point
       )
     }

I had not tweaked the Scaladoc, so at least there is no need to revert it.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

Thanks! Indentation math was always my worst subject at school.

@adpi2 adpi2 merged commit 2c4502b into scala:main May 1, 2023
@Kordyjan Kordyjan added this to the 3.3.0 backports milestone May 12, 2023
@Kordyjan Kordyjan added the backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" label May 12, 2023
Kordyjan pushed a commit that referenced this pull request May 12, 2023
Kordyjan added a commit that referenced this pull request May 12, 2023
@Kordyjan Kordyjan added backport:done This PR was successfully backported. and removed backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels May 15, 2023
@Kordyjan Kordyjan modified the milestones: 3.3.0 backports, 3.3.1, 3.3.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:done This PR was successfully backported.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect rewriting of code from significant indentation to non-significant indentation based syntax

4 participants