Skip to content

Commit fc14d02

Browse files
committed
Make files invariant under rewriting
1 parent 62705f1 commit fc14d02

Some content is hidden

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

49 files changed

+196
-261
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,21 @@ class Driver {
7272
// Resolve classpath and class names of tasty files
7373
val (classPaths, classNames) = fileNames0.flatMap { name =>
7474
val path = Paths.get(name)
75-
if (name.endsWith(".jar")) {
75+
if (name.endsWith(".jar"))
7676
new dotty.tools.io.Jar(File(name)).toList.collect {
7777
case e if e.getName.endsWith(".tasty") =>
7878
(name, e.getName.stripSuffix(".tasty").replace("/", "."))
7979
}
80-
}
8180
else if (!name.endsWith(".tasty"))
8281
("", name) :: Nil
83-
else if (Files.exists(path)) {
82+
else if (Files.exists(path))
8483
TastyFileUtil.getClassName(path) match {
8584
case Some(res) => res:: Nil
8685
case _ =>
8786
ctx0.error(s"Could not load classname from $name.")
8887
("", name) :: Nil
8988
}
90-
} else {
89+
else {
9190
ctx0.error(s"File $name does not exist.")
9291
("", name) :: Nil
9392
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,9 @@ object desugar {
454454
if (isCaseClass)
455455
ctx.error(CaseClassMissingParamList(cdef), namePos)
456456
ListOfNil
457-
} else if (isCaseClass && originalVparamss.head.exists(_.mods.isOneOf(GivenOrImplicit))) {
458-
ctx.error("Case classes should have a non-implicit parameter list", namePos)
457+
}
458+
else if (isCaseClass && originalVparamss.head.exists(_.mods.isOneOf(GivenOrImplicit))) {
459+
ctx.error("Case classes should have a non-implicit parameter list", namePos)
459460
ListOfNil
460461
}
461462
else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = false))
@@ -717,12 +718,11 @@ object desugar {
717718
}
718719
else if (companionMembers.nonEmpty || companionDerived.nonEmpty || isEnum)
719720
companionDefs(anyRef, companionMembers)
720-
else if (isValueClass) {
721+
else if (isValueClass)
721722
impl.constr.vparamss match {
722723
case (_ :: Nil) :: _ => companionDefs(anyRef, Nil)
723724
case _ => Nil // error will be emitted in typer
724725
}
725-
}
726726
else Nil
727727

728728
enumCompanionRef match {
@@ -1129,12 +1129,11 @@ object desugar {
11291129
case tree: MemberDef =>
11301130
var tested: MemberDef = tree
11311131
def fail(msg: String) = ctx.error(msg, tree.sourcePos)
1132-
def checkApplicable(flag: Flag, test: MemberDefTest): Unit = {
1132+
def checkApplicable(flag: Flag, test: MemberDefTest): Unit =
11331133
if (tested.mods.is(flag) && !test.applyOrElse(tree, (md: MemberDef) => false)) {
11341134
fail(i"modifier `${flag.flagsString}` is not allowed for this definition")
11351135
tested = tested.withMods(tested.mods.withoutFlags(flag))
11361136
}
1137-
}
11381137
checkApplicable(Opaque, legalOpaque)
11391138
tested
11401139
case _ =>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
4242
if (param.info.isRepeatedParam) {
4343
for (arg <- args) f(param, arg)
4444
true
45-
} else args match {
45+
}
46+
else args match {
4647
case Nil => false
4748
case arg :: args1 =>
4849
f(param, args.head)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ object Trees {
14671467
case _ =>
14681468
foldMoreCases(x, tree)
14691469
}
1470-
}
1470+
}
14711471

14721472
def foldMoreCases(x: X, tree: Tree)(implicit ctx: Context): X = {
14731473
assert(ctx.reporter.errorsReported || ctx.mode.is(Mode.Interactive), tree)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class CheckRealizable(implicit ctx: Context) {
107107
if (tp.info.isStable && tpInfoRealizable == Realizable) {
108108
sym.setFlag(StableRealizable)
109109
Realizable
110-
} else r
110+
}
111+
else r
111112
}
112113
}
113114
case _: SingletonType | NoPrefix =>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ object Comments {
371371
superComment(sym) foreach { sc =>
372372
val superSections = tagIndex(sc)
373373
replaceWith(sc.substring(3, startTag(sc, superSections)))
374-
for (sec @ (start, end) <- superSections) {
374+
for (sec @ (start, end) <- superSections)
375375
if (!isMovable(sc, sec)) out append sc.substring(start, end)
376-
}
377376
}
378377
case "" => idx += 1
379378
case vname =>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ object Names {
390390
override def toString: String =
391391
if (length == 0) ""
392392
else {
393-
if (Config.checkBackendNames) {
393+
if (Config.checkBackendNames)
394394
if (!toStringOK) {
395395
// We print the stacktrace instead of doing an assert directly,
396396
// because asserts are caught in exception handlers which might
@@ -400,7 +400,6 @@ object Names {
400400
Thread.dumpStack()
401401
assert(false)
402402
}
403-
}
404403
new String(chrs, start, length)
405404
}
406405

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,11 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
484484

485485
def foreachTypeVar(op: TypeVar => Unit): Unit =
486486
boundsMap.foreachBinding { (poly, entries) =>
487-
for (i <- 0 until paramCount(entries)) {
487+
for (i <- 0 until paramCount(entries))
488488
typeVar(entries, i) match {
489489
case tv: TypeVar if !tv.inst.exists => op(tv)
490490
case _ =>
491491
}
492-
}
493492
}
494493

495494
def & (other: Constraint, otherHasErrors: Boolean)(implicit ctx: Context): OrderingConstraint = {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,19 @@ trait SymDenotations { this: Context =>
8686
else {
8787
implicit val ctx = this
8888
val initial = denot.initial
89-
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId) {
89+
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId)
9090
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)
91-
} else try {
91+
else try {
9292
val owner = denot.owner.denot
9393
if (!traceInvalid(owner)) explainSym("owner is invalid")
9494
else if (!owner.isClass || owner.isRefinementClass || denot.isSelfSym) true
9595
else if (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol) true
9696
else explainSym(s"decls of ${show(owner)} are ${owner.unforcedDecls.lookupAll(denot.name).toList}, do not contain ${denot.symbol}")
97-
} catch {
97+
}
98+
catch {
9899
case ex: StaleSymbol => explainSym(s"$ex was thrown")
99100
}
100-
}
101+
}
101102
case _ =>
102103
explain("denotation is not a SymDenotation")
103104
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
466466

467467
case _ =>
468468
val cls2 = tp2.symbol
469-
if (cls2.isClass) {
469+
if (cls2.isClass)
470470
if (cls2.typeParams.isEmpty) {
471471
if (cls2 eq AnyKindClass) return true
472472
if (tp1.isRef(NothingClass)) return true
@@ -485,7 +485,6 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
485485
}
486486
else if (tp1.isLambdaSub && !tp1.isRef(AnyKindClass))
487487
return recur(tp1, EtaExpansion(cls2.typeRef))
488-
}
489488
fourthTry
490489
}
491490

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
6868
case pre: SuperType => toPrefix(pre.thistpe, cls, thiscls)
6969
case _ =>
7070
if (thiscls.derivesFrom(cls) && pre.baseType(thiscls).exists)
71-
if (variance <= 0 && !isLegalPrefix(pre)) {
71+
if (variance <= 0 && !isLegalPrefix(pre))
7272
if (variance < 0) {
7373
approximated = true
7474
defn.NothingType
@@ -80,7 +80,6 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
8080
// is not possible, then `expandBounds` will end up being
8181
// called which we override to set the `approximated` flag.
8282
range(defn.NothingType, pre)
83-
}
8483
else pre
8584
else if ((pre.termSymbol is Package) && !(thiscls is Package))
8685
toPrefix(pre.select(nme.PACKAGE), cls, thiscls)

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,8 @@ object Types {
646646
else tp
647647
rt.opened = true
648648
try go(rt.parent).mapInfo(_.substRecThis(rt, pre))
649-
finally {
649+
finally
650650
if (!rt.openedTwice) rt.opened = false
651-
}
652651
}
653652

654653
def goRefined(tp: RefinedType) = {
@@ -1359,11 +1358,10 @@ object Types {
13591358
case tp @ AppliedType(tycon, args) if tycon.typeSymbol.isClass =>
13601359
tycon.parents.map(_.subst(tycon.typeSymbol.typeParams, args))
13611360
case tp: TypeRef =>
1362-
if (tp.info.isInstanceOf[TempClassInfo]) {
1361+
if (tp.info.isInstanceOf[TempClassInfo])
13631362
tp.recomputeDenot()
13641363
// We usually should have `!tp.info.isInstanceOf[TempClassInfo]` here, but
13651364
// this can be falsified for code with illegal cyclic references. See neg/i7107.scala.
1366-
}
13671365
tp.info.parents
13681366
case tp: TypeProxy =>
13691367
tp.superType.parents
@@ -2104,9 +2102,9 @@ object Types {
21042102
try {
21052103
ctx.pendingUnderlying += this
21062104
op
2107-
} finally {
2108-
ctx.pendingUnderlying -= this
21092105
}
2106+
finally
2107+
ctx.pendingUnderlying -= this
21102108
}
21112109
finally
21122110
ctx.base.underlyingRecursions -= 1
@@ -4767,7 +4765,7 @@ object Types {
47674765
case _ =>
47684766
tp.derivedRefinedType(parent, tp.refinedName, info)
47694767
}
4770-
}
4768+
}
47714769

47724770
override protected def derivedRecType(tp: RecType, parent: Type): Type =
47734771
if (parent eq tp.parent) tp
@@ -4801,7 +4799,7 @@ object Types {
48014799
case Range(tyconLo, tyconHi) =>
48024800
range(derivedAppliedType(tp, tyconLo, args), derivedAppliedType(tp, tyconHi, args))
48034801
case _ =>
4804-
if (args.exists(isRange)) {
4802+
if (args.exists(isRange))
48054803
if (variance > 0) tp.derivedAppliedType(tycon, args.map(rangeToBounds))
48064804
else {
48074805
val loBuf, hiBuf = new mutable.ListBuffer[Type]
@@ -4833,7 +4831,6 @@ object Types {
48334831
else range(defn.NothingType, defn.AnyType)
48344832
// TODO: can we give a better bound than `topType`?
48354833
}
4836-
}
48374834
else tp.derivedAppliedType(tycon, args)
48384835
}
48394836

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
742742
def tparamsText[T >: Untyped](params: List[Tree[T]]): Text =
743743
"[" ~ toText(params, ", ") ~ "]" provided params.nonEmpty
744744

745-
def addVparamssText[T >: Untyped](leading: Text, vparamss: List[List[ValDef[T]]]): Text = {
745+
def addVparamssText[T >: Untyped](leading: Text, vparamss: List[List[ValDef[T]]]): Text =
746746
vparamss.foldLeft(leading)((txt, params) =>
747747
txt ~
748748
(Str(" given ") provided params.nonEmpty && params.head.mods.is(Given)) ~
749749
paramsText(params))
750-
}
751750
protected def valDefToText[T >: Untyped](tree: ValDef[T]): Text = {
752751
import untpd.{modsDeco => _}
753752
dclTextOr(tree) {

compiler/src/dotty/tools/dotc/reporting/trace.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ abstract class TraceSyntax {
9898
if (ctx.mode.is(Mode.Printing)) op
9999
else {
100100
var finalized = false
101-
def finalize(result: Any, note: String) = {
101+
def finalize(result: Any, note: String) =
102102
if (!finalized) {
103103
ctx.base.indent -= 1
104104
log(s"${ctx.base.indentTab * ctx.base.indent}${trailing(result)}$note")
105105
finalized = true
106106
}
107-
}
108107
try {
109108
log(s"${ctx.base.indentTab * ctx.base.indent}$leading")
110109
ctx.base.indent += 1

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
8282
*/
8383
def refClass(cls: Symbol, isVolatile: Boolean)(implicit ctx: Context): Symbol = {
8484
val refMap = if (isVolatile) refInfo.volatileRefClass else refInfo.refClass
85-
if (cls.isClass) {
85+
if (cls.isClass)
8686
refMap.getOrElse(cls, refMap(defn.ObjectClass))
87-
}
8887
else refMap(defn.ObjectClass)
8988
}
9089

@@ -108,7 +107,8 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
108107
cpy.ValDef(vdef)(
109108
rhs = boxMethod(nme.create).appliedTo(vdef.rhs),
110109
tpt = TypeTree(vble.info).withSpan(vdef.tpt.span))
111-
} else vdef
110+
}
111+
else vdef
112112
}
113113

114114
override def transformIdent(id: Ident)(implicit ctx: Context): Tree = {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ class CheckReentrant extends MiniPhase {
5555
finally indent -= 1
5656
}
5757

58-
def addVars(cls: ClassSymbol)(implicit ctx: Context): Unit = {
58+
def addVars(cls: ClassSymbol)(implicit ctx: Context): Unit =
5959
if (!seen.contains(cls) && !isIgnored(cls)) {
6060
seen += cls
6161
scanning(cls) {
62-
for (sym <- cls.classInfo.decls) {
63-
if (sym.isTerm && !sym.isSetter && !isIgnored(sym)) {
62+
for (sym <- cls.classInfo.decls)
63+
if (sym.isTerm && !sym.isSetter && !isIgnored(sym))
6464
if (sym.is(Mutable)) {
6565
ctx.error(
6666
i"""possible data race involving globally reachable ${sym.showLocated}: ${sym.info}
@@ -71,13 +71,10 @@ class CheckReentrant extends MiniPhase {
7171
scanning(sym) {
7272
sym.info.widenExpr.classSymbols.foreach(addVars)
7373
}
74-
}
75-
}
7674
for (parent <- cls.classInfo.classParents)
7775
addVars(parent.classSymbol.asClass)
7876
}
7977
}
80-
}
8178

8279
override def transformTemplate(tree: Template)(implicit ctx: Context): Tree = {
8380
if (ctx.settings.YcheckReentrant.value && tree.symbol.owner.isStaticOwner)

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
7474
}
7575
else retain()
7676
case _ => retain()
77-
}
77+
}
7878
}
7979
}
8080

@@ -159,14 +159,12 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
159159
if (noDirectRefsFrom(tree)) tree else super.transform(tree)
160160
}
161161

162-
def apply(tree: Tree, prevOwner: Symbol)(implicit ctx: Context): Tree = {
162+
def apply(tree: Tree, prevOwner: Symbol)(implicit ctx: Context): Tree =
163163
transform(tree).changeOwnerAfter(prevOwner, constr.symbol, thisPhase)
164-
}
165164
}
166165

167-
def isRetained(acc: Symbol) = {
166+
def isRetained(acc: Symbol) =
168167
!mightBeDropped(acc) || retainedPrivateVals(acc)
169-
}
170168

171169
val constrStats, clsStats = new mutable.ListBuffer[Tree]
172170

@@ -223,7 +221,8 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
223221
if (!isRetained(acc)) {
224222
dropped += acc
225223
Nil
226-
} else {
224+
}
225+
else {
227226
if (acc.hasAnnotation(defn.TransientParamAnnot))
228227
ctx.error(em"transient parameter $acc is retained as field in class ${acc.owner}", acc.sourcePos)
229228
val target = if (acc.is(Method)) acc.field else acc
@@ -250,7 +249,6 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
250249
cls.copy(
251250
info = clsInfo.derivedClassInfo(
252251
decls = clsInfo.decls.filteredScope(!dropped.contains(_))))
253-
254252
// TODO: this happens to work only because Constructors is the last phase in group
255253
}
256254

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
5454
if (paramTypes.nonEmpty && paramTypes.last.isRepeatedParam) {
5555
val last = paramTypes.last.underlyingIfRepeated(tp.isJavaMethod)
5656
paramTypes.init :+ last
57-
} else paramTypes
57+
}
58+
else paramTypes
5859
tp.derivedLambdaType(paramNames, paramTypes1, resultType1)
5960
case tp: PolyType =>
6061
tp.derivedLambdaType(tp.paramNames, tp.paramInfos, elimRepeated(tp.resultType))

0 commit comments

Comments
 (0)