Skip to content

Fix #8256: Disallow silent indent for template bodies #8264

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 6 commits into from
Feb 10, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def exec(projectDir: Path, binary: String, arguments: String*): Int =
exitCode


sealed trait CommunityProject
sealed trait CommunityProject:
private var published = false

val project: String
Expand Down Expand Up @@ -77,17 +77,23 @@ sealed trait CommunityProject
published = true
end CommunityProject

final case class MillCommunityProject(project: String, baseCommand: String,
dependencies: List[CommunityProject] = Nil) extends CommunityProject
final case class MillCommunityProject(
project: String,
baseCommand: String,
dependencies: List[CommunityProject] = Nil) extends CommunityProject:
override val binaryName: String = "./mill"
override val updateCommand = s"$baseCommand.compileClasspath"
override val testCommand = s"$baseCommand.test"
override val publishCommand = s"$baseCommand.publishLocal"
override val runCommandsArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")

final case class SbtCommunityProject(project: String, sbtTestCommand: String,
sbtUpdateCommand: String, extraSbtArgs: List[String] = Nil,
dependencies: List[CommunityProject] = Nil, sbtPublishCommand: String = null) extends CommunityProject
final case class SbtCommunityProject(
project: String,
sbtTestCommand: String,
sbtUpdateCommand: String,
extraSbtArgs: List[String] = Nil,
dependencies: List[CommunityProject] = Nil,
sbtPublishCommand: String = null) extends CommunityProject:
override val binaryName: String = "sbt"
private val baseCommand = s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! "
override val testCommand = s"$baseCommand$sbtTestCommand"
Expand All @@ -103,7 +109,7 @@ final case class SbtCommunityProject(project: String, sbtTestCommand: String,
"-sbt-version", "1.3.6",
s"--addPluginSbtFile=$sbtPluginFilePath")

object projects
object projects:
lazy val utest = MillCommunityProject(
project = "utest",
baseCommand = s"utest.jvm[$compilerVersion]",
Expand Down Expand Up @@ -265,7 +271,7 @@ object projects
end projects

@Category(Array(classOf[TestCategory]))
class CommunityBuildTest {
class CommunityBuildTest:
given CommunityBuildTest = this

/** Build the given project with the published local compiler and sbt plugin.
Expand Down Expand Up @@ -335,7 +341,7 @@ class CommunityBuildTest {
@Test def xmlInterpolator = projects.xmlInterpolator.run()
@Test def effpi = projects.effpi.run()
@Test def sconfig = projects.sconfig.run()
}
end CommunityBuildTest

class TestCategory
class UpdateCategory
Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ object Config {
/** Assume -indent by default */
final val defaultIndent = true

/** Assume indentation is significant after a class, object, ... signature */
final val silentTemplateIndent = true

/** If set, prints a trace of all symbol completions */
final val showCompletions = false

Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Decorators._
import scala.internal.Chars
import scala.annotation.{tailrec, switch}
import rewrites.Rewrites.{patch, overlapsPatch}
import config.Config.silentTemplateIndent

object Parsers {

Expand Down Expand Up @@ -1319,7 +1318,6 @@ object Parsers {
if in.token != LBRACE && in.token != INDENT then
syntaxError(i"indented definitions or `{` expected")
else
if silentTemplateIndent && !isNew then in.observeIndented()
newLineOptWhenFollowedBy(LBRACE)

def endMarkerScope[T](pid: Tree)(op: => T): T = pid match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ object Inliner {

object Intrinsics {
import dotty.tools.dotc.reporting.diagnostic.messages.Error
private enum ErrorKind
private enum ErrorKind:
case Parser, Typer

private def compileForErrors(tree: Tree, stopAfterParser: Boolean)(using ctx: Context): List[(ErrorKind, Error)] =
Expand Down
22 changes: 11 additions & 11 deletions compiler/src/dotty/tools/dotc/typer/Nullables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import config.Printers.nullables
import ast.{tpd, untpd}

/** Operations for implementing a flow analysis for nullability */
object Nullables with
object Nullables:
import ast.tpd._

/** A set of val or var references that are known to be not null, plus a set of
* variable references that are not known (anymore) to be not null
*/
case class NotNullInfo(asserted: Set[TermRef], retracted: Set[TermRef])
case class NotNullInfo(asserted: Set[TermRef], retracted: Set[TermRef]):
assert((asserted & retracted).isEmpty)

def isEmpty = this eq NotNullInfo.empty
Expand All @@ -43,18 +43,18 @@ object Nullables with
def alt(that: NotNullInfo): NotNullInfo =
NotNullInfo(this.asserted.intersect(that.asserted), this.retracted.union(that.retracted))

object NotNullInfo with
object NotNullInfo:
val empty = new NotNullInfo(Set(), Set())
def apply(asserted: Set[TermRef], retracted: Set[TermRef]): NotNullInfo =
if asserted.isEmpty && retracted.isEmpty then empty
else new NotNullInfo(asserted, retracted)
end NotNullInfo

/** A pair of not-null sets, depending on whether a condition is `true` or `false` */
case class NotNullConditional(ifTrue: Set[TermRef], ifFalse: Set[TermRef]) with
case class NotNullConditional(ifTrue: Set[TermRef], ifFalse: Set[TermRef]):
def isEmpty = this eq NotNullConditional.empty

object NotNullConditional with
object NotNullConditional:
val empty = new NotNullConditional(Set(), Set())
def apply(ifTrue: Set[TermRef], ifFalse: Set[TermRef]): NotNullConditional =
if ifTrue.isEmpty && ifFalse.isEmpty then empty
Expand All @@ -72,7 +72,7 @@ object Nullables with
private[typer] val NNInfo = Property.StickyKey[NotNullInfo]

/** An extractor for null comparisons */
object CompareNull with
object CompareNull:

/** Matches one of
*
Expand All @@ -97,7 +97,7 @@ object Nullables with
end CompareNull

/** An extractor for null-trackable references */
object TrackedRef
object TrackedRef:
def unapply(tree: Tree)(using Context): Option[TermRef] = tree.typeOpt match
case ref: TermRef if isTracked(ref) => Some(ref)
case _ => None
Expand Down Expand Up @@ -160,7 +160,7 @@ object Nullables with
// TODO: Add constant pattern if the constant type is not nullable
case _ => false

extension notNullInfoOps on (infos: List[NotNullInfo]) with
extension notNullInfoOps on (infos: List[NotNullInfo]):

/** Do the current not-null infos imply that `ref` is not null?
* Not-null infos are as a history where earlier assertions and retractions replace
Expand Down Expand Up @@ -191,7 +191,7 @@ object Nullables with
infos.extendWith(NotNullInfo(Set(), mutables))
// end notNullInfoOps

extension refOps on (ref: TermRef) with
extension refOps on (ref: TermRef):

/** Is the use of a mutable variable out of order
*
Expand Down Expand Up @@ -245,7 +245,7 @@ object Nullables with
&& refOwner.isTerm
&& recur(curCtx.owner)

extension treeOps on (tree: Tree) with
extension treeOps on (tree: Tree):

/* The `tree` with added nullability attachment */
def withNotNullInfo(info: NotNullInfo): tree.type =
Expand Down Expand Up @@ -335,7 +335,7 @@ object Nullables with
tree.computeNullable()
}.traverse(tree)

extension assignOps on (tree: Assign) with
extension assignOps on (tree: Assign):
def computeAssignNullable()(using Context): tree.type = tree.lhs match
case TrackedRef(ref) =>
val rhstp = tree.rhs.typeOpt
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/IArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import reflect.ClassTag
/** An immutable array. An `IArray[T]` has the same representation as an `Array[T]`,
* but it cannot be updated. Unlike regular arrays, immutable arrays are covariant.
*/
object opaques
object opaques:
opaque type IArray[+T] = Array[_ <: T]

/** Defines extension methods for immutable arrays */
Expand Down
8 changes: 3 additions & 5 deletions library/src/scala/TupledFunction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import scala.annotation.implicitNotFound
* @tparam G a tupled function type (function of arity 1 receiving a tuple as argument)
*/
@implicitNotFound("${F} cannot be tupled as ${G}")
sealed trait TupledFunction[F, G] {
sealed trait TupledFunction[F, G]:
def tupled(f: F): G
def untupled(g: G): F
}

private[scala] object TupledFunction
private[scala] object TupledFunction:
def apply[F, G](tupledImpl: F => G, untupledImpl: G => F): TupledFunction[F, G] =
new TupledFunction[F, G] {
new TupledFunction[F, G]:
def tupled(f: F): G = tupledImpl(f)
def untupled(g: G): F = untupledImpl(g)
}
2 changes: 1 addition & 1 deletion library/src/scala/compiletime/testing/ErrorKind.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package scala.compiletime.testing

/** An error can be either a parse-time or a typecheck-time */
sealed trait ErrorKind // TODO make this enum, so far not doable because ScalaJS compilation fails on it
object ErrorKind
object ErrorKind:
case object Parser extends ErrorKind
case object Typer extends ErrorKind
14 changes: 6 additions & 8 deletions library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1560,30 +1560,28 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>

given (using ctx: Context) as IsInstanceOf[SimpleSelector] = internal.isInstanceOfSimpleSelector

object SimpleSelector
object SimpleSelector:
def unapply(x: SimpleSelector)(using ctx: Context): Option[Id] = Some(x.selection)

extension renameSelectorOps on (self: RenameSelector) {
extension renameSelectorOps on (self: RenameSelector):
def from(using ctx: Context): Id =
internal.RenameSelector_from(self)

def to(using ctx: Context): Id =
internal.RenameSelector_to(self)
}

given (using ctx: Context) as IsInstanceOf[RenameSelector] = internal.isInstanceOfRenameSelector

object RenameSelector
object RenameSelector:
def unapply(x: RenameSelector)(using ctx: Context): Option[(Id, Id)] = Some((x.from, x.to))

extension omitSelectorOps on (self: OmitSelector) {
extension omitSelectorOps on (self: OmitSelector):
def omitted(using ctx: Context): Id =
internal.SimpleSelector_omitted(self)
}

given (using ctx: Context) as IsInstanceOf[OmitSelector] = internal.isInstanceOfOmitSelector

object OmitSelector
object OmitSelector:
def unapply(x: OmitSelector)(using ctx: Context): Option[Id] = Some(x.omitted)


Expand Down Expand Up @@ -1980,7 +1978,7 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>

given (using ctx: Context) as IsInstanceOf[NoPrefix] = internal.isInstanceOfNoPrefix

object NoPrefix
object NoPrefix:
def unapply(x: NoPrefix)(using ctx: Context): Boolean = true


Expand Down
12 changes: 6 additions & 6 deletions tests/neg/endmarkers.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
object Test
object Test:

locally {
var x = 0
Expand Down Expand Up @@ -43,11 +43,11 @@ object Test
x < 10
do ()

class Test2
class Test2:
self =>
def foo = 1

object x
object x:
new Test2 {
override def foo = 2
end new // error: misaligned end marker
Expand All @@ -56,16 +56,16 @@ class Test2
end Test2 // error: misaligned end marker
end Test2

class Test3
class Test3:
self =>
def foo = 1
end Test3 // error: misaligned end marker

import collection.mutable.HashMap

class Coder(words: List[String])
class Coder(words: List[String]):

class Foo
class Foo:
println()
end Foo // error: misaligned end marker

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/given-eta.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

trait D
trait D:
type T
def trans(other: T): T

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i7359-b.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait SAMTrait
trait SAMTrait:
def first(): String
def notifyAll(): Unit // error
2 changes: 1 addition & 1 deletion tests/neg/i7359-c.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait SAMTrait
trait SAMTrait:
def first(): String
def wait(): Unit // error
2 changes: 1 addition & 1 deletion tests/neg/i7359-d.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait SAMTrait
trait SAMTrait:
def first(): String
def wait(a: Long): Unit // error
2 changes: 1 addition & 1 deletion tests/neg/i7359-e.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait SAMTrait
trait SAMTrait:
def first(): String
def wait(a: Long, n: Int): Unit // error
2 changes: 1 addition & 1 deletion tests/neg/i7359-f.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- [E120] Duplicate Symbol Error: tests/neg/i7359-f.scala:1:6 ----------------------------------------------------------
1 |trait SAMTrait // error
1 |trait SAMTrait: // error
| ^
| Name clash between inherited members:
| def equals: [T >: Boolean <: Boolean](obj: Any): T in trait SAMTrait at line 3 and
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i7359-f.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait SAMTrait // error
trait SAMTrait: // error
def first(): String
def equals[T >: Boolean <: Boolean](obj: Any): T
2 changes: 1 addition & 1 deletion tests/neg/i7359-g.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
trait SAMTrait
trait SAMTrait:
def first(): String
def equals(obj: Int): Boolean

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i7359.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait SAMTrait
trait SAMTrait:
def first(): String
def notify(): Unit // error
4 changes: 2 additions & 2 deletions tests/neg/i7980.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
trait Evidence[X]

trait Trait[X : Evidence]
trait Trait[X : Evidence]:
def method(x : X) : X

given ev : Evidence[Int] = new Evidence[Int]{}
given ev as Evidence[Int] = new Evidence[Int]{}
val crash : Trait[Int] = (x: Int) => x // error
4 changes: 2 additions & 2 deletions tests/neg/i8069.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
trait A
trait A:
type B

enum Test
enum Test:
case Test(a: A, b: a.B) // error: Implementation restriction: case classes cannot have dependencies between parameters

case class Test2(a: A, b: a.B) // error: Implementation restriction: case classes cannot have dependencies between parameters
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/override-inner-class.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class C
class C:
type T >: String <: Any

class D extends C
class D extends C:
class T // error
2 changes: 1 addition & 1 deletion tests/neg/parser-stability-12.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
trait x0[] // error
trait x0[]: // error
trait x1[x1 <:x0]
extends x1[ // error
// error
Loading