Skip to content

Commit e0c6e6f

Browse files
Merge pull request #10613 from dotty-staging/drop-old-given-syntax
Drop old given syntax
2 parents 11f53c7 + d145300 commit e0c6e6f

Some content is hidden

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

57 files changed

+373
-391
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ object DottyBackendInterface {
124124
requiredModule(className)
125125
}
126126

127-
given symExtensions as AnyRef:
127+
given symExtensions: AnyRef with
128128
extension (sym: Symbol):
129129

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

compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
942942
private case object NoTypeTest extends RTTypeTest
943943

944944
private object RTTypeTest {
945-
given PartialOrdering[RTTypeTest] {
945+
given PartialOrdering[RTTypeTest] with {
946946
override def tryCompare(lhs: RTTypeTest, rhs: RTTypeTest): Option[Int] = {
947947
if (lteq(lhs, rhs)) if (lteq(rhs, lhs)) Some(0) else Some(-1)
948948
else if (lteq(rhs, lhs)) Some(1) else None

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
8585
private var myCtx = rootContext(using ictx)
8686

8787
/** The context created for this run */
88-
given runContext[Dummy_so_its_a_def] as Context = myCtx
88+
given runContext[Dummy_so_its_a_def]: Context = myCtx
8989
assert(runContext.runId <= Periods.MaxPossibleRunId)
9090

9191
private var myUnits: List[CompilationUnit] = _

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ object Trees {
15531553
def applyOverloaded(
15541554
receiver: tpd.Tree, method: TermName, args: List[Tree], targs: List[Type],
15551555
expectedType: Type)(using parentCtx: Context): tpd.Tree = {
1556-
given ctx as Context = parentCtx.retractMode(Mode.ImplicitsEnabled)
1556+
given ctx: Context = parentCtx.retractMode(Mode.ImplicitsEnabled)
15571557
import dotty.tools.dotc.ast.tpd.TreeOps
15581558

15591559
val typer = ctx.typer

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Comments {
1515
val ContextDoc: Key[ContextDocstrings] = new Key[ContextDocstrings]
1616

1717
/** Decorator for getting docbase out of context */
18-
given CommentsContext as AnyRef:
18+
given CommentsContext: AnyRef with
1919
extension (c: Context) def docCtx: Option[ContextDocstrings] = c.property(ContextDoc)
2020

2121
/** Context for Docstrings, contains basic functionality for getting

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ object Contexts {
649649
def setDebug: this.type = setSetting(base.settings.Ydebug, true)
650650
}
651651

652-
given ops as AnyRef:
652+
given ops: AnyRef with
653653
extension (c: Context):
654654
def addNotNullInfo(info: NotNullInfo) =
655655
c.withNotNullInfos(c.notNullInfos.extendWith(info))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Definitions {
3838
import Definitions._
3939

4040
private var initCtx: Context = _
41-
private given currentContext[Dummy_so_its_a_def] as Context = initCtx
41+
private given currentContext[Dummy_so_its_a_def]: Context = initCtx
4242

4343
private def newPermanentSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type) =
4444
newSymbol(owner, name, flags | Permanent, info)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
3434
private var myContext: Context = initctx
3535
def comparerContext: Context = myContext
3636

37-
protected given [DummySoItsADef] as Context = myContext
37+
protected given [DummySoItsADef]: Context = myContext
3838

3939
protected var state: TyperState = null
4040
def constraint: Constraint = state.constraint

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ object Parsers {
913913
lookahead.nextToken()
914914
skipParams()
915915
skipParams()
916-
lookahead.token == COLON || lookahead.isIdent(nme.as)
916+
lookahead.token == COLON
917917

918918
def followingIsExtension() =
919919
val next = in.lookahead.token
@@ -3517,9 +3517,8 @@ object Parsers {
35173517
*/
35183518
def givenDef(start: Offset, mods: Modifiers, givenMod: Mod) = atSpan(start, nameStart) {
35193519
var mods1 = addMod(mods, givenMod)
3520-
val hasGivenSig = followingIsGivenSig()
35213520
val nameStart = in.offset
3522-
val name = if isIdent && hasGivenSig then ident() else EmptyTermName
3521+
val name = if isIdent && followingIsGivenSig() then ident() else EmptyTermName
35233522

35243523
val gdef =
35253524
val tparams = typeParamClauseOpt(ParamOwner.Def)
@@ -3530,10 +3529,7 @@ object Parsers {
35303529
else Nil
35313530
newLinesOpt()
35323531
val noParams = tparams.isEmpty && vparamss.isEmpty
3533-
val newSyntax = in.token == COLON
3534-
if !(name.isEmpty && noParams) then
3535-
if isIdent(nme.as) then in.nextToken()
3536-
else accept(COLON)
3532+
if !(name.isEmpty && noParams) then accept(COLON)
35373533
val parents = constrApp() :: withConstrApps()
35383534
val parentsIsType = parents.length == 1 && parents.head.isType
35393535
if in.token == EQUALS && parentsIsType then
@@ -3544,22 +3540,16 @@ object Parsers {
35443540
ValDef(name, parents.head, subExpr())
35453541
else
35463542
DefDef(name, tparams, vparamss, parents.head, subExpr())
3547-
else if newSyntax && in.token != WITH && in.token != WITHEOL && parentsIsType then
3543+
else if in.token != WITH && in.token != WITHEOL && parentsIsType then
35483544
if name.isEmpty then
35493545
syntaxError(em"anonymous given cannot be abstract")
35503546
DefDef(name, tparams, vparamss, parents.head, EmptyTree)
35513547
else
35523548
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
35533549
val vparamss1 = vparamss.map(_.map(vparam =>
35543550
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
3555-
val constr = makeConstructor(tparams1, vparamss1)
3556-
val templ =
3557-
if newSyntax || in.token == WITHEOL || in.token == WITH then
3558-
withTemplate(constr, parents)
3559-
else
3560-
possibleTemplateStart()
3561-
templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3562-
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3551+
val templ = withTemplate(makeConstructor(tparams1, vparamss1), parents)
3552+
if noParams then ModuleDef(name, templ)
35633553
else TypeDef(name.toTypeName, templ)
35643554
end gdef
35653555
finalizeDef(gdef, mods1, start)

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
2121
* Overridden in RefinedPrinter.
2222
*/
2323
protected def curCtx: Context = _ctx.addMode(Mode.Printing)
24-
protected given [DummyToEnforceDef] as Context = curCtx
24+
protected given [DummyToEnforceDef]: Context = curCtx
2525

2626
protected def printDebug = ctx.settings.YprintDebug.value
2727

@@ -39,7 +39,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
3939
limiter.register(str)
4040
Texts.Str(str, lineRange)
4141

42-
given stringToText as Conversion[String, Text] = Str(_)
42+
given stringToText: Conversion[String, Text] = Str(_)
4343

4444
/** If true, tweak output so it is the same before and after pickling */
4545
protected def homogenizedView: Boolean = ctx.settings.YtestPickler.value

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object Scala3:
6868
end Symbols
6969

7070

71-
given NameOps as AnyRef:
71+
given NameOps: AnyRef with
7272
extension (name: Name):
7373
def isWildcard = name match
7474
case nme.WILDCARD | WILDCARDTypeName => true
@@ -89,7 +89,7 @@ object Scala3:
8989
}
9090
end NameOps
9191

92-
given SymbolOps as AnyRef:
92+
given SymbolOps: AnyRef with
9393
extension (sym: Symbol):
9494

9595
def ifExists(using Context): Option[Symbol] = if sym.exists then Some(sym) else None
@@ -145,7 +145,7 @@ object Scala3:
145145
case '/' | '.' | '#' | ']' | ')' => true
146146
case _ => false
147147

148-
given StringOps as AnyRef:
148+
given StringOps: AnyRef with
149149
extension (symbol: String):
150150
def isSymbol: Boolean = !symbol.isEmpty
151151
def isRootPackage: Boolean = RootPackage == symbol
@@ -169,7 +169,7 @@ object Scala3:
169169
isJavaIdentifierStart(symbol.head) && symbol.tail.forall(isJavaIdentifierPart)
170170
end StringOps
171171

172-
given InfoOps as AnyRef:
172+
given InfoOps: AnyRef with
173173
extension (info: SymbolInformation):
174174
def isAbstract: Boolean = (info.properties & SymbolInformation.Property.ABSTRACT.value) != 0
175175
def isFinal: Boolean = (info.properties & SymbolInformation.Property.FINAL.value) != 0
@@ -204,13 +204,13 @@ object Scala3:
204204
def isInterface: Boolean = info.kind.isInterface
205205
end InfoOps
206206

207-
given RangeOps as AnyRef:
207+
given RangeOps: AnyRef with
208208
extension (range: Range):
209209
def hasLength = range.endLine > range.startLine || range.endCharacter > range.startCharacter
210210
end RangeOps
211211

212212
/** Sort symbol occurrences by their start position. */
213-
given OccurrenceOrdering as Ordering[SymbolOccurrence] = (x, y) =>
213+
given OccurrenceOrdering: Ordering[SymbolOccurrence] = (x, y) =>
214214
x.range -> y.range match
215215
case None -> _ | _ -> None => 0
216216
case Some(a) -> Some(b) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ object ExplicitOuter {
353353
*/
354354
class OuterOps(val ictx: Context) extends AnyVal {
355355
/** The context of all operations of this class */
356-
given [Dummy] as Context = ictx
356+
given [Dummy]: Context = ictx
357357

358358
/** If `cls` has an outer parameter add one to the method type `tp`. */
359359
def addParam(cls: ClassSymbol, tp: Type): Type =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ trait Deriving {
125125
//
126126
// ADT: C[A, B] (A, B have same kinds at T, U)
127127
//
128-
// given derived$TC as TC[ C ] // a "natural" instance
128+
// given derived$TC : TC[ C ] // a "natural" instance
129129
//
130130
// ADT: C[A] (A has same kind as U)
131131
//
132-
// given derived$TC as TC[[t, u] =>> C[ u]]
132+
// given derived$TC : TC[[t, u] =>> C[ u]]
133133
//
134134
// (b) The type class and all ADT type parameters are of kind *
135135
//

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class Namer { typer: Typer =>
669669
protected def localContext(owner: Symbol): FreshContext = ctx.fresh.setOwner(owner).setTree(original)
670670

671671
/** The context with which this completer was created */
672-
given creationContext as Context = ictx
672+
given creationContext: Context = ictx
673673

674674
// make sure testing contexts are not captured by completers
675675
assert(!ictx.reporter.isInstanceOf[ExploringReporter])
@@ -835,7 +835,7 @@ class Namer { typer: Typer =>
835835

836836
override final def typeSig(sym: Symbol): Type =
837837
val tparamSyms = completerTypeParams(sym)(using ictx)
838-
given ctx as Context = nestedCtx
838+
given ctx: Context = nestedCtx
839839

840840
def abstracted(tp: TypeBounds): TypeBounds =
841841
HKTypeLambda.boundsFromParams(tparamSyms, tp)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ object PrepareInlineable {
236236
if (!ctx.isAfterTyper) {
237237
val inlineCtx = ctx
238238
inlined.updateAnnotation(LazyBodyAnnotation {
239-
given ctx as Context = inlineCtx
239+
given ctx: Context = inlineCtx
240240
var inlinedBody = dropInlineIfError(inlined, treeExpr)
241241
if inlined.isInlineMethod then
242242
inlinedBody = dropInlineIfError(inlined,

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class ReplCompilerTests extends ReplTest {
174174
| extension (x: T) def > (y: T) = compare(x, y) > 0
175175
|}
176176
|
177-
|given IntOrd as Ord[Int] {
177+
|given IntOrd: Ord[Int] with {
178178
| def compare(x: Int, y: Int) =
179179
| if (x < y) -1 else if (x > y) +1 else 0
180180
|}

docs/docs/reference/metaprogramming/erased-terms-spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ title: "Erased Terms Spec"
3232

3333
3. Functions
3434
* `(erased x1: T1, x2: T2, ..., xN: TN) => y : (erased T1, T2, ..., TN) => R`
35-
* `(given erased x1: T1, x2: T2, ..., xN: TN) => y as (given erased T1, T2, ..., TN) => R`
35+
* `(given erased x1: T1, x2: T2, ..., xN: TN) => y: (given erased T1, T2, ..., TN) => R`
3636
* `(given erased T1) => R <:< erased T1 => R`
3737
* `(given erased T1, T2) => R <:< (erased T1, T2) => R`
3838
* ...

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class CompletionTest {
361361
@Test def completeExtensionMethodFromGivenInstanceDefinedInScope: Unit = {
362362
code"""object Foo
363363
|trait FooOps
364-
|given FooOps {
364+
|given FooOps with {
365365
| extension (foo: Foo.type) def xxxx = 1
366366
|}
367367
|object Main { Foo.xx${m1} }""".withSource
@@ -372,7 +372,7 @@ class CompletionTest {
372372
code"""object Foo
373373
|trait FooOps
374374
|object Bar {
375-
| given FooOps {
375+
| given FooOps with {
376376
| extension (foo: Foo.type) def xxxx = 1
377377
| }
378378
|}
@@ -394,7 +394,7 @@ class CompletionTest {
394394
code"""trait Bar
395395
|case class Foo(i: Int)
396396
|object Foo {
397-
| given Bar {
397+
| given Bar with {
398398
| extension (foo: Foo) def xxxx = foo.i
399399
| }
400400
|}

0 commit comments

Comments
 (0)