Skip to content

Commit fa2d063

Browse files
authored
Merge pull request #8264 from dotty-staging/fix-#8256
Fix #8256: Disallow silent indent for template bodies
2 parents 571d579 + 2bbecb8 commit fa2d063

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+191
-201
lines changed

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def exec(projectDir: Path, binary: String, arguments: String*): Int =
3131
exitCode
3232

3333

34-
sealed trait CommunityProject
34+
sealed trait CommunityProject:
3535
private var published = false
3636

3737
val project: String
@@ -77,17 +77,23 @@ sealed trait CommunityProject
7777
published = true
7878
end CommunityProject
7979

80-
final case class MillCommunityProject(project: String, baseCommand: String,
81-
dependencies: List[CommunityProject] = Nil) extends CommunityProject
80+
final case class MillCommunityProject(
81+
project: String,
82+
baseCommand: String,
83+
dependencies: List[CommunityProject] = Nil) extends CommunityProject:
8284
override val binaryName: String = "./mill"
8385
override val updateCommand = s"$baseCommand.compileClasspath"
8486
override val testCommand = s"$baseCommand.test"
8587
override val publishCommand = s"$baseCommand.publishLocal"
8688
override val runCommandsArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
8789

88-
final case class SbtCommunityProject(project: String, sbtTestCommand: String,
89-
sbtUpdateCommand: String, extraSbtArgs: List[String] = Nil,
90-
dependencies: List[CommunityProject] = Nil, sbtPublishCommand: String = null) extends CommunityProject
90+
final case class SbtCommunityProject(
91+
project: String,
92+
sbtTestCommand: String,
93+
sbtUpdateCommand: String,
94+
extraSbtArgs: List[String] = Nil,
95+
dependencies: List[CommunityProject] = Nil,
96+
sbtPublishCommand: String = null) extends CommunityProject:
9197
override val binaryName: String = "sbt"
9298
private val baseCommand = s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! "
9399
override val testCommand = s"$baseCommand$sbtTestCommand"
@@ -103,7 +109,7 @@ final case class SbtCommunityProject(project: String, sbtTestCommand: String,
103109
"-sbt-version", "1.3.6",
104110
s"--addPluginSbtFile=$sbtPluginFilePath")
105111

106-
object projects
112+
object projects:
107113
lazy val utest = MillCommunityProject(
108114
project = "utest",
109115
baseCommand = s"utest.jvm[$compilerVersion]",
@@ -265,7 +271,7 @@ object projects
265271
end projects
266272

267273
@Category(Array(classOf[TestCategory]))
268-
class CommunityBuildTest {
274+
class CommunityBuildTest:
269275
given CommunityBuildTest = this
270276

271277
/** Build the given project with the published local compiler and sbt plugin.
@@ -335,7 +341,7 @@ class CommunityBuildTest {
335341
@Test def xmlInterpolator = projects.xmlInterpolator.run()
336342
@Test def effpi = projects.effpi.run()
337343
@Test def sconfig = projects.sconfig.run()
338-
}
344+
end CommunityBuildTest
339345

340346
class TestCategory
341347
class UpdateCategory

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ object Config {
160160
/** Assume -indent by default */
161161
final val defaultIndent = true
162162

163-
/** Assume indentation is significant after a class, object, ... signature */
164-
final val silentTemplateIndent = true
165-
166163
/** If set, prints a trace of all symbol completions */
167164
final val showCompletions = false
168165

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import Decorators._
2626
import scala.internal.Chars
2727
import scala.annotation.{tailrec, switch}
2828
import rewrites.Rewrites.{patch, overlapsPatch}
29-
import config.Config.silentTemplateIndent
3029

3130
object Parsers {
3231

@@ -1319,7 +1318,6 @@ object Parsers {
13191318
if in.token != LBRACE && in.token != INDENT then
13201319
syntaxError(i"indented definitions or `{` expected")
13211320
else
1322-
if silentTemplateIndent && !isNew then in.observeIndented()
13231321
newLineOptWhenFollowedBy(LBRACE)
13241322

13251323
def endMarkerScope[T](pid: Tree)(op: => T): T = pid match {

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ object Inliner {
197197

198198
object Intrinsics {
199199
import dotty.tools.dotc.reporting.diagnostic.messages.Error
200-
private enum ErrorKind
200+
private enum ErrorKind:
201201
case Parser, Typer
202202

203203
private def compileForErrors(tree: Tree, stopAfterParser: Boolean)(using ctx: Context): List[(ErrorKind, Error)] =

compiler/src/dotty/tools/dotc/typer/Nullables.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import config.Printers.nullables
1616
import ast.{tpd, untpd}
1717

1818
/** Operations for implementing a flow analysis for nullability */
19-
object Nullables with
19+
object Nullables:
2020
import ast.tpd._
2121

2222
/** A set of val or var references that are known to be not null, plus a set of
2323
* variable references that are not known (anymore) to be not null
2424
*/
25-
case class NotNullInfo(asserted: Set[TermRef], retracted: Set[TermRef])
25+
case class NotNullInfo(asserted: Set[TermRef], retracted: Set[TermRef]):
2626
assert((asserted & retracted).isEmpty)
2727

2828
def isEmpty = this eq NotNullInfo.empty
@@ -43,18 +43,18 @@ object Nullables with
4343
def alt(that: NotNullInfo): NotNullInfo =
4444
NotNullInfo(this.asserted.intersect(that.asserted), this.retracted.union(that.retracted))
4545

46-
object NotNullInfo with
46+
object NotNullInfo:
4747
val empty = new NotNullInfo(Set(), Set())
4848
def apply(asserted: Set[TermRef], retracted: Set[TermRef]): NotNullInfo =
4949
if asserted.isEmpty && retracted.isEmpty then empty
5050
else new NotNullInfo(asserted, retracted)
5151
end NotNullInfo
5252

5353
/** A pair of not-null sets, depending on whether a condition is `true` or `false` */
54-
case class NotNullConditional(ifTrue: Set[TermRef], ifFalse: Set[TermRef]) with
54+
case class NotNullConditional(ifTrue: Set[TermRef], ifFalse: Set[TermRef]):
5555
def isEmpty = this eq NotNullConditional.empty
5656

57-
object NotNullConditional with
57+
object NotNullConditional:
5858
val empty = new NotNullConditional(Set(), Set())
5959
def apply(ifTrue: Set[TermRef], ifFalse: Set[TermRef]): NotNullConditional =
6060
if ifTrue.isEmpty && ifFalse.isEmpty then empty
@@ -72,7 +72,7 @@ object Nullables with
7272
private[typer] val NNInfo = Property.StickyKey[NotNullInfo]
7373

7474
/** An extractor for null comparisons */
75-
object CompareNull with
75+
object CompareNull:
7676

7777
/** Matches one of
7878
*
@@ -97,7 +97,7 @@ object Nullables with
9797
end CompareNull
9898

9999
/** An extractor for null-trackable references */
100-
object TrackedRef
100+
object TrackedRef:
101101
def unapply(tree: Tree)(using Context): Option[TermRef] = tree.typeOpt match
102102
case ref: TermRef if isTracked(ref) => Some(ref)
103103
case _ => None
@@ -160,7 +160,7 @@ object Nullables with
160160
// TODO: Add constant pattern if the constant type is not nullable
161161
case _ => false
162162

163-
extension notNullInfoOps on (infos: List[NotNullInfo]) with
163+
extension notNullInfoOps on (infos: List[NotNullInfo]):
164164

165165
/** Do the current not-null infos imply that `ref` is not null?
166166
* Not-null infos are as a history where earlier assertions and retractions replace
@@ -191,7 +191,7 @@ object Nullables with
191191
infos.extendWith(NotNullInfo(Set(), mutables))
192192
// end notNullInfoOps
193193

194-
extension refOps on (ref: TermRef) with
194+
extension refOps on (ref: TermRef):
195195

196196
/** Is the use of a mutable variable out of order
197197
*
@@ -245,7 +245,7 @@ object Nullables with
245245
&& refOwner.isTerm
246246
&& recur(curCtx.owner)
247247

248-
extension treeOps on (tree: Tree) with
248+
extension treeOps on (tree: Tree):
249249

250250
/* The `tree` with added nullability attachment */
251251
def withNotNullInfo(info: NotNullInfo): tree.type =
@@ -335,7 +335,7 @@ object Nullables with
335335
tree.computeNullable()
336336
}.traverse(tree)
337337

338-
extension assignOps on (tree: Assign) with
338+
extension assignOps on (tree: Assign):
339339
def computeAssignNullable()(using Context): tree.type = tree.lhs match
340340
case TrackedRef(ref) =>
341341
val rhstp = tree.rhs.typeOpt

library/src/scala/IArray.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import reflect.ClassTag
44
/** An immutable array. An `IArray[T]` has the same representation as an `Array[T]`,
55
* but it cannot be updated. Unlike regular arrays, immutable arrays are covariant.
66
*/
7-
object opaques
7+
object opaques:
88
opaque type IArray[+T] = Array[_ <: T]
99

1010
/** Defines extension methods for immutable arrays */

library/src/scala/TupledFunction.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import scala.annotation.implicitNotFound
88
* @tparam G a tupled function type (function of arity 1 receiving a tuple as argument)
99
*/
1010
@implicitNotFound("${F} cannot be tupled as ${G}")
11-
sealed trait TupledFunction[F, G] {
11+
sealed trait TupledFunction[F, G]:
1212
def tupled(f: F): G
1313
def untupled(g: G): F
14-
}
1514

16-
private[scala] object TupledFunction
15+
private[scala] object TupledFunction:
1716
def apply[F, G](tupledImpl: F => G, untupledImpl: G => F): TupledFunction[F, G] =
18-
new TupledFunction[F, G] {
17+
new TupledFunction[F, G]:
1918
def tupled(f: F): G = tupledImpl(f)
2019
def untupled(g: G): F = untupledImpl(g)
21-
}

library/src/scala/compiletime/testing/ErrorKind.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package scala.compiletime.testing
22

33
/** An error can be either a parse-time or a typecheck-time */
44
sealed trait ErrorKind // TODO make this enum, so far not doable because ScalaJS compilation fails on it
5-
object ErrorKind
5+
object ErrorKind:
66
case object Parser extends ErrorKind
77
case object Typer extends ErrorKind

library/src/scala/tasty/Reflection.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,30 +1560,28 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
15601560

15611561
given (using ctx: Context) as IsInstanceOf[SimpleSelector] = internal.isInstanceOfSimpleSelector
15621562

1563-
object SimpleSelector
1563+
object SimpleSelector:
15641564
def unapply(x: SimpleSelector)(using ctx: Context): Option[Id] = Some(x.selection)
15651565

1566-
extension renameSelectorOps on (self: RenameSelector) {
1566+
extension renameSelectorOps on (self: RenameSelector):
15671567
def from(using ctx: Context): Id =
15681568
internal.RenameSelector_from(self)
15691569

15701570
def to(using ctx: Context): Id =
15711571
internal.RenameSelector_to(self)
1572-
}
15731572

15741573
given (using ctx: Context) as IsInstanceOf[RenameSelector] = internal.isInstanceOfRenameSelector
15751574

1576-
object RenameSelector
1575+
object RenameSelector:
15771576
def unapply(x: RenameSelector)(using ctx: Context): Option[(Id, Id)] = Some((x.from, x.to))
15781577

1579-
extension omitSelectorOps on (self: OmitSelector) {
1578+
extension omitSelectorOps on (self: OmitSelector):
15801579
def omitted(using ctx: Context): Id =
15811580
internal.SimpleSelector_omitted(self)
1582-
}
15831581

15841582
given (using ctx: Context) as IsInstanceOf[OmitSelector] = internal.isInstanceOfOmitSelector
15851583

1586-
object OmitSelector
1584+
object OmitSelector:
15871585
def unapply(x: OmitSelector)(using ctx: Context): Option[Id] = Some(x.omitted)
15881586

15891587

@@ -1980,7 +1978,7 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
19801978

19811979
given (using ctx: Context) as IsInstanceOf[NoPrefix] = internal.isInstanceOfNoPrefix
19821980

1983-
object NoPrefix
1981+
object NoPrefix:
19841982
def unapply(x: NoPrefix)(using ctx: Context): Boolean = true
19851983

19861984

tests/neg/endmarkers.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
object Test
1+
object Test:
22

33
locally {
44
var x = 0
@@ -43,11 +43,11 @@ object Test
4343
x < 10
4444
do ()
4545

46-
class Test2
46+
class Test2:
4747
self =>
4848
def foo = 1
4949

50-
object x
50+
object x:
5151
new Test2 {
5252
override def foo = 2
5353
end new // error: misaligned end marker
@@ -56,16 +56,16 @@ class Test2
5656
end Test2 // error: misaligned end marker
5757
end Test2
5858

59-
class Test3
59+
class Test3:
6060
self =>
6161
def foo = 1
6262
end Test3 // error: misaligned end marker
6363

6464
import collection.mutable.HashMap
6565

66-
class Coder(words: List[String])
66+
class Coder(words: List[String]):
6767

68-
class Foo
68+
class Foo:
6969
println()
7070
end Foo // error: misaligned end marker
7171

tests/neg/given-eta.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
trait D
2+
trait D:
33
type T
44
def trans(other: T): T
55

tests/neg/i7359-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
trait SAMTrait
1+
trait SAMTrait:
22
def first(): String
33
def notifyAll(): Unit // error

tests/neg/i7359-c.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
trait SAMTrait
1+
trait SAMTrait:
22
def first(): String
33
def wait(): Unit // error

tests/neg/i7359-d.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
trait SAMTrait
1+
trait SAMTrait:
22
def first(): String
33
def wait(a: Long): Unit // error

tests/neg/i7359-e.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
trait SAMTrait
1+
trait SAMTrait:
22
def first(): String
33
def wait(a: Long, n: Int): Unit // error

tests/neg/i7359-f.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- [E120] Duplicate Symbol Error: tests/neg/i7359-f.scala:1:6 ----------------------------------------------------------
2-
1 |trait SAMTrait // error
2+
1 |trait SAMTrait: // error
33
| ^
44
| Name clash between inherited members:
55
| def equals: [T >: Boolean <: Boolean](obj: Any): T in trait SAMTrait at line 3 and

tests/neg/i7359-f.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
trait SAMTrait // error
1+
trait SAMTrait: // error
22
def first(): String
33
def equals[T >: Boolean <: Boolean](obj: Any): T

tests/neg/i7359-g.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
trait SAMTrait
1+
trait SAMTrait:
22
def first(): String
33
def equals(obj: Int): Boolean
44

tests/neg/i7359.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
trait SAMTrait
1+
trait SAMTrait:
22
def first(): String
33
def notify(): Unit // error

tests/neg/i7980.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
trait Evidence[X]
22

3-
trait Trait[X : Evidence]
3+
trait Trait[X : Evidence]:
44
def method(x : X) : X
55

6-
given ev : Evidence[Int] = new Evidence[Int]{}
6+
given ev as Evidence[Int] = new Evidence[Int]{}
77
val crash : Trait[Int] = (x: Int) => x // error

tests/neg/i8069.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
trait A
1+
trait A:
22
type B
33

4-
enum Test
4+
enum Test:
55
case Test(a: A, b: a.B) // error: Implementation restriction: case classes cannot have dependencies between parameters
66

77
case class Test2(a: A, b: a.B) // error: Implementation restriction: case classes cannot have dependencies between parameters

tests/neg/override-inner-class.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
class C
1+
class C:
22
type T >: String <: Any
33

4-
class D extends C
4+
class D extends C:
55
class T // error

tests/neg/parser-stability-12.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
trait x0[] // error
1+
trait x0[]: // error
22
trait x1[x1 <:x0]
33
extends x1[ // error
44
// error

0 commit comments

Comments
 (0)