Skip to content

Fixes to indentation rewrites #7180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,21 @@ class Driver {
// Resolve classpath and class names of tasty files
val (classPaths, classNames) = fileNames0.flatMap { name =>
val path = Paths.get(name)
if (name.endsWith(".jar")) {
if (name.endsWith(".jar"))
new dotty.tools.io.Jar(File(name)).toList.collect {
case e if e.getName.endsWith(".tasty") =>
(name, e.getName.stripSuffix(".tasty").replace("/", "."))
}
}
else if (!name.endsWith(".tasty"))
("", name) :: Nil
else if (Files.exists(path)) {
else if (Files.exists(path))
TastyFileUtil.getClassName(path) match {
case Some(res) => res:: Nil
case _ =>
ctx0.error(s"Could not load classname from $name.")
("", name) :: Nil
}
} else {
else {
ctx0.error(s"File $name does not exist.")
("", name) :: Nil
}
Expand Down
11 changes: 5 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ object desugar {
if (isCaseClass)
ctx.error(CaseClassMissingParamList(cdef), namePos)
ListOfNil
} else if (isCaseClass && originalVparamss.head.exists(_.mods.isOneOf(GivenOrImplicit))) {
ctx.error("Case classes should have a non-implicit parameter list", namePos)
}
else if (isCaseClass && originalVparamss.head.exists(_.mods.isOneOf(GivenOrImplicit))) {
ctx.error("Case classes should have a non-implicit parameter list", namePos)
ListOfNil
}
else originalVparamss.nestedMap(toDefParam(_, keepAnnotations = false))
Expand Down Expand Up @@ -717,12 +718,11 @@ object desugar {
}
else if (companionMembers.nonEmpty || companionDerived.nonEmpty || isEnum)
companionDefs(anyRef, companionMembers)
else if (isValueClass) {
else if (isValueClass)
impl.constr.vparamss match {
case (_ :: Nil) :: _ => companionDefs(anyRef, Nil)
case _ => Nil // error will be emitted in typer
}
}
else Nil

enumCompanionRef match {
Expand Down Expand Up @@ -1133,12 +1133,11 @@ object desugar {
case tree: MemberDef =>
var tested: MemberDef = tree
def fail(msg: String) = ctx.error(msg, tree.sourcePos)
def checkApplicable(flag: Flag, test: MemberDefTest): Unit = {
def checkApplicable(flag: Flag, test: MemberDefTest): Unit =
if (tested.mods.is(flag) && !test.applyOrElse(tree, (md: MemberDef) => false)) {
fail(i"modifier `${flag.flagsString}` is not allowed for this definition")
tested = tested.withMods(tested.mods.withoutFlags(flag))
}
}
checkApplicable(Opaque, legalOpaque)
tested
case _ =>
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
if (param.info.isRepeatedParam) {
for (arg <- args) f(param, arg)
true
} else args match {
}
else args match {
case Nil => false
case arg :: args1 =>
f(param, args.head)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ object Trees {
case _ =>
foldMoreCases(x, tree)
}
}
}

def foldMoreCases(x: X, tree: Tree)(implicit ctx: Context): X = {
assert(ctx.reporter.errorsReported || ctx.mode.is(Mode.Interactive), tree)
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/CheckRealizable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class CheckRealizable(implicit ctx: Context) {
if (tp.info.isStable && tpInfoRealizable == Realizable) {
sym.setFlag(StableRealizable)
Realizable
} else r
}
else r
}
}
case _: SingletonType | NoPrefix =>
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/Comments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,8 @@ object Comments {
superComment(sym) foreach { sc =>
val superSections = tagIndex(sc)
replaceWith(sc.substring(3, startTag(sc, superSections)))
for (sec @ (start, end) <- superSections) {
for (sec @ (start, end) <- superSections)
if (!isMovable(sc, sec)) out append sc.substring(start, end)
}
}
case "" => idx += 1
case vname =>
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ object Names {
override def toString: String =
if (length == 0) ""
else {
if (Config.checkBackendNames) {
if (Config.checkBackendNames)
if (!toStringOK) {
// We print the stacktrace instead of doing an assert directly,
// because asserts are caught in exception handlers which might
Expand All @@ -400,7 +400,6 @@ object Names {
Thread.dumpStack()
assert(false)
}
}
new String(chrs, start, length)
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,11 @@ class OrderingConstraint(private val boundsMap: ParamBounds,

def foreachTypeVar(op: TypeVar => Unit): Unit =
boundsMap.foreachBinding { (poly, entries) =>
for (i <- 0 until paramCount(entries)) {
for (i <- 0 until paramCount(entries))
typeVar(entries, i) match {
case tv: TypeVar if !tv.inst.exists => op(tv)
case _ =>
}
}
}

def & (other: Constraint, otherHasErrors: Boolean)(implicit ctx: Context): OrderingConstraint = {
Expand Down
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ trait SymDenotations { this: Context =>
else {
implicit val ctx = this
val initial = denot.initial
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId) {
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId)
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial)
} else try {
else try {
val owner = denot.owner.denot
if (!traceInvalid(owner)) explainSym("owner is invalid")
else if (!owner.isClass || owner.isRefinementClass || denot.isSelfSym) true
else if (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol) true
else explainSym(s"decls of ${show(owner)} are ${owner.unforcedDecls.lookupAll(denot.name).toList}, do not contain ${denot.symbol}")
} catch {
}
catch {
case ex: StaleSymbol => explainSym(s"$ex was thrown")
}
}
}
case _ =>
explain("denotation is not a SymDenotation")
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w

case _ =>
val cls2 = tp2.symbol
if (cls2.isClass) {
if (cls2.isClass)
if (cls2.typeParams.isEmpty) {
if (cls2 eq AnyKindClass) return true
if (tp1.isRef(NothingClass)) return true
Expand All @@ -485,7 +485,6 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
}
else if (tp1.isLambdaSub && !tp1.isRef(AnyKindClass))
return recur(tp1, EtaExpansion(cls2.typeRef))
}
fourthTry
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
case pre: SuperType => toPrefix(pre.thistpe, cls, thiscls)
case _ =>
if (thiscls.derivesFrom(cls) && pre.baseType(thiscls).exists)
if (variance <= 0 && !isLegalPrefix(pre)) {
if (variance <= 0 && !isLegalPrefix(pre))
if (variance < 0) {
approximated = true
defn.NothingType
Expand All @@ -80,7 +80,6 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
// is not possible, then `expandBounds` will end up being
// called which we override to set the `approximated` flag.
range(defn.NothingType, pre)
}
else pre
else if ((pre.termSymbol is Package) && !(thiscls is Package))
toPrefix(pre.select(nme.PACKAGE), cls, thiscls)
Expand Down
15 changes: 6 additions & 9 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,8 @@ object Types {
else tp
rt.opened = true
try go(rt.parent).mapInfo(_.substRecThis(rt, pre))
finally {
finally
if (!rt.openedTwice) rt.opened = false
}
}

def goRefined(tp: RefinedType) = {
Expand Down Expand Up @@ -1359,11 +1358,10 @@ object Types {
case tp @ AppliedType(tycon, args) if tycon.typeSymbol.isClass =>
tycon.parents.map(_.subst(tycon.typeSymbol.typeParams, args))
case tp: TypeRef =>
if (tp.info.isInstanceOf[TempClassInfo]) {
if (tp.info.isInstanceOf[TempClassInfo])
tp.recomputeDenot()
// We usually should have `!tp.info.isInstanceOf[TempClassInfo]` here, but
// this can be falsified for code with illegal cyclic references. See neg/i7107.scala.
}
tp.info.parents
case tp: TypeProxy =>
tp.superType.parents
Expand Down Expand Up @@ -2104,9 +2102,9 @@ object Types {
try {
ctx.pendingUnderlying += this
op
} finally {
ctx.pendingUnderlying -= this
}
finally
ctx.pendingUnderlying -= this
}
finally
ctx.base.underlyingRecursions -= 1
Expand Down Expand Up @@ -4768,7 +4766,7 @@ object Types {
case _ =>
tp.derivedRefinedType(parent, tp.refinedName, info)
}
}
}

override protected def derivedRecType(tp: RecType, parent: Type): Type =
if (parent eq tp.parent) tp
Expand Down Expand Up @@ -4802,7 +4800,7 @@ object Types {
case Range(tyconLo, tyconHi) =>
range(derivedAppliedType(tp, tyconLo, args), derivedAppliedType(tp, tyconHi, args))
case _ =>
if (args.exists(isRange)) {
if (args.exists(isRange))
if (variance > 0) tp.derivedAppliedType(tycon, args.map(rangeToBounds))
else {
val loBuf, hiBuf = new mutable.ListBuffer[Type]
Expand Down Expand Up @@ -4834,7 +4832,6 @@ object Types {
else range(defn.NothingType, defn.AnyType)
// TODO: can we give a better bound than `topType`?
}
}
else tp.derivedAppliedType(tycon, args)
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ object Parsers {
}

def needsBraces(t: Any): Boolean = t match {
case Match(EmptyTree, _) => true
case Block(stats, expr) =>
stats.nonEmpty || needsBraces(expr)
case expr: Tree =>
Expand Down Expand Up @@ -712,8 +713,9 @@ object Parsers {
val (startOpening, endOpening) = startingElimRegion(colonRequired)
val isOutermost = in.currentRegion.isOutermost
def allBraces(r: Region): Boolean = r match {
case r: Indented => r.isOutermost || allBraces(r.enclosing)
case r: InBraces => allBraces(r.enclosing)
case _ => r.isOutermost
case _ => false
}
var canRewrite = allBraces(in.currentRegion) && // test (1)
!testChars(in.lastOffset - 3, " =>") // test(6)
Expand Down Expand Up @@ -1843,7 +1845,7 @@ object Parsers {
def matchExpr(t: Tree, start: Offset, mkMatch: (Tree, List[CaseDef]) => Match) =
indentRegion(MATCH) {
atSpan(start, in.skipToken()) {
inBracesOrIndented(mkMatch(t, caseClauses(caseClause)))
mkMatch(t, inBracesOrIndented(caseClauses(caseClause)))
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
def tparamsText[T >: Untyped](params: List[Tree[T]]): Text =
"[" ~ toText(params, ", ") ~ "]" provided params.nonEmpty

def addVparamssText[T >: Untyped](leading: Text, vparamss: List[List[ValDef[T]]]): Text = {
def addVparamssText[T >: Untyped](leading: Text, vparamss: List[List[ValDef[T]]]): Text =
vparamss.foldLeft(leading)((txt, params) =>
txt ~
(Str(" given ") provided params.nonEmpty && params.head.mods.is(Given)) ~
paramsText(params))
}
protected def valDefToText[T >: Untyped](tree: ValDef[T]): Text = {
import untpd.{modsDeco => _}
dclTextOr(tree) {
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ abstract class TraceSyntax {
if (ctx.mode.is(Mode.Printing)) op
else {
var finalized = false
def finalize(result: Any, note: String) = {
def finalize(result: Any, note: String) =
if (!finalized) {
ctx.base.indent -= 1
log(s"${ctx.base.indentTab * ctx.base.indent}${trailing(result)}$note")
finalized = true
}
}
try {
log(s"${ctx.base.indentTab * ctx.base.indent}$leading")
ctx.base.indent += 1
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/CapturedVars.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
*/
def refClass(cls: Symbol, isVolatile: Boolean)(implicit ctx: Context): Symbol = {
val refMap = if (isVolatile) refInfo.volatileRefClass else refInfo.refClass
if (cls.isClass) {
if (cls.isClass)
refMap.getOrElse(cls, refMap(defn.ObjectClass))
}
else refMap(defn.ObjectClass)
}

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

override def transformIdent(id: Ident)(implicit ctx: Context): Tree = {
Expand Down
9 changes: 3 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class CheckReentrant extends MiniPhase {
finally indent -= 1
}

def addVars(cls: ClassSymbol)(implicit ctx: Context): Unit = {
def addVars(cls: ClassSymbol)(implicit ctx: Context): Unit =
if (!seen.contains(cls) && !isIgnored(cls)) {
seen += cls
scanning(cls) {
for (sym <- cls.classInfo.decls) {
if (sym.isTerm && !sym.isSetter && !isIgnored(sym)) {
for (sym <- cls.classInfo.decls)
if (sym.isTerm && !sym.isSetter && !isIgnored(sym))
if (sym.is(Mutable)) {
ctx.error(
i"""possible data race involving globally reachable ${sym.showLocated}: ${sym.info}
Expand All @@ -71,13 +71,10 @@ class CheckReentrant extends MiniPhase {
scanning(sym) {
sym.info.widenExpr.classSymbols.foreach(addVars)
}
}
}
for (parent <- cls.classInfo.classParents)
addVars(parent.classSymbol.asClass)
}
}
}

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