Skip to content

Fix #10648: Fixes of syntax documentation #10658

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 11 commits into from
Dec 9, 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 @@ -5,5 +5,5 @@ import scala.quoted.Type
class FieldsDsl[V](v: V):
inline def of[T]: Seq[T] = FieldsImpl.fieldsOfType[V, T](v)

extension [V](on: V):
extension [V](on: V)
def reflectedFields = FieldsDsl(on)
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
* object T { def f { object U } }
* the owner of U is T, so UModuleClass.isStatic is true. Phase travel does not help here.
*/
extension (sym: Symbol):
extension (sym: Symbol)
private def isOriginallyStaticOwner: Boolean =
sym.is(PackageClass) || sym.is(ModuleClass) && sym.originalOwner.originalLexicallyEnclosingClass.isOriginallyStaticOwner

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object DottyBackendInterface {
}

given symExtensions: AnyRef with
extension (sym: Symbol):
extension (sym: Symbol)

def isInterface(using Context): Boolean = (sym.is(PureInterface)) || sym.is(Trait)

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
!(sym.is(Method) && sym.info.isInstanceOf[MethodOrPoly]) // if is a method it is parameterless
}

extension (xs: List[tpd.Tree]):
extension (xs: List[tpd.Tree])
def tpes: List[Type] = xs match {
case x :: xs1 => x.tpe :: xs1.tpes
case nil => Nil
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/ContextOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ast.untpd
/** Extension methods for contexts where we want to keep the ctx.<methodName> syntax */
object ContextOps:

extension (ctx: Context):
extension (ctx: Context)

/** Enter symbol into current class, if current class is owner of current context,
* or into current scope, if not. Should always be called instead of scope.enter
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ object Contexts {
}

given ops: AnyRef with
extension (c: Context):
extension (c: Context)
def addNotNullInfo(info: NotNullInfo) =
c.withNotNullInfos(c.notNullInfos.extendWith(info))

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Decorators {
case s: String => typeName(s)
case n: Name => n.toTypeName

extension (s: String):
extension (s: String)
def splitWhere(f: Char => Boolean, doDropIndex: Boolean): Option[(String, String)] =
def splitAt(idx: Int, doDropIndex: Boolean): Option[(String, String)] =
if (idx == -1) None
Expand Down Expand Up @@ -61,7 +61,7 @@ object Decorators {
/** Implements a findSymbol method on iterators of Symbols that
* works like find but avoids Option, replacing None with NoSymbol.
*/
extension (it: Iterator[Symbol]):
extension (it: Iterator[Symbol])
final def findSymbol(p: Symbol => Boolean): Symbol = {
while (it.hasNext) {
val sym = it.next()
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ object TypeComparer {
*/
val Fresh: Repr = 4

extension (approx: Repr):
extension (approx: Repr)
def low: Boolean = (approx & LoApprox) != 0
def high: Boolean = (approx & HiApprox) != 0
def addLow: Repr = approx | LoApprox
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ object Completion {
}
}

// There are four possible ways for an extension method to be applicable:
// There are four possible ways for an extension method to be applicable

// 1. The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference.
val extMethodsInScope =
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object Parsers {
val Spliced = 2
}

extension (buf: ListBuffer[Tree]):
extension (buf: ListBuffer[Tree])
def +++=(x: Tree) = x match {
case x: Thicket => buf ++= x.trees
case x => buf += x
Expand Down Expand Up @@ -3565,8 +3565,9 @@ object Parsers {
val tparams = typeParamClauseOpt(ParamOwner.Def)
val extParams = paramClause(0, prefix = true)
val givenParamss = paramClauses(givenOnly = true)
in.observeColonEOL()
if (in.token == COLONEOL) in.nextToken()
if in.token == COLON then
syntaxError("no `:` expected here")
in.nextToken()
val methods =
if isDefIntro(modifierTokens) then
extMethod() :: Nil
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/Texts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ object Texts {
/** The given texts `xs`, each on a separate line */
def lines(xs: Traversable[Text]): Vertical = Vertical(xs.toList.reverse)

extension (text: => Text):
extension (text: => Text)
def provided(cond: Boolean): Text = if (cond) text else Str("")

}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package object printing {
val XprintMode: Key[Unit] = new Key

/** @pre `nel` is non-empty list */
extension [A](nel: List[A]):
extension [A](nel: List[A])
private[printing] def intersperse(a: A): List[A] =
nel.flatMap(a :: _ :: Nil).tail

Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class ExtractSemanticDB extends Phase:

case _ => None

extension (tpe: Types.Type):
extension (tpe: Types.Type)
private inline def isAnnotatedByUnchecked(using Context) = tpe match
case Types.AnnotatedType(_, annot) => annot.symbol == defn.UncheckedAnnot
case _ => false
Expand Down Expand Up @@ -490,12 +490,12 @@ class ExtractSemanticDB extends Phase:
val start = if idx >= 0 then idx else span.start
Span(start, start + sym.name.show.length, start)

extension (list: List[List[ValDef]]):
extension (list: List[List[ValDef]])
private inline def isSingleArg = list match
case (_::Nil)::Nil => true
case _ => false

extension (tree: DefDef):
extension (tree: DefDef)
private def isSetterDef(using Context): Boolean =
tree.name.isSetterName && tree.mods.is(Accessor) && tree.vparamss.isSingleArg

Expand All @@ -521,21 +521,21 @@ class ExtractSemanticDB extends Phase:
else limit
Span(start max limit, end)

extension (span: Span):
extension (span: Span)
private def hasLength: Boolean = span.exists && !span.isZeroExtent

/**Consume head while not an import statement.
* Returns the rest of the list after the first import, or else the empty list
*/
extension (body: List[Tree]):
extension (body: List[Tree])
@tailrec private def foreachUntilImport(op: Tree => Unit): List[Tree] = body match
case ((_: Import) :: rest) => rest
case stat :: rest =>
op(stat)
rest.foreachUntilImport(op)
case Nil => Nil

extension (sym: Symbol):
extension (sym: Symbol)
private def adjustIfCtorTyparam(using Context) =
if sym.isType && sym.owner.exists && sym.owner.isConstructor then
matchingMemberType(sym, sym.owner.owner)
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object Scala3:


given NameOps: AnyRef with
extension (name: Name):
extension (name: Name)
def isWildcard = name match
case nme.WILDCARD | WILDCARDTypeName => true
case _ => name.is(NameKinds.WildcardParamName)
Expand All @@ -90,7 +90,7 @@ object Scala3:
end NameOps

given SymbolOps: AnyRef with
extension (sym: Symbol):
extension (sym: Symbol)

def ifExists(using Context): Option[Symbol] = if sym.exists then Some(sym) else None

Expand Down Expand Up @@ -140,13 +140,13 @@ object Scala3:

end LocalSymbol

extension (char: Char):
extension (char: Char)
private inline def isGlobalTerminal = (char: @switch) match
case '/' | '.' | '#' | ']' | ')' => true
case _ => false

given StringOps: AnyRef with
extension (symbol: String):
extension (symbol: String)
def isSymbol: Boolean = !symbol.isEmpty
def isRootPackage: Boolean = RootPackage == symbol
def isEmptyPackage: Boolean = EmptyPackage == symbol
Expand All @@ -170,7 +170,7 @@ object Scala3:
end StringOps

given InfoOps: AnyRef with
extension (info: SymbolInformation):
extension (info: SymbolInformation)
def isAbstract: Boolean = (info.properties & SymbolInformation.Property.ABSTRACT.value) != 0
def isFinal: Boolean = (info.properties & SymbolInformation.Property.FINAL.value) != 0
def isSealed: Boolean = (info.properties & SymbolInformation.Property.SEALED.value) != 0
Expand Down Expand Up @@ -205,7 +205,7 @@ object Scala3:
end InfoOps

given RangeOps: AnyRef with
extension (range: Range):
extension (range: Range)
def hasLength = range.endLine > range.startLine || range.endCharacter > range.startCharacter
end RangeOps

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/semanticdb/Tools.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ object Tools:
sb.append(if occ.role.isReference then " -> " else " <- ").append(occ.symbol).nl
end processOccurrence

extension (sb: StringBuilder):
extension (sb: StringBuilder)
private inline def nl = sb.append(System.lineSeparator)
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ImportInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object ImportInfo {

ImportInfo(sym, selectors, None, isRootImport = true)

extension (c: Context):
extension (c: Context)
def withRootImports(rootRefs: List[RootRef])(using Context): Context =
rootRefs.foldLeft(c)((ctx, ref) => ctx.fresh.setImportInfo(rootImport(ref)))

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Nullables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ object Nullables:
}.traverse(tree)
end extension

extension (tree: Assign):
extension (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 compiler/src/dotty/tools/dotc/util/LinearMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object LinearMap:
def empty[K <: AnyRef, V >: Null <: AnyRef]: LinearMap[K, V] =
immutable.Map.empty[K, V]

extension [K <: AnyRef, V >: Null <: AnyRef](m: LinearMap[K, V]):
extension [K <: AnyRef, V >: Null <: AnyRef](m: LinearMap[K, V])

def lookup(key: K): V /*| Null*/ = (m: @unchecked) match
case m: immutable.AbstractMap[K, V] @unchecked =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/util/LinearSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object LinearSet:

def empty[Elem >: Null <: AnyRef]: LinearSet[Elem] = immutable.Set.empty[Elem]

extension [Elem >: Null <: AnyRef](s: LinearSet[Elem]):
extension [Elem >: Null <: AnyRef](s: LinearSet[Elem])

def contains(elem: Elem): Boolean = (s: @unchecked) match
case s: immutable.AbstractSet[Elem] @unchecked => s.contains(elem)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package object tools {
throw new UnsupportedOperationException(methodName)

/** Forward-ported from the explicit-nulls branch. */
extension [T](x: T | Null):
extension [T](x: T | Null)

/** Assert `x` is non null and strip `Null` from type */
inline def nn: T =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {

object Rendering {

extension (s: Symbol):
extension (s: Symbol)
def showUser(using Context): String = {
val printer = new ReplPrinter(ctx)
val text = printer.dclText(s)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/repl/results.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ object results {
/** Result is a type alias for an Either with left value `Errors` */
type Result[+A] = scala.util.Either[Errors, A]

extension [A](a: A):
extension [A](a: A)
def result: Result[A] = scala.util.Right(a)

extension [A](xs: Errors):
extension [A](xs: Errors)
def errors: Result[A] = scala.util.Left(xs)

}
6 changes: 3 additions & 3 deletions compiler/src/scala/quoted/runtime/impl/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ object Matcher {
case _ => notMatched
}

extension (scrutinees: List[Tree]):
extension (scrutinees: List[Tree])
/** Check that all trees match with =?= and concatenate the results with &&& */
private def =?= (patterns: List[Tree])(using Env): Matching =
matchLists(scrutinees, patterns)(_ =?= _)

extension (scrutinee0: Tree):
extension (scrutinee0: Tree)
/** Check that the trees match and return the contents from the pattern holes.
* Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes.
*
Expand Down Expand Up @@ -408,7 +408,7 @@ object Matcher {
val matched: Matching = Some(Tuple())
def matched(x: Any): Matching = Some(Tuple1(x))

extension (self: Matching):
extension (self: Matching)
def asOptionOfTuple: Option[Tuple] = self

/** Concatenates the contents of two successful matchings or return a `notMatched` */
Expand Down
Loading