Skip to content

Commit 939811b

Browse files
committed
align if then syntax
1 parent 5ee8777 commit 939811b

17 files changed

+70
-69
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ node_modules
2929
# Metals
3030
.bloop/
3131
.metals/
32-
project/metals.sbt
32+
metals.sbt
3333

3434
# Scala-IDE specific
3535
.scala_dependencies

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ sealed trait CommunityProject:
5959

6060
/** Publish this project to the local Maven repository */
6161
final def publish(): Unit =
62-
if !published
62+
if !published then
6363
log(s"Publishing $project")
64-
if publishCommand eq null
64+
if publishCommand eq null then
6565
throw RuntimeException(s"Publish command is not specified for $project. Project details:\n$this")
6666
val exitCode = exec(projectDir, binaryName, (runCommandsArgs :+ publishCommand): _*)
67-
if exitCode != 0
67+
if exitCode != 0 then
6868
throw RuntimeException(s"Publish command exited with code $exitCode for project $project. Project details:\n$this")
6969
published = true
7070
end CommunityProject

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Compiler {
145145
def newRun(using Context): Run = {
146146
reset()
147147
val rctx =
148-
if ctx.settings.Ysemanticdb.value
148+
if ctx.settings.Ysemanticdb.value then
149149
ctx.addMode(Mode.ReadPositions)
150150
else
151151
ctx

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ trait ConstraintHandling {
7979

8080
protected def addOneBound(param: TypeParamRef, bound: Type, isUpper: Boolean)(using Context): Boolean =
8181
if !constraint.contains(param) then true
82-
else if !isUpper && param.occursIn(bound)
82+
else if !isUpper && param.occursIn(bound) then
8383
// We don't allow recursive lower bounds when defining a type,
8484
// so we shouldn't allow them as constraints either.
8585
false

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ object SymbolLoaders {
121121
def enterToplevelsFromSource(
122122
owner: Symbol, name: PreName, src: AbstractFile,
123123
scope: Scope = EmptyScope)(using Context): Unit =
124-
if src.exists && !src.isDirectory
124+
if src.exists && !src.isDirectory then
125125
val completer = new SourcefileLoader(src)
126126
val filePath = owner.ownersIterator.takeWhile(!_.isRoot).map(_.name.toTermName).toList
127127

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ExtractSemanticDB extends Phase:
115115
private def traverseAnnotsOfDefinition(sym: Symbol)(using Context): Unit =
116116
for annot <- sym.annotations do
117117
if annot.tree.span.exists
118-
&& annot.tree.span.hasLength
118+
&& annot.tree.span.hasLength then
119119
annot.tree match
120120
case tree: Typed => () // hack for inline code
121121
case tree => traverse(tree)
@@ -131,23 +131,23 @@ class ExtractSemanticDB extends Phase:
131131
tree match
132132
case tree: PackageDef =>
133133
if !excludeDef(tree.pid.symbol)
134-
&& tree.pid.span.hasLength
134+
&& tree.pid.span.hasLength then
135135
tree.pid match
136136
case tree: Select =>
137137
registerDefinition(tree.symbol, selectSpan(tree), Set.empty, tree.source)
138138
traverse(tree.qualifier)
139139
case tree => registerDefinition(tree.symbol, tree.span, Set.empty, tree.source)
140140
tree.stats.foreach(traverse)
141141
case tree: NamedDefTree =>
142-
if tree.symbol.isAllOf(ModuleValCreationFlags)
142+
if tree.symbol.isAllOf(ModuleValCreationFlags) then
143143
return
144144
if !excludeDef(tree.symbol)
145-
&& tree.span.hasLength
145+
&& tree.span.hasLength then
146146
registerDefinition(tree.symbol, tree.adjustedNameSpan, symbolKinds(tree), tree.source)
147147
val privateWithin = tree.symbol.privateWithin
148-
if privateWithin.exists
148+
if privateWithin.exists then
149149
registerUseGuarded(None, privateWithin, spanOfSymbol(privateWithin, tree.span, tree.source), tree.source)
150-
else if !excludeSymbol(tree.symbol)
150+
else if !excludeSymbol(tree.symbol) then
151151
registerSymbol(tree.symbol, symbolName(tree.symbol), symbolKinds(tree))
152152
tree match
153153
case tree: ValDef
@@ -158,7 +158,7 @@ class ExtractSemanticDB extends Phase:
158158
case _ => // calls $new
159159
case tree: ValDef
160160
if tree.symbol.isSelfSym =>
161-
if tree.tpt.span.hasLength
161+
if tree.tpt.span.hasLength then
162162
traverse(tree.tpt)
163163
case tree: DefDef
164164
if tree.symbol.isConstructor => // ignore typeparams for secondary ctors
@@ -171,18 +171,18 @@ class ExtractSemanticDB extends Phase:
171171
tree.tparams.foreach(tparam => registerSymbolSimple(tparam.symbol))
172172
tree.vparamss.foreach(_.foreach(vparam => registerSymbolSimple(vparam.symbol)))
173173
case _ =>
174-
if !tree.symbol.isGlobal
174+
if !tree.symbol.isGlobal then
175175
localBodies(tree.symbol) = tree.rhs
176176
// ignore rhs
177177
case PatternValDef(pat, rhs) =>
178178
traverse(rhs)
179179
PatternValDef.collectPats(pat).foreach(traverse)
180180
case tree =>
181-
if !excludeChildren(tree.symbol)
181+
if !excludeChildren(tree.symbol) then
182182
traverseChildren(tree)
183183
case tree: Template =>
184184
val ctorSym = tree.constr.symbol
185-
if !excludeDef(ctorSym)
185+
if !excludeDef(ctorSym) then
186186
traverseAnnotsOfDefinition(ctorSym)
187187
registerDefinition(ctorSym, tree.constr.span, Set.empty, tree.source)
188188
ctorParams(tree.constr.vparamss, tree.body)
@@ -191,7 +191,7 @@ class ExtractSemanticDB extends Phase:
191191
val selfSpan = tree.self.span
192192
if selfSpan.exists && selfSpan.hasLength then
193193
traverse(tree.self)
194-
if tree.symbol.owner.is(Enum, butNot=Case)
194+
if tree.symbol.owner.is(Enum, butNot=Case) then
195195
tree.body.foreachUntilImport(traverse).foreach(traverse) // the first import statement
196196
else
197197
tree.body.foreach(traverse)
@@ -206,7 +206,7 @@ class ExtractSemanticDB extends Phase:
206206
case _ => traverse(arg)
207207
case tree: Assign =>
208208
val qualSym = condOpt(tree.lhs) { case Select(qual, _) if qual.symbol.exists => qual.symbol }
209-
if !excludeUse(qualSym, tree.lhs.symbol)
209+
if !excludeUse(qualSym, tree.lhs.symbol) then
210210
val lhs = tree.lhs.symbol
211211
val setter = lhs.matchingSetter.orElse(lhs)
212212
tree.lhs match
@@ -285,7 +285,7 @@ class ExtractSemanticDB extends Phase:
285285

286286
extension (tree: NamedDefTree):
287287
private def adjustedNameSpan(using Context): Span =
288-
if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName
288+
if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName then
289289
Span(tree.span.point)
290290
else
291291
tree.nameSpan
@@ -304,7 +304,7 @@ class ExtractSemanticDB extends Phase:
304304
def addOverloadIdx(sym: Symbol): Unit =
305305
val decls =
306306
val decls0 = sym.owner.info.decls.lookupAll(sym.name)
307-
if sym.owner.isAllOf(JavaModule)
307+
if sym.owner.isAllOf(JavaModule) then
308308
decls0 ++ sym.owner.companionClass.info.decls.lookupAll(sym.name)
309309
else
310310
decls0
@@ -384,70 +384,70 @@ class ExtractSemanticDB extends Phase:
384384
Some(Range(startLine, startCol, endLine, endCol))
385385

386386
private def symbolKind(sym: Symbol, symkinds: Set[SymbolKind])(using Context): SymbolInformation.Kind =
387-
if sym.isTypeParam
387+
if sym.isTypeParam then
388388
SymbolInformation.Kind.TYPE_PARAMETER
389-
else if sym.is(TermParam)
389+
else if sym.is(TermParam) then
390390
SymbolInformation.Kind.PARAMETER
391-
else if sym.isTerm && sym.owner.isTerm
391+
else if sym.isTerm && sym.owner.isTerm then
392392
SymbolInformation.Kind.LOCAL
393-
else if sym.isInlineMethod || sym.is(Macro)
393+
else if sym.isInlineMethod || sym.is(Macro) then
394394
SymbolInformation.Kind.MACRO
395-
else if sym.isConstructor
395+
else if sym.isConstructor then
396396
SymbolInformation.Kind.CONSTRUCTOR
397-
else if sym.isSelfSym
397+
else if sym.isSelfSym then
398398
SymbolInformation.Kind.SELF_PARAMETER
399-
else if sym.isOneOf(Method) || symkinds.exists(_.isVarOrVal)
399+
else if sym.isOneOf(Method) || symkinds.exists(_.isVarOrVal) then
400400
SymbolInformation.Kind.METHOD
401-
else if sym.isPackageObject
401+
else if sym.isPackageObject then
402402
SymbolInformation.Kind.PACKAGE_OBJECT
403-
else if sym.is(Module)
403+
else if sym.is(Module) then
404404
SymbolInformation.Kind.OBJECT
405-
else if sym.is(Package)
405+
else if sym.is(Package) then
406406
SymbolInformation.Kind.PACKAGE
407-
else if sym.isAllOf(JavaInterface)
407+
else if sym.isAllOf(JavaInterface) then
408408
SymbolInformation.Kind.INTERFACE
409-
else if sym.is(Trait)
409+
else if sym.is(Trait) then
410410
SymbolInformation.Kind.TRAIT
411-
else if sym.isClass
411+
else if sym.isClass then
412412
SymbolInformation.Kind.CLASS
413-
else if sym.isType
413+
else if sym.isType then
414414
SymbolInformation.Kind.TYPE
415-
else if sym.is(ParamAccessor)
415+
else if sym.is(ParamAccessor) then
416416
SymbolInformation.Kind.FIELD
417417
else
418418
SymbolInformation.Kind.UNKNOWN_KIND
419419

420420
private def symbolProps(sym: Symbol, symkinds: Set[SymbolKind])(using Context): Int =
421-
if sym.is(ModuleClass)
421+
if sym.is(ModuleClass) then
422422
return symbolProps(sym.sourceModule, symkinds)
423423
var props = 0
424-
if sym.isPrimaryConstructor
424+
if sym.isPrimaryConstructor then
425425
props |= SymbolInformation.Property.PRIMARY.value
426-
if sym.is(Abstract) || symkinds.contains(SymbolKind.Abstract)
426+
if sym.is(Abstract) || symkinds.contains(SymbolKind.Abstract) then
427427
props |= SymbolInformation.Property.ABSTRACT.value
428-
if sym.is(Final)
428+
if sym.is(Final) then
429429
props |= SymbolInformation.Property.FINAL.value
430-
if sym.is(Sealed)
430+
if sym.is(Sealed) then
431431
props |= SymbolInformation.Property.SEALED.value
432-
if sym.isOneOf(GivenOrImplicit)
432+
if sym.isOneOf(GivenOrImplicit) then
433433
props |= SymbolInformation.Property.IMPLICIT.value
434-
if sym.is(Lazy, butNot=Module)
434+
if sym.is(Lazy, butNot=Module) then
435435
props |= SymbolInformation.Property.LAZY.value
436-
if sym.isAllOf(Case | Module) || sym.is(CaseClass) || sym.isAllOf(EnumCase)
436+
if sym.isAllOf(Case | Module) || sym.is(CaseClass) || sym.isAllOf(EnumCase) then
437437
props |= SymbolInformation.Property.CASE.value
438-
if sym.is(Covariant)
438+
if sym.is(Covariant) then
439439
props |= SymbolInformation.Property.COVARIANT.value
440-
if sym.is(Contravariant)
440+
if sym.is(Contravariant) then
441441
props |= SymbolInformation.Property.CONTRAVARIANT.value
442-
if sym.isAllOf(DefaultMethod | JavaDefined) || sym.is(Accessor) && sym.name.is(NameKinds.DefaultGetterName)
442+
if sym.isAllOf(DefaultMethod | JavaDefined) || sym.is(Accessor) && sym.name.is(NameKinds.DefaultGetterName) then
443443
props |= SymbolInformation.Property.DEFAULT.value
444-
if symkinds.exists(_.isVal)
444+
if symkinds.exists(_.isVal) then
445445
props |= SymbolInformation.Property.VAL.value
446-
if symkinds.exists(_.isVar)
446+
if symkinds.exists(_.isVar) then
447447
props |= SymbolInformation.Property.VAR.value
448-
if sym.is(JavaStatic)
448+
if sym.is(JavaStatic) then
449449
props |= SymbolInformation.Property.STATIC.value
450-
if sym.is(Enum)
450+
if sym.is(Enum) then
451451
props |= SymbolInformation.Property.ENUM.value
452452
props
453453

@@ -462,8 +462,8 @@ class ExtractSemanticDB extends Phase:
462462

463463
private def registerSymbol(sym: Symbol, symbolName: String, symkinds: Set[SymbolKind])(using Context): Unit =
464464
val isLocal = symbolName.isLocal
465-
if !isLocal || !localNames.contains(symbolName)
466-
if isLocal
465+
if !isLocal || !localNames.contains(symbolName) then
466+
if isLocal then
467467
localNames += symbolName
468468
symbolInfos += symbolInfo(sym, symbolName, symkinds)
469469

@@ -489,7 +489,7 @@ class ExtractSemanticDB extends Phase:
489489
private def registerDefinition(sym: Symbol, span: Span, symkinds: Set[SymbolKind], treeSource: SourceFile)(using Context) =
490490
val symbol = symbolName(sym)
491491
registerOccurrence(symbol, span, SymbolOccurrence.Role.DEFINITION, treeSource)
492-
if !sym.is(Package)
492+
if !sym.is(Package) then
493493
registerSymbol(sym, symbol, symkinds)
494494

495495
private def spanOfSymbol(sym: Symbol, span: Span, treeSource: SourceFile)(using Context): Span =

compiler/src/dotty/tools/dotc/semanticdb/Tools.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object Tools:
3434
val text = new String(Files.readAllBytes(scalaAbsolutePath), StandardCharsets.UTF_8)
3535
// Assert the SemanticDB payload is in-sync with the contents of the Scala file on disk.
3636
val md5FingerprintOnDisk = internal.MD5.compute(text)
37-
if document.md5 != md5FingerprintOnDisk
37+
if document.md5 != md5FingerprintOnDisk then
3838
throw new IllegalArgumentException(s"stale semanticdb: $scalaRelativePath")
3939
else
4040
// Update text document to include full text contents of the file.
@@ -132,7 +132,7 @@ object Tools:
132132
.append("):")
133133
if range.endLine == range.startLine
134134
&& range.startCharacter != range.endCharacter
135-
&& !(occ.symbol.isConstructor && occ.role.isDefinition)
135+
&& !(occ.symbol.isConstructor && occ.role.isDefinition) then
136136
val line = sourceFile.lineContent(sourceFile.lineToOffset(range.startLine))
137137
assert(range.startCharacter <= line.length && range.endCharacter <= line.length,
138138
s"Line is only ${line.length} - start line was ${range.startLine} in source ${sourceFile.name}"

compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase =>
8686
/** If this is a constructor of a enum class that extends, add $name and $ordinal parameters to it. */
8787
override def transformDefDef(tree: DefDef)(using Context): DefDef = {
8888
val sym = tree.symbol
89-
if (sym.isConstructor && sym.owner.derivesFromJavaEnum)
89+
if sym.isConstructor && sym.owner.derivesFromJavaEnum then
9090
val tree1 = cpy.DefDef(tree)(
9191
vparamss = tree.vparamss.init :+ (tree.vparamss.last ++ addedParams(sym, isLocal=false, Param)))
9292
sym.setParamssFromDefs(tree1.tparams, tree1.vparamss)

compiler/src/dotty/tools/dotc/transform/Constructors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
211211
if stat.symbol.isGetter && stat.symbol.owner.is(Trait) && !stat.symbol.is(Lazy) =>
212212
val sym = stat.symbol
213213
assert(isRetained(sym), sym)
214-
if (!stat.rhs.isEmpty && !isWildcardArg(stat.rhs))
214+
if !stat.rhs.isEmpty && !isWildcardArg(stat.rhs) then
215215
/* !!! Work around #9390
216216
* This should really just be `sym.setter`. However, if we do that, we'll miss
217217
* setters for mixed in `private var`s. Even though the scope clearly contains the

compiler/src/dotty/tools/dotc/transform/DropOuterAccessors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ class DropOuterAccessors extends MiniPhase with IdentityDenotTransformer:
8383
when dropping outer accessors for ${ctx.owner} with
8484
$impl""")
8585
cpy.Template(impl)(constr = constr1, body = body1)
86-
end transformTemplate
86+
end transformTemplate

compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
5555
sym.sourcePos)
5656
else
5757
addVarArgsForwarder(sym, isJavaVarargsOverride, hasAnnotation)
58-
else if hasAnnotation
58+
else if hasAnnotation then
5959
report.error("A method without repeated parameters cannot be annotated with @varargs", sym.sourcePos)
6060
end
6161

compiler/src/dotty/tools/dotc/transform/Getters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Getters extends MiniPhase with SymTransformer { thisPhase =>
112112

113113
override def transformAssign(tree: Assign)(using Context): Tree =
114114
val lsym = tree.lhs.symbol.asTerm
115-
if (lsym.is(Method))
115+
if lsym.is(Method) then
116116
ensureSetter(lsym)
117117
tree.lhs.becomes(tree.rhs).withSpan(tree.span)
118118
else tree

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Pickler extends Phase {
108108

109109
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
110110
val result = super.runOn(units)
111-
if ctx.settings.YtestPickler.value
111+
if ctx.settings.YtestPickler.value then
112112
testUnpickler(
113113
using ctx.fresh
114114
.setPeriod(Period(ctx.runId + 1, FirstPhaseId))

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ object Splicer {
252252
val staticMethodCall = interpretedStaticMethodCall(fn.symbol.owner, fn.symbol)
253253
staticMethodCall(args.flatten.map(interpretTree))
254254
}
255-
else if (fn.symbol.isStatic)
255+
else if fn.symbol.isStatic then
256256
assert(args.isEmpty)
257257
interpretedStaticFieldAccess(fn.symbol)
258258
else if (fn.qualifier.symbol.is(Module) && fn.qualifier.symbol.isStatic)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ object Inliner {
7272
def inlineCall(tree: Tree)(using Context): Tree = {
7373
val startId = ctx.source.nextId
7474

75-
if tree.symbol.denot != SymDenotations.NoDenotation && tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject
75+
if tree.symbol.denot != SymDenotations.NoDenotation
76+
&& tree.symbol.owner.companionModule == defn.CompiletimeTestingPackageObject then
7677
if (tree.symbol == defn.CompiletimeTesting_typeChecks) return Intrinsics.typeChecks(tree)
7778
if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors) return Intrinsics.typeCheckErrors(tree)
7879

@@ -298,7 +299,7 @@ object Inliner {
298299

299300
val parseErrors = ctx2.reporter.allErrors.toList
300301
res ++= parseErrors.map(e => ErrorKind.Parser -> e)
301-
if !stopAfterParser || res.isEmpty
302+
if !stopAfterParser || res.isEmpty then
302303
ctx2.typer.typed(tree2)(using ctx2)
303304
val typerErrors = ctx2.reporter.allErrors.filterNot(parseErrors.contains)
304305
res ++= typerErrors.map(e => ErrorKind.Typer -> e)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ trait QuotesAndSplices {
152152
case _ =>
153153
}
154154

155-
if (ctx.mode.is(Mode.QuotedPattern) && level == 1)
155+
if ctx.mode.is(Mode.QuotedPattern) && level == 1 then
156156
def spliceOwner(ctx: Context): Symbol =
157157
if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner
158158
val name = tree.expr match {

0 commit comments

Comments
 (0)