Skip to content

Commit d67b5cf

Browse files
authored
Merge pull request #8289 from dotty-staging/change-given-import
Drop outdated syntax for given import selectors
2 parents 5b006fb + da645f3 commit d67b5cf

File tree

72 files changed

+174
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+174
-187
lines changed
Submodule intent updated 38 files

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
868868
/** Extractor for not-null assertions.
869869
* A not-null assertion for reference `x` has the form `x.$asInstanceOf$[x.type & T]`.
870870
*/
871-
object AssertNotNull with
871+
object AssertNotNull :
872872
def apply(tree: tpd.Tree, tpnn: Type)(using Context): tpd.Tree =
873873
tree.select(defn.Any_typeCast).appliedToType(AndType(tree.tpe, tpnn))
874874

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ast.untpd
1616
import Flags.GivenOrImplicit
1717
import util.{NoSource, SimpleIdentityMap, SourceFile}
1818
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
19-
import Nullables.{NotNullInfo, given}
19+
import Nullables.{NotNullInfo, given _}
2020
import Implicits.ContextualImplicits
2121
import config.Settings._
2222
import config.Config
@@ -599,7 +599,7 @@ object Contexts {
599599
def setDebug: this.type = setSetting(base.settings.Ydebug, true)
600600
}
601601

602-
extension ops on (c: Context) with
602+
extension ops on (c: Context):
603603
def addNotNullInfo(info: NotNullInfo) =
604604
c.withNotNullInfos(c.notNullInfos.extendWith(info))
605605

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -646,15 +646,13 @@ object Parsers {
646646
else body()
647647
case _ => body()
648648

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

660658
/* -------- REWRITES ----------------------------------------------------------- */
@@ -1292,10 +1290,6 @@ object Parsers {
12921290
in.nextToken()
12931291
if in.token != INDENT then
12941292
syntaxError(i"indented definitions expected")
1295-
else if in.token == WITH then
1296-
in.nextToken()
1297-
if in.token != LBRACE && in.token != INDENT then
1298-
syntaxError(i"indented definitions or `{` expected")
12991293
else
13001294
newLineOptWhenFollowedBy(LBRACE)
13011295

@@ -3022,43 +3016,37 @@ object Parsers {
30223016
*/
30233017
def importExpr(mkTree: ImportConstr): () => Tree = {
30243018

3025-
/** '_' | 'given'
3026-
*/
3027-
def wildcardSelectorId() =
3028-
val name = if in.token == GIVEN then nme.EMPTY else nme.WILDCARD
3029-
atSpan(in.skipToken()) { Ident(name) }
3019+
/** '_' */
3020+
def wildcardSelectorId(name: TermName) = atSpan(in.skipToken()) { Ident(name) }
30303021

30313022
/** ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors]
30323023
* | WildCardSelector {‘,’ WildCardSelector}
30333024
* WildCardSelector ::= ‘given’ (‘_' | InfixType)
30343025
* | ‘_'
30353026
*/
30363027
def importSelectors(idOK: Boolean): List[ImportSelector] =
3037-
val selToken = in.token
3038-
val isWildcard = selToken == USCORE || selToken == GIVEN
3039-
val selector =
3040-
if isWildcard then
3041-
val id = wildcardSelectorId()
3042-
if selToken == USCORE then ImportSelector(id)
3043-
else atSpan(startOffset(id)) {
3028+
val isWildcard = in.token == USCORE || in.token == GIVEN
3029+
val selector = atSpan(in.offset) {
3030+
in.token match
3031+
case USCORE =>
3032+
ImportSelector(wildcardSelectorId(nme.WILDCARD))
3033+
case GIVEN =>
3034+
val id = wildcardSelectorId(nme.EMPTY)
30443035
if in.token == USCORE then
30453036
in.nextToken()
30463037
ImportSelector(id)
3047-
else if in.token != RBRACE && in.token != COMMA then
3048-
ImportSelector(id, bound = infixType())
30493038
else
3050-
ImportSelector(id) // TODO: drop
3051-
}
3052-
else
3053-
val from = termIdent()
3054-
if !idOK then syntaxError(i"named imports cannot follow wildcard imports")
3055-
if in.token == ARROW then
3056-
atSpan(startOffset(from), in.skipToken()) {
3057-
val to = if in.token == USCORE then wildcardIdent() else termIdent()
3058-
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)
3059-
}
3060-
else ImportSelector(from)
3061-
3039+
ImportSelector(id, bound = infixType())
3040+
case _ =>
3041+
val from = termIdent()
3042+
if !idOK then syntaxError(i"named imports cannot follow wildcard imports")
3043+
if in.token == ARROW then
3044+
atSpan(startOffset(from), in.skipToken()) {
3045+
val to = if in.token == USCORE then wildcardIdent() else termIdent()
3046+
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)
3047+
}
3048+
else ImportSelector(from)
3049+
}
30623050
val rest =
30633051
if in.token == COMMA then
30643052
in.nextToken()
@@ -3069,8 +3057,8 @@ object Parsers {
30693057

30703058
val handleImport: Tree => Tree = tree =>
30713059
in.token match
3072-
case USCORE | GIVEN =>
3073-
mkTree(tree, ImportSelector(wildcardSelectorId()) :: Nil)
3060+
case USCORE =>
3061+
mkTree(tree, ImportSelector(wildcardSelectorId(nme.WILDCARD)) :: Nil)
30743062
case LBRACE =>
30753063
mkTree(tree, inBraces(importSelectors(idOK = true)))
30763064
case _ =>

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ object Tokens extends TokensCommon {
257257
AT, CASE)
258258

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

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

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

278278
/** Faced with the choice between a type and a formal parameter, the following

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import scala.annotation.{ threadUnsafe => tu, tailrec }
2727
* for a description of the format.
2828
* TODO: Also extract type information
2929
*/
30-
class ExtractSemanticDB extends Phase with
30+
class ExtractSemanticDB extends Phase:
3131
import Scala3.{_, given _}
3232
import Symbols.{given _}
3333

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

4848
/** Extractor of symbol occurrences from trees */
49-
class Extractor extends TreeTraverser with
49+
class Extractor extends TreeTraverser:
5050

5151
private var nextLocalIdx: Int = 0
5252

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

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

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

245-
private object PatternValDef with
245+
private object PatternValDef:
246246

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

@@ -570,7 +570,7 @@ class ExtractSemanticDB extends Phase with
570570
registerSymbol(vparam.symbol, symbolName(vparam.symbol), symkinds)
571571
traverseTpt(vparam.tpt)
572572

573-
object ExtractSemanticDB with
573+
object ExtractSemanticDB:
574574
import java.nio.file.Path
575575
import scala.collection.JavaConverters._
576576
import java.nio.file.Files

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import java.lang.Character.{isJavaIdentifierPart, isJavaIdentifierStart}
1515
import scala.annotation.internal.sharable
1616
import scala.annotation.switch
1717

18-
object Scala3 with
18+
object Scala3:
1919
import Symbols._
20-
import core.NameOps.given
20+
import core.NameOps.{given _}
2121

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

2626
private val WILDCARDTypeName = nme.WILDCARD.toTypeName
2727

28-
enum SymbolKind derives Eql with
28+
enum SymbolKind derives Eql:
2929
kind =>
3030

3131
case Val, Var, Setter, Abstract
@@ -38,13 +38,13 @@ object Scala3 with
3838

3939
end SymbolKind
4040

41-
object SymbolKind with
41+
object SymbolKind:
4242
val ValSet = Set(Val)
4343
val VarSet = Set(Var)
4444
val emptySet = Set.empty[SymbolKind]
4545
end SymbolKind
4646

47-
object Symbols with
47+
object Symbols:
4848

4949
val RootPackage: String = "_root_/"
5050
val EmptyPackage: String = "_empty_/"
@@ -67,7 +67,7 @@ object Scala3 with
6767

6868
end Symbols
6969

70-
extension NameOps on (name: Name) with
70+
extension NameOps on (name: Name):
7171

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

9090
// end NameOps
9191

92-
extension SymbolOps on (sym: Symbol) with
92+
extension SymbolOps on (sym: Symbol):
9393

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

@@ -128,7 +128,7 @@ object Scala3 with
128128

129129
// end SymbolOps
130130

131-
object LocalSymbol with
131+
object LocalSymbol:
132132

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

149-
extension StringOps on (symbol: String) with
149+
extension StringOps on (symbol: String):
150150

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

172172
// end StringOps
173173

174-
extension InfoOps on (info: SymbolInformation) with
174+
extension InfoOps on (info: SymbolInformation):
175175

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

208208
// end InfoOps
209209

210-
extension RangeOps on (range: Range) with
210+
extension RangeOps on (range: Range):
211211
def hasLength = range.endLine > range.startLine || range.endCharacter > range.startCharacter
212212
// end RangeOps
213213

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

241241
override def compare(o1: T, o2: T): Int =
242242
val len = math.min(o1.length(), o2.length())

compiler/src/dotty/tools/dotc/semanticdb/Tools.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import java.nio.file._
44
import java.nio.charset.StandardCharsets
55
import scala.collection.JavaConverters._
66
import dotty.tools.dotc.util.SourceFile
7-
import dotty.tools.dotc.semanticdb.Scala3.{_, given}
7+
import dotty.tools.dotc.semanticdb.Scala3.{_, given _}
88

9-
object Tools with
9+
object Tools:
1010

1111
/** Load SemanticDB TextDocument for a single Scala source file
1212
*

compiler/src/dotty/tools/dotc/transform/LiftTry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ class LiftTry extends MiniPhase with IdentityDenotTransformer { thisPhase =>
7878
}
7979
else tree
8080
}
81-
object LiftTry with
81+
object LiftTry:
8282
val name = "liftTry"

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import NameKinds.DefaultGetterName
2222
import ProtoTypes._
2323
import Inferencing._
2424
import transform.TypeUtils._
25-
import Nullables.{postProcessByNameArgs, given}
25+
import Nullables.{postProcessByNameArgs, given _}
2626

2727
import collection.mutable
2828
import config.Printers.{overload, typr, unapp}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ trait Implicits { self: Typer =>
14831483
if diff == 0 then
14841484
// Fall back: if both results are extension method applications,
14851485
// compare the extension methods instead of their wrappers.
1486-
object extMethodApply with
1486+
object extMethodApply:
14871487
def unapply(t: Tree): Option[Type] = t match
14881488
case t: Applications.ExtMethodApply => Some(methPart(stripApply(t.app)).tpe)
14891489
case _ => None

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import collection.mutable
1616
/** This trait defines the method `importSuggestionAddendum` that adds an addendum
1717
* to error messages suggesting additional imports.
1818
*/
19-
trait ImportSuggestions with
19+
trait ImportSuggestions:
2020
this: Typer =>
2121

2222
import tpd._
@@ -167,7 +167,7 @@ trait ImportSuggestions with
167167
def deepTest(ref: TermRef): Boolean =
168168
System.currentTimeMillis < deadLine
169169
&& {
170-
val task = new TimerTask with
170+
val task = new TimerTask:
171171
def run() =
172172
println(i"Cancelling test of $ref when making suggestions for error in ${ctx.source}")
173173
ctx.run.isCancelled = true

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import ErrorReporting.errorTree
2424
import dotty.tools.dotc.tastyreflect.ReflectionImpl
2525
import dotty.tools.dotc.util.{SimpleIdentityMap, SimpleIdentitySet, SourceFile, SourcePosition}
2626
import dotty.tools.dotc.parsing.Parsers.Parser
27-
import Nullables.given
27+
import Nullables.{given _}
2828

2929
import collection.mutable
3030
import reporting.trace

0 commit comments

Comments
 (0)