Skip to content

Commit 909d854

Browse files
committed
Drop outdated syntax for given import selectors
It is `given _`, or `given Type`, never `given` alone.
1 parent 6beb2f4 commit 909d854

File tree

54 files changed

+134
-140
lines changed

Some content is hidden

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

54 files changed

+134
-140
lines changed

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: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,43 +3022,37 @@ object Parsers {
30223022
*/
30233023
def importExpr(mkTree: ImportConstr): () => Tree = {
30243024

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) }
3025+
/** '_' */
3026+
def wildcardSelectorId(name: TermName) = atSpan(in.skipToken()) { Ident(name) }
30303027

30313028
/** ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors]
30323029
* | WildCardSelector {‘,’ WildCardSelector}
30333030
* WildCardSelector ::= ‘given’ (‘_' | InfixType)
30343031
* | ‘_'
30353032
*/
30363033
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)) {
3034+
val isWildcard = in.token == USCORE || in.token == GIVEN
3035+
val selector = atSpan(in.offset) {
3036+
in.token match
3037+
case USCORE =>
3038+
ImportSelector(wildcardSelectorId(nme.WILDCARD))
3039+
case GIVEN =>
3040+
val id = wildcardSelectorId(nme.EMPTY)
30443041
if in.token == USCORE then
30453042
in.nextToken()
30463043
ImportSelector(id)
3047-
else if in.token != RBRACE && in.token != COMMA then
3048-
ImportSelector(id, bound = infixType())
30493044
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-
3045+
ImportSelector(id, bound = infixType())
3046+
case _ =>
3047+
val from = termIdent()
3048+
if !idOK then syntaxError(i"named imports cannot follow wildcard imports")
3049+
if in.token == ARROW then
3050+
atSpan(startOffset(from), in.skipToken()) {
3051+
val to = if in.token == USCORE then wildcardIdent() else termIdent()
3052+
ImportSelector(from, if to.name == nme.ERROR then EmptyTree else to)
3053+
}
3054+
else ImportSelector(from)
3055+
}
30623056
val rest =
30633057
if in.token == COMMA then
30643058
in.nextToken()
@@ -3069,8 +3063,8 @@ object Parsers {
30693063

30703064
val handleImport: Tree => Tree = tree =>
30713065
in.token match
3072-
case USCORE | GIVEN =>
3073-
mkTree(tree, ImportSelector(wildcardSelectorId()) :: Nil)
3066+
case USCORE =>
3067+
mkTree(tree, ImportSelector(wildcardSelectorId(nme.WILDCARD)) :: Nil)
30743068
case LBRACE =>
30753069
mkTree(tree, inBraces(importSelectors(idOK = true)))
30763070
case _ =>

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ object Nullables:
370370
def assignmentSpans(using Context): Map[Int, List[Span]] =
371371
import ast.untpd._
372372

373-
object populate extends UntypedTreeTraverser with
373+
object populate extends UntypedTreeTraverser:
374374

375375
/** The name offsets of variables that are tracked */
376376
var tracked: Map[Int, List[Span]] = Map.empty
@@ -468,7 +468,7 @@ object Nullables:
468468
if mt.paramInfos.exists(_.isInstanceOf[ExprType]) && !fn.symbol.is(Inline) =>
469469
app match
470470
case Apply(fn, args) =>
471-
val dropNotNull = new TreeMap with
471+
val dropNotNull = new TreeMap:
472472
override def transform(t: Tree)(using Context) = t match
473473
case AssertNotNull(t0) if t0.symbol.is(Mutable) =>
474474
nullables.println(i"dropping $t")
@@ -481,7 +481,7 @@ object Nullables:
481481
t
482482
case _ => super.transform(t)
483483

484-
object retyper extends ReTyper with
484+
object retyper extends ReTyper:
485485
override def typedUnadapted(t: untpd.Tree, pt: Type, locked: TypeVars)(implicit ctx: Context): Tree = t match
486486
case t: ValDef if !t.symbol.is(Lazy) => super.typedUnadapted(t, pt, locked)
487487
case t: MemberDef => promote(t)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ object ProtoTypes {
115115
}
116116

117117
/** A class marking ignored prototypes that can be revealed by `deepenProto` */
118-
case class IgnoredProto(ignored: Type) extends UncachedGroundType with MatchAlways with
118+
case class IgnoredProto(ignored: Type) extends UncachedGroundType with MatchAlways:
119119
override def revealIgnored = ignored
120120
override def deepenProto(implicit ctx: Context): Type = ignored
121121

122-
object IgnoredProto with
122+
object IgnoredProto:
123123
def apply(ignored: Type): IgnoredProto = ignored match
124124
case ignored: IgnoredProto => ignored
125125
case _ => new IgnoredProto(ignored)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import dotty.tools.dotc.transform.{PCPCheckAndHeal, Staging, TreeMapWithStages}
4040
import transform.SymUtils._
4141
import transform.TypeUtils._
4242
import reporting.trace
43-
import Nullables.{NotNullInfo, given}
43+
import Nullables.{NotNullInfo, given _}
4444
import NullOpsDecorator._
4545

4646
object Typer {

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import org.junit.experimental.categories.Category
1919

2020
import dotty.BootstrappedOnlyTests
2121
import dotty.tools.dotc.Main
22-
import dotty.tools.dotc.semanticdb.Scala3.given
22+
import dotty.tools.dotc.semanticdb.Scala3.{given _}
2323
import dotty.tools.dotc.util.SourceFile
2424

2525
@main def updateExpect =
2626
SemanticdbTests().runExpectTest(updateExpectFiles = true)
2727

2828
@Category(Array(classOf[BootstrappedOnlyTests]))
29-
class SemanticdbTests with
29+
class SemanticdbTests:
3030
val javaFile = FileSystems.getDefault.getPathMatcher("glob:**.java")
3131
val scalaFile = FileSystems.getDefault.getPathMatcher("glob:**.scala")
3232
val expectFile = FileSystems.getDefault.getPathMatcher("glob:**.expect.scala")

0 commit comments

Comments
 (0)