Skip to content

Commit 96b0854

Browse files
authored
Merge pull request #7114 from dotty-staging/change-indent
Change indentation rules to allow copy-paste
2 parents 6a08e09 + f8bf15b commit 96b0854

File tree

242 files changed

+3644
-2729
lines changed

Some content is hidden

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

242 files changed

+3644
-2729
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ class JSCodeGen()(implicit ctx: Context) {
728728
else genExpr(tree)
729729

730730
//if (!isScalaJSDefinedJSClass(currentClassSym)) {
731-
val flags = js.MemberFlags.empty.withNamespace(namespace)
732-
js.MethodDef(flags, methodName, jsParams, resultIRType, Some(genBody()))(
731+
val flags = js.MemberFlags.empty.withNamespace(namespace)
732+
js.MethodDef(flags, methodName, jsParams, resultIRType, Some(genBody()))(
733733
optimizerHints, None)
734734
/*} else {
735735
assert(!namespace.isStatic, tree.span)

compiler/src/dotty/tools/backend/sjs/JSPositions.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class JSPositions()(implicit ctx: Context) {
6666
case ScalaJSOptions.URIMap(from, to) if matches(from) =>
6767
val relURI = from.relativize(srcURI)
6868
to.fold(relURI)(_.resolve(relURI))
69-
} getOrElse*/ srcURI
69+
} getOrElse*/
70+
srcURI
7071
}
7172
}
7273
}

compiler/src/dotty/tools/dotc/Driver.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ class Driver {
5959
MacroClassLoader.init(ctx)
6060
Positioned.updateDebugPos(ctx)
6161

62-
if (!ctx.settings.YdropComments.value(ctx) || ctx.mode.is(Mode.ReadComments)) {
62+
if (!ctx.settings.YdropComments.value(ctx) || ctx.mode.is(Mode.ReadComments))
6363
ctx.setProperty(ContextDoc, new ContextDocstrings)
64-
}
6564

6665
val fileNames = CompilerCommand.checkUsage(summary, sourcesRequired)(ctx)
6766
fromTastySetup(fileNames, ctx)
6867
}
6968

7069
/** Setup extra classpath and figure out class names for tasty file inputs */
71-
protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) = {
70+
protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) =
7271
if (ctx0.settings.fromTasty.value(ctx0)) {
7372
// Resolve classpath and class names of tasty files
7473
val (classPaths, classNames) = fileNames0.flatMap { name =>
@@ -98,8 +97,8 @@ class Driver {
9897
val fullClassPath = (classPaths1 :+ ctx1.settings.classpath.value(ctx1)).mkString(java.io.File.pathSeparator)
9998
ctx1.setSetting(ctx1.settings.classpath, fullClassPath)
10099
(classNames, ctx1)
101-
} else (fileNames0, ctx0)
102-
}
100+
}
101+
else (fileNames0, ctx0)
103102

104103
/** Entry point to the compiler that can be conveniently used with Java reflection.
105104
*

compiler/src/dotty/tools/dotc/Run.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
102102
def compile(fileNames: List[String]): Unit = try {
103103
val sources = fileNames.map(ctx.getSource(_))
104104
compileSources(sources)
105-
} catch {
105+
}
106+
catch {
106107
case NonFatal(ex) =>
107108
ctx.echo(i"exception occurred while compiling $units%, %")
108109
throw ex
@@ -157,12 +158,10 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
157158
val profileBefore = profiler.beforePhase(phase)
158159
units = phase.runOn(units)
159160
profiler.afterPhase(phase, profileBefore)
160-
if (ctx.settings.Xprint.value.containsPhase(phase)) {
161-
for (unit <- units) {
161+
if (ctx.settings.Xprint.value.containsPhase(phase))
162+
for (unit <- units)
162163
lastPrintedTree =
163164
printTree(lastPrintedTree)(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
164-
}
165-
}
166165
ctx.informTime(s"$phase ", start)
167166
Stats.record(s"total trees at end of $phase", ast.Trees.ntrees)
168167
for (unit <- units)

compiler/src/dotty/tools/dotc/ast/Desugar.scala

+17-12
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ object desugar {
308308
* case '{ @patternBindHole def `$a`(...) = ...; ... `$a`() ... } => a
309309
* ```
310310
*/
311-
def transformQuotedPatternName(tree: ValOrDefDef)(implicit ctx: Context): ValOrDefDef = {
311+
def transformQuotedPatternName(tree: ValOrDefDef)(implicit ctx: Context): ValOrDefDef =
312312
if (ctx.mode.is(Mode.QuotedPattern) && !isBackquoted(tree) && tree.name != nme.ANON_FUN && tree.name.startsWith("$")) {
313313
val mods = tree.mods.withAddedAnnotation(New(ref(defn.InternalQuoted_patternBindHoleAnnot.typeRef)).withSpan(tree.span))
314314
tree.withMods(mods)
315-
} else tree
316-
}
315+
}
316+
else tree
317317

318318
/** Add an explicit ascription to the `expectedTpt` to every tail splice.
319319
*
@@ -926,7 +926,8 @@ object desugar {
926926
val patternBindHoleAnnot = New(ref(defn.InternalQuoted_patternBindHoleAnnot.typeRef)).withSpan(tree.span)
927927
val mods = tree.mods.withAddedAnnotation(patternBindHoleAnnot)
928928
tree.withMods(mods)
929-
} else tree
929+
}
930+
else tree
930931
}
931932

932933
/** The normalized name of `mdef`. This means
@@ -953,7 +954,8 @@ object desugar {
953954
impl.body.find {
954955
case dd: DefDef if dd.mods.is(Extension) => true
955956
case _ => false
956-
} match {
957+
}
958+
match {
957959
case Some(DefDef(name, _, (vparam :: _) :: _, _, _)) =>
958960
s"${name}_of_${inventTypeName(vparam.tpt)}"
959961
case _ =>
@@ -1007,7 +1009,7 @@ object desugar {
10071009
case id: Ident =>
10081010
expandSimpleEnumCase(id.name.asTermName, mods,
10091011
Span(id.span.start, id.span.end, id.span.start))
1010-
}
1012+
}
10111013
else {
10121014
val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
10131015
pats1 map (makePatDef(pdef, mods, _, rhs))
@@ -1068,7 +1070,7 @@ object desugar {
10681070
if (tupleOptimizable) // include `_`
10691071
pat match {
10701072
case Tuple(pats) =>
1071-
pats.map { case id: Ident => id -> TypeTree() }
1073+
pats.map { case id: Ident => id -> TypeTree() }
10721074
}
10731075
else getVariables(pat) // no `_`
10741076

@@ -1127,11 +1129,12 @@ object desugar {
11271129
case tree: MemberDef =>
11281130
var tested: MemberDef = tree
11291131
def fail(msg: String) = ctx.error(msg, tree.sourcePos)
1130-
def checkApplicable(flag: Flag, test: MemberDefTest): Unit =
1132+
def checkApplicable(flag: Flag, test: MemberDefTest): Unit = {
11311133
if (tested.mods.is(flag) && !test.applyOrElse(tree, (md: MemberDef) => false)) {
11321134
fail(i"modifier `${flag.flagsString}` is not allowed for this definition")
11331135
tested = tested.withMods(tested.mods.withoutFlags(flag))
11341136
}
1137+
}
11351138
checkApplicable(Opaque, legalOpaque)
11361139
tested
11371140
case _ =>
@@ -1296,7 +1299,7 @@ object desugar {
12961299
if (isGenericTuple) Apply(Select(refOfDef(param), nme.apply), Literal(Constant(n)))
12971300
else Select(refOfDef(param), nme.selectorName(n))
12981301
val vdefs =
1299-
params.zipWithIndex.map{
1302+
params.zipWithIndex.map {
13001303
case (param, idx) =>
13011304
DefDef(param.name, Nil, Nil, TypeTree(), selector(idx)).withSpan(param.span)
13021305
}
@@ -1338,7 +1341,7 @@ object desugar {
13381341
.withSpan(original.span.withPoint(named.span.start))
13391342
val mayNeedSetter = valDef(vdef)
13401343
mayNeedSetter
1341-
}
1344+
}
13421345

13431346
private def derivedDefDef(original: Tree, named: NameTree, tpt: Tree, rhs: Tree, mods: Modifiers)(implicit src: SourceFile) =
13441347
DefDef(named.name.asTermName, Nil, Nil, tpt, rhs)
@@ -1551,7 +1554,8 @@ object desugar {
15511554
RefinedTypeTree(polyFunctionTpt, List(
15521555
DefDef(nme.apply, applyTParams, List(applyVParams), res, EmptyTree)
15531556
))
1554-
} else {
1557+
}
1558+
else {
15551559
// Desugar [T_1, ..., T_M] -> (x_1: P_1, ..., x_N: P_N) => body
15561560
// Into new scala.PolyFunction { def apply[T_1, ..., T_M](x_1: P_1, ..., x_N: P_N) = body }
15571561

@@ -1606,7 +1610,8 @@ object desugar {
16061610
Annotated(
16071611
AppliedTypeTree(ref(seqType), t),
16081612
New(ref(defn.RepeatedAnnot.typeRef), Nil :: Nil))
1609-
} else {
1613+
}
1614+
else {
16101615
assert(ctx.mode.isExpr || ctx.reporter.errorsReported || ctx.mode.is(Mode.Interactive), ctx.mode)
16111616
Select(t, op.name)
16121617
}

compiler/src/dotty/tools/dotc/ast/MainProxies.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object MainProxies {
4545
def pos = mainFun.sourcePos
4646
val argsRef = Ident(nme.args)
4747

48-
def addArgs(call: untpd.Tree, mt: MethodType, idx: Int): untpd.Tree = {
48+
def addArgs(call: untpd.Tree, mt: MethodType, idx: Int): untpd.Tree =
4949
if (mt.isImplicitMethod) {
5050
ctx.error(s"@main method cannot have implicit parameters", pos)
5151
call
@@ -71,7 +71,6 @@ object MainProxies {
7171
call1
7272
}
7373
}
74-
}
7574

7675
var result: List[TypeDef] = Nil
7776
if (!mainFun.owner.isStaticOwner)

compiler/src/dotty/tools/dotc/ast/NavigateAST.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ object NavigateAST {
9797
case _ =>
9898
}
9999
childPath(p.productIterator, p :: path)
100-
} else path
100+
}
101+
else path
101102
singlePath(from, Nil)
102103
}
103104
}

compiler/src/dotty/tools/dotc/ast/Positioned.scala

+7-10
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
3838
/** The span part of the item's position */
3939
def span: Span = mySpan
4040

41-
def span_=(span: Span): Unit = {
41+
def span_=(span: Span): Unit =
4242
mySpan = span
43-
}
4443

4544
uniqueId = src.nextId
4645
span = envelope(src)
@@ -58,9 +57,8 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
5857
else {
5958
val newpd: this.type =
6059
if (mySpan.isSynthetic) {
61-
if (!mySpan.exists && span.exists) {
60+
if (!mySpan.exists && span.exists)
6261
envelope(source, span.startPos) // fill in children spans
63-
}
6462
this
6563
}
6664
else cloneIn(source)
@@ -109,12 +107,11 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
109107
else if (span1.start == MaxOffset)
110108
// No positioned child was found
111109
NoSpan
112-
else {
110+
else
113111
///println(s"revisit $uniqueId with $span1")
114112
// We have some children left whose span could not be assigned.
115113
// Go through it again with the known start position.
116114
includeChildren(span1.startPos, 0)
117-
}
118115
span2.toSynthetic
119116
}
120117

@@ -145,7 +142,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
145142
found = isParent(productElement(n))
146143
}
147144
found
148-
}
145+
}
149146
}
150147

151148
/** A hook that can be overridden if overlap checking in `checkPos` should be
@@ -232,7 +229,8 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
232229
n += 1
233230
}
234231
}
235-
} catch {
232+
}
233+
catch {
236234
case ex: AssertionError =>
237235
println(i"error while checking $this")
238236
throw ex
@@ -242,7 +240,6 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
242240
object Positioned {
243241
@sharable private[Positioned] var debugId = Int.MinValue
244242

245-
def updateDebugPos(implicit ctx: Context): Unit = {
243+
def updateDebugPos(implicit ctx: Context): Unit =
246244
debugId = ctx.settings.YdebugTreeWithId.value
247-
}
248245
}

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
401401
|| fn.symbol.isPrimaryConstructor && fn.symbol.owner.isNoInitsClass) // TODO: include in isStable?
402402
minOf(exprPurity(fn), args.map(exprPurity)) `min` Pure
403403
else if (fn.symbol.is(Erased)) Pure
404-
else if (fn.symbol.isStableMember /* && fn.symbol.is(Lazy) */)
404+
else if (fn.symbol.isStableMember) /* && fn.symbol.is(Lazy) */
405405
minOf(exprPurity(fn), args.map(exprPurity)) `min` Idempotent
406406
else Impure
407407
case Typed(expr, _) =>
@@ -686,15 +686,14 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
686686
def defPath(sym: Symbol, root: Tree)(implicit ctx: Context): List[Tree] = trace.onDebug(s"defpath($sym with position ${sym.span}, ${root.show})") {
687687
require(sym.span.exists, sym)
688688
object accum extends TreeAccumulator[List[Tree]] {
689-
def apply(x: List[Tree], tree: Tree)(implicit ctx: Context): List[Tree] = {
689+
def apply(x: List[Tree], tree: Tree)(implicit ctx: Context): List[Tree] =
690690
if (tree.span.contains(sym.span))
691691
if (definedSym(tree) == sym) tree :: x
692692
else {
693693
val x1 = foldOver(x, tree)
694694
if (x1 ne x) tree :: x1 else x1
695695
}
696696
else x
697-
}
698697
}
699698
accum(Nil, root)
700699
}

compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
2828

2929
@tailrec def traverse(curStats: List[Tree])(implicit ctx: Context): List[Tree] = {
3030

31-
def recur(stats: List[Tree], changed: Tree, rest: List[Tree])(implicit ctx: Context): List[Tree] = {
31+
def recur(stats: List[Tree], changed: Tree, rest: List[Tree])(implicit ctx: Context): List[Tree] =
3232
if (stats eq curStats) {
3333
val rest1 = transformStats(rest, exprOwner)
3434
changed match {
@@ -37,7 +37,6 @@ class TreeMapWithImplicits extends tpd.TreeMap {
3737
}
3838
}
3939
else stats.head :: recur(stats.tail, changed, rest)
40-
}
4140

4241
curStats match {
4342
case stat :: rest =>
@@ -123,5 +122,5 @@ class TreeMapWithImplicits extends tpd.TreeMap {
123122
tree
124123
}
125124
}
126-
127125
}
126+

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ class TreeTypeMap(
189189
val origDcls = cls.info.decls.toList
190190
val mappedDcls = ctx.mapSymbols(origDcls, tmap)
191191
val tmap1 = tmap.withMappedSyms(origDcls, mappedDcls)
192-
if (symsChanged) {
192+
if (symsChanged)
193193
origDcls.lazyZip(mappedDcls).foreach(cls.asClass.replace)
194-
}
195194
tmap1
196195
}
197196
if (symsChanged || (fullMap eq substMap)) fullMap

compiler/src/dotty/tools/dotc/ast/Trees.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ object Trees {
374374
if (idx >= 0) idx
375375
else point // use `point` anyway. This is important if no source exists so scanning fails
376376
}
377-
Span(point, point + realName.length, point)
377+
Span(point, point + realName.length, point)
378378
}
379379
}
380380
else span
@@ -421,14 +421,13 @@ object Trees {
421421
extends DenotingTree[T] with TermTree[T] {
422422
type ThisTree[-T >: Untyped] = This[T]
423423
// Denotation of a This tree is always the underlying class; needs correction for modules.
424-
override def denot(implicit ctx: Context): Denotation = {
424+
override def denot(implicit ctx: Context): Denotation =
425425
typeOpt match {
426426
case tpe @ TermRef(pre, _) if tpe.symbol.is(Module) =>
427427
tpe.symbol.moduleClass.denot.asSeenFrom(pre)
428428
case _ =>
429429
super.denot
430430
}
431-
}
432431
}
433432

434433
/** C.super[mix], where qual = C.this */

0 commit comments

Comments
 (0)