Skip to content

Drop outdated syntax for given import selectors #8289

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 7 commits into from
Feb 12, 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
2 changes: 1 addition & 1 deletion community-build/community-projects/intent
Submodule intent updated 38 files
+2 −2 README.md
+1 −1 consume/src/test/scala/ATest.scala
+1 −1 docs/getting-started.md
+2 −2 docs/index.md
+8 −8 docs/test-styles.md
+2 −2 macros/src/main/scala/intent/macros/source.scala
+1 −1 src/main/scala/intent/core/descriptiveness.scala
+17 −17 src/main/scala/intent/core/equality.scala
+3 −3 src/main/scala/intent/core/expect.scala
+2 −2 src/main/scala/intent/core/expectations/contain.scala
+3 −3 src/main/scala/intent/core/expectations/equal.scala
+1 −1 src/main/scala/intent/core/expectations/future.scala
+1 −1 src/main/scala/intent/core/expectations/match.scala
+1 −1 src/main/scala/intent/core/expectations/size.scala
+6 −6 src/main/scala/intent/core/expectations/throw.scala
+12 −12 src/main/scala/intent/core/formatters.scala
+13 −13 src/main/scala/intent/core/internal.scala
+1 −1 src/main/scala/intent/core/observable.scala
+2 −2 src/main/scala/intent/core/structure.scala
+2 −2 src/main/scala/intent/runner/TestSuiteRunner.scala
+9 −9 src/main/scala/intent/sbt/Runner.scala
+3 −3 src/main/scala/intent/util/futures.scala
+1 −1 src/test/scala/intent/formatters/FormatTest.scala
+1 −1 src/test/scala/intent/helpers/Meta.scala
+1 −1 src/test/scala/intent/helpers/TestSuiteRunnerTester.scala
+1 −1 src/test/scala/intent/matchers/ExpectTest.scala
+1 −1 src/test/scala/intent/matchers/ToCompleteWithTest.scala
+13 −13 src/test/scala/intent/runner/FocusedTest.scala
+9 −9 src/test/scala/intent/runner/TestSuiteRunnerTest.scala
+1 −1 src/test/scala/intent/sbt/IgnoredTest.scala
+3 −3 src/test/scala/intent/styles/AsyncTest.scala
+2 −2 src/test/scala/intent/styles/StatefulTest.scala
+1 −1 src/test/scala/intent/styles/StatelessTest.scala
+2 −2 src/test/scala/intent/styles/TableDrivenTest.scala
+2 −2 src/test/scala/intent/suite/TestDiscoveryTest.scala
+1 −1 src/test/scala/intent/testdata/NestedTestsSuite.scala
+1 −1 src/test/scala/intent/testdata/SingleLevelTestSuite.scala
+3 −3 src/test/scala/intent/util/DelayedFutureTest.scala
2 changes: 1 addition & 1 deletion community-build/community-projects/scalatest
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
/** Extractor for not-null assertions.
* A not-null assertion for reference `x` has the form `x.$asInstanceOf$[x.type & T]`.
*/
object AssertNotNull with
object AssertNotNull :
def apply(tree: tpd.Tree, tpnn: Type)(using Context): tpd.Tree =
tree.select(defn.Any_typeCast).appliedToType(AndType(tree.tpe, tpnn))

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ast.untpd
import Flags.GivenOrImplicit
import util.{NoSource, SimpleIdentityMap, SourceFile}
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
import Nullables.{NotNullInfo, given}
import Nullables.{NotNullInfo, given _}
import Implicits.ContextualImplicits
import config.Settings._
import config.Config
Expand Down Expand Up @@ -599,7 +599,7 @@ object Contexts {
def setDebug: this.type = setSetting(base.settings.Ydebug, true)
}

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

Expand Down
60 changes: 24 additions & 36 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,13 @@ object Parsers {
else body()
case _ => body()

/** If indentation is not significant, check that this is not the start of a
* statement that's indented relative to the current region.
* TODO: Drop if `with` is required before indented template definitions.
/** Check that this is not the start of a statement that's indented relative to the current region.
*/
def checkNextNotIndented(): Unit = in.currentRegion match
case r: IndentSignificantRegion if in.isNewLine =>
val nextIndentWidth = in.indentWidth(in.next.offset)
if r.indentWidth < nextIndentWidth then
warning(i"Line is indented too far to the right, or a `{` is missing", in.next.offset)
warning(i"Line is indented too far to the right, or a `{` or `:` is missing", in.next.offset)
case _ =>

/* -------- REWRITES ----------------------------------------------------------- */
Expand Down Expand Up @@ -1292,10 +1290,6 @@ object Parsers {
in.nextToken()
if in.token != INDENT then
syntaxError(i"indented definitions expected")
else if in.token == WITH then
in.nextToken()
if in.token != LBRACE && in.token != INDENT then
syntaxError(i"indented definitions or `{` expected")
else
newLineOptWhenFollowedBy(LBRACE)

Expand Down Expand Up @@ -3022,43 +3016,37 @@ object Parsers {
*/
def importExpr(mkTree: ImportConstr): () => Tree = {

/** '_' | 'given'
*/
def wildcardSelectorId() =
val name = if in.token == GIVEN then nme.EMPTY else nme.WILDCARD
atSpan(in.skipToken()) { Ident(name) }
/** '_' */
def wildcardSelectorId(name: TermName) = atSpan(in.skipToken()) { Ident(name) }

/** ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors]
* | WildCardSelector {‘,’ WildCardSelector}
* WildCardSelector ::= ‘given’ (‘_' | InfixType)
* | ‘_'
*/
def importSelectors(idOK: Boolean): List[ImportSelector] =
val selToken = in.token
val isWildcard = selToken == USCORE || selToken == GIVEN
val selector =
if isWildcard then
val id = wildcardSelectorId()
if selToken == USCORE then ImportSelector(id)
else atSpan(startOffset(id)) {
val isWildcard = in.token == USCORE || in.token == GIVEN
val selector = atSpan(in.offset) {
in.token match
case USCORE =>
ImportSelector(wildcardSelectorId(nme.WILDCARD))
case GIVEN =>
val id = wildcardSelectorId(nme.EMPTY)
if in.token == USCORE then
in.nextToken()
ImportSelector(id)
else if in.token != RBRACE && in.token != COMMA then
ImportSelector(id, bound = infixType())
else
ImportSelector(id) // TODO: drop
}
else
val from = termIdent()
if !idOK then syntaxError(i"named imports cannot follow wildcard imports")
if in.token == ARROW then
atSpan(startOffset(from), in.skipToken()) {
val to = if in.token == USCORE then wildcardIdent() else termIdent()
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)
}
else ImportSelector(from)

ImportSelector(id, bound = infixType())
case _ =>
val from = termIdent()
if !idOK then syntaxError(i"named imports cannot follow wildcard imports")
if in.token == ARROW then
atSpan(startOffset(from), in.skipToken()) {
val to = if in.token == USCORE then wildcardIdent() else termIdent()
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)
}
else ImportSelector(from)
}
val rest =
if in.token == COMMA then
in.nextToken()
Expand All @@ -3069,8 +3057,8 @@ object Parsers {

val handleImport: Tree => Tree = tree =>
in.token match
case USCORE | GIVEN =>
mkTree(tree, ImportSelector(wildcardSelectorId()) :: Nil)
case USCORE =>
mkTree(tree, ImportSelector(wildcardSelectorId(nme.WILDCARD)) :: Nil)
case LBRACE =>
mkTree(tree, inBraces(importSelectors(idOK = true)))
case _ =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ object Tokens extends TokensCommon {
AT, CASE)

final val canEndStatTokens: TokenSet = atomicExprTokens | BitSet(
TYPE, GIVEN, RPAREN, RBRACE, RBRACKET, OUTDENT) // TODO: remove GIVEN once old import syntax is dropped
TYPE, RPAREN, RBRACE, RBRACKET, OUTDENT) // TODO: remove GIVEN once old import syntax is dropped

/** Tokens that stop a lookahead scan search for a `<-`, `then`, or `do`.
* Used for disambiguating between old and new syntax.
Expand All @@ -272,7 +272,7 @@ object Tokens extends TokensCommon {
final val closingRegionTokens = BitSet(RBRACE, CASE) | statCtdTokens

final val canStartIndentTokens: BitSet =
statCtdTokens | BitSet(COLONEOL, EQUALS, ARROW, LARROW, WHILE, TRY, FOR, IF, WITH)
statCtdTokens | BitSet(COLONEOL, EQUALS, ARROW, LARROW, WHILE, TRY, FOR, IF)
// `if` is excluded because it often comes after `else` which makes for awkward indentation rules TODO: try to do without the exception

/** Faced with the choice between a type and a formal parameter, the following
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import scala.annotation.{ threadUnsafe => tu, tailrec }
* for a description of the format.
* TODO: Also extract type information
*/
class ExtractSemanticDB extends Phase with
class ExtractSemanticDB extends Phase:
import Scala3.{_, given _}
import Symbols.{given _}

Expand All @@ -46,7 +46,7 @@ class ExtractSemanticDB extends Phase with
ExtractSemanticDB.write(unit.source, extract.occurrences.toList, extract.symbolInfos.toList)

/** Extractor of symbol occurrences from trees */
class Extractor extends TreeTraverser with
class Extractor extends TreeTraverser:

private var nextLocalIdx: Int = 0

Expand All @@ -57,7 +57,7 @@ class ExtractSemanticDB extends Phase with
private val localBodies = mutable.HashMap[Symbol, Tree]()

/** The local symbol(s) starting at given offset */
private val symsAtOffset = new mutable.HashMap[Int, Set[Symbol]]() with
private val symsAtOffset = new mutable.HashMap[Int, Set[Symbol]]():
override def default(key: Int) = Set[Symbol]()

/** The extracted symbol occurrences */
Expand Down Expand Up @@ -242,7 +242,7 @@ class ExtractSemanticDB extends Phase with
name => locals.keys.find(local => local.isTerm && local.owner == funSym && local.name == name)
.fold("<?>")(Symbols.LocalPrefix + _)

private object PatternValDef with
private object PatternValDef:

def unapply(tree: ValDef)(using Context): Option[(Tree, Tree)] = tree.rhs match

Expand Down Expand Up @@ -570,7 +570,7 @@ class ExtractSemanticDB extends Phase with
registerSymbol(vparam.symbol, symbolName(vparam.symbol), symkinds)
traverseTpt(vparam.tpt)

object ExtractSemanticDB with
object ExtractSemanticDB:
import java.nio.file.Path
import scala.collection.JavaConverters._
import java.nio.file.Files
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import java.lang.Character.{isJavaIdentifierPart, isJavaIdentifierStart}
import scala.annotation.internal.sharable
import scala.annotation.switch

object Scala3 with
object Scala3:
import Symbols._
import core.NameOps.given
import core.NameOps.{given _}

@sharable private val unicodeEscape = raw"\$$u(\p{XDigit}{4})".r
@sharable private val locals = raw"local(\d+)".r
@sharable private val ctor = raw"[^;].*`<init>`\((?:\+\d+)?\)\.".r

private val WILDCARDTypeName = nme.WILDCARD.toTypeName

enum SymbolKind derives Eql with
enum SymbolKind derives Eql:
kind =>

case Val, Var, Setter, Abstract
Expand All @@ -38,13 +38,13 @@ object Scala3 with

end SymbolKind

object SymbolKind with
object SymbolKind:
val ValSet = Set(Val)
val VarSet = Set(Var)
val emptySet = Set.empty[SymbolKind]
end SymbolKind

object Symbols with
object Symbols:

val RootPackage: String = "_root_/"
val EmptyPackage: String = "_empty_/"
Expand All @@ -67,7 +67,7 @@ object Scala3 with

end Symbols

extension NameOps on (name: Name) with
extension NameOps on (name: Name):

def isWildcard = name match
case nme.WILDCARD | WILDCARDTypeName => true
Expand All @@ -89,7 +89,7 @@ object Scala3 with

// end NameOps

extension SymbolOps on (sym: Symbol) with
extension SymbolOps on (sym: Symbol):

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

Expand Down Expand Up @@ -128,7 +128,7 @@ object Scala3 with

// end SymbolOps

object LocalSymbol with
object LocalSymbol:

def unapply(symbolInfo: SymbolInformation): Option[Int] = symbolInfo.symbol match
case locals(ints) =>
Expand All @@ -146,7 +146,7 @@ object Scala3 with
case '/' | '.' | '#' | ']' | ')' => true
case _ => false

extension StringOps on (symbol: String) with
extension StringOps on (symbol: String):

def isSymbol: Boolean = !symbol.isEmpty
def isRootPackage: Boolean = RootPackage == symbol
Expand All @@ -171,7 +171,7 @@ object Scala3 with

// end StringOps

extension InfoOps on (info: SymbolInformation) with
extension InfoOps on (info: SymbolInformation):

def isAbstract: Boolean = (info.properties & SymbolInformation.Property.ABSTRACT.value) != 0
def isFinal: Boolean = (info.properties & SymbolInformation.Property.FINAL.value) != 0
Expand Down Expand Up @@ -207,7 +207,7 @@ object Scala3 with

// end InfoOps

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

Expand Down Expand Up @@ -236,7 +236,7 @@ object Scala3 with
*
* taken from https://github.com/scalameta/scalameta/blob/master/semanticdb/metap/src/main/scala/scala/meta/internal/metap/IdentifierOrdering.scala
*/
private class IdentifierOrdering[T <: CharSequence] extends Ordering[T] with
private class IdentifierOrdering[T <: CharSequence] extends Ordering[T]:

override def compare(o1: T, o2: T): Int =
val len = math.min(o1.length(), o2.length())
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/semanticdb/Tools.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import java.nio.file._
import java.nio.charset.StandardCharsets
import scala.collection.JavaConverters._
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.semanticdb.Scala3.{_, given}
import dotty.tools.dotc.semanticdb.Scala3.{_, given _}

object Tools with
object Tools:

/** Load SemanticDB TextDocument for a single Scala source file
*
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/LiftTry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase =>
}
else tree
}
object LiftTry with
object LiftTry:
val name = "liftTry"
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import NameKinds.DefaultGetterName
import ProtoTypes._
import Inferencing._
import transform.TypeUtils._
import Nullables.{postProcessByNameArgs, given}
import Nullables.{postProcessByNameArgs, given _}

import collection.mutable
import config.Printers.{overload, typr, unapp}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ trait Implicits { self: Typer =>
if diff == 0 then
// Fall back: if both results are extension method applications,
// compare the extension methods instead of their wrappers.
object extMethodApply with
object extMethodApply:
def unapply(t: Tree): Option[Type] = t match
case t: Applications.ExtMethodApply => Some(methPart(stripApply(t.app)).tpe)
case _ => None
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import collection.mutable
/** This trait defines the method `importSuggestionAddendum` that adds an addendum
* to error messages suggesting additional imports.
*/
trait ImportSuggestions with
trait ImportSuggestions:
this: Typer =>

import tpd._
Expand Down Expand Up @@ -167,7 +167,7 @@ trait ImportSuggestions with
def deepTest(ref: TermRef): Boolean =
System.currentTimeMillis < deadLine
&& {
val task = new TimerTask with
val task = new TimerTask:
def run() =
println(i"Cancelling test of $ref when making suggestions for error in ${ctx.source}")
ctx.run.isCancelled = true
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 @@ -24,7 +24,7 @@ import ErrorReporting.errorTree
import dotty.tools.dotc.tastyreflect.ReflectionImpl
import dotty.tools.dotc.util.{SimpleIdentityMap, SimpleIdentitySet, SourceFile, SourcePosition}
import dotty.tools.dotc.parsing.Parsers.Parser
import Nullables.given
import Nullables.{given _}

import collection.mutable
import reporting.trace
Expand Down
Loading