Skip to content

Don't require colon after class or object signatures #7185

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 9 commits into from
Sep 12, 2019
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package jvm
* the compiler cake (Global).
*/
final class BCodeAsmCommon[I <: BackendInterface](val interface: I) {
import interface._
import interface._

/**
* True if `classSym` is an anonymous class or a local class. I.e., false if `classSym` is a
Expand Down
821 changes: 410 additions & 411 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Large diffs are not rendered by default.

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
33 changes: 21 additions & 12 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 @@ -1176,6 +1178,11 @@ object Parsers {
newLineOptWhenFollowedBy(LBRACE)
}

def possibleTemplateStart(): Unit = {
in.observeIndented()
newLineOptWhenFollowedBy(LBRACE)
}

def indentRegion[T](tag: EndMarkerTag)(op: => T): T = {
val iw = in.currentRegion.indentWidth
val t = op
Expand Down Expand Up @@ -1843,7 +1850,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 Expand Up @@ -3328,7 +3335,7 @@ object Parsers {
if (in.token == LPAREN)
try paramClause(prefix = true) :: Nil
finally {
possibleBracesStart()
possibleTemplateStart()
if (!in.isNestedStart) syntaxErrorOrIncomplete("`{' expected")
}
else Nil
Expand All @@ -3346,7 +3353,7 @@ object Parsers {
DefDef(name, tparams, vparamss, parents.head, expr())
}
else {
possibleBracesStart()
possibleTemplateStart()
val (tparams1, vparamss1) =
if (leadingParamss.nonEmpty)
(tparams, leadingParamss)
Expand Down Expand Up @@ -3446,7 +3453,7 @@ object Parsers {
*/
def template(constr: DefDef, isEnum: Boolean = false): Template = {
val (parents, derived) = inheritClauses()
possibleBracesStart()
possibleTemplateStart()
if (isEnum) {
val (self, stats) = withinEnum(templateBody())
Template(constr, parents, derived, self, stats)
Expand All @@ -3456,13 +3463,15 @@ object Parsers {

/** TemplateOpt = [Template]
*/
def templateOpt(constr: DefDef): Template = {
def templateOpt(constr: DefDef): Template =
possibleBracesStart()
if (in.token == EXTENDS || isIdent(nme.derives) || in.isNestedStart)
if (in.token == EXTENDS || isIdent(nme.derives))
template(constr)
else
Template(constr, Nil, Nil, EmptyValDef, Nil)
}
else {
possibleTemplateStart()
if (in.isNestedStart) template(constr)
else Template(constr, Nil, Nil, EmptyValDef, Nil)
}

/** TemplateBody ::= [nl] `{' TemplateStatSeq `}'
*/
Expand Down Expand Up @@ -3494,7 +3503,7 @@ object Parsers {
def packaging(start: Int): Tree = {
val pkg = qualId()
indentRegion(pkg) {
possibleBracesStart()
possibleTemplateStart()
val stats = inDefScopeBraces(topStatSeq())
makePackaging(start, pkg, stats)
}
Expand Down Expand Up @@ -3700,7 +3709,7 @@ object Parsers {
else {
val pkg = qualId()
indentRegion(pkg) {
possibleBracesStart()
possibleTemplateStart()
if (in.token == EOF)
ts += makePackaging(start, pkg, List())
else if (in.isNestedStart) {
Expand Down
Loading