Skip to content

Update given syntax in compiler and library #10598

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

Closed
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 @@ -124,7 +124,7 @@ object DottyBackendInterface {
requiredModule(className)
}

given symExtensions as AnyRef:
given symExtensions: AnyRef with
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/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
private var myCtx = rootContext(using ictx)

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

private var myUnits: List[CompilationUnit] = _
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ object Trees {
def applyOverloaded(
receiver: tpd.Tree, method: TermName, args: List[Tree], targs: List[Type],
expectedType: Type)(using parentCtx: Context): tpd.Tree = {
given ctx as Context = parentCtx.retractMode(Mode.ImplicitsEnabled)
given ctx: Context = parentCtx.retractMode(Mode.ImplicitsEnabled)
import dotty.tools.dotc.ast.tpd.TreeOps

val typer = ctx.typer
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Comments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Comments {
val ContextDoc: Key[ContextDocstrings] = new Key[ContextDocstrings]

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

/** Context for Docstrings, contains basic functionality for getting
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 @@ -649,7 +649,7 @@ object Contexts {
def setDebug: this.type = setSetting(base.settings.Ydebug, true)
}

given ops as AnyRef:
given ops: AnyRef with
extension (c: Context):
def addNotNullInfo(info: NotNullInfo) =
c.withNotNullInfos(c.notNullInfos.extendWith(info))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Definitions {
import Definitions._

private var initCtx: Context = _
private given currentContext[Dummy_so_its_a_def] as Context = initCtx
private given currentContext[Dummy_so_its_a_def]: Context = initCtx

private def newPermanentSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type) =
newSymbol(owner, name, flags | Permanent, info)
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 @@ -34,7 +34,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
private var myContext: Context = initctx
def comparerContext: Context = myContext

protected given [DummySoItsADef] as Context = myContext
protected given [DummySoItsADef]: Context = myContext

protected var state: TyperState = null
def constraint: Constraint = state.constraint
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
* Overridden in RefinedPrinter.
*/
protected def curCtx: Context = _ctx.addMode(Mode.Printing)
protected given [DummyToEnforceDef] as Context = curCtx
protected given [DummyToEnforceDef]: Context = curCtx

protected def printDebug = ctx.settings.YprintDebug.value

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

given stringToText as Conversion[String, Text] = Str(_)
given stringToText: Conversion[String, Text] = Str(_)

/** If true, tweak output so it is the same before and after pickling */
protected def homogenizedView: Boolean = ctx.settings.YtestPickler.value
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 @@ -68,7 +68,7 @@ object Scala3:
end Symbols


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

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

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

given StringOps as AnyRef:
given StringOps: AnyRef with
extension (symbol: String):
def isSymbol: Boolean = !symbol.isEmpty
def isRootPackage: Boolean = RootPackage == symbol
Expand All @@ -169,7 +169,7 @@ object Scala3:
isJavaIdentifierStart(symbol.head) && symbol.tail.forall(isJavaIdentifierPart)
end StringOps

given InfoOps as AnyRef:
given InfoOps: AnyRef with
extension (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 @@ -204,13 +204,13 @@ object Scala3:
def isInterface: Boolean = info.kind.isInterface
end InfoOps

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

/** Sort symbol occurrences by their start position. */
given OccurrenceOrdering as Ordering[SymbolOccurrence] = (x, y) =>
given OccurrenceOrdering: Ordering[SymbolOccurrence] = (x, y) =>
x.range -> y.range match
case None -> _ | _ -> None => 0
case Some(a) -> Some(b) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ object ExplicitOuter {
*/
class OuterOps(val ictx: Context) extends AnyVal {
/** The context of all operations of this class */
given [Dummy] as Context = ictx
given [Dummy]: Context = ictx

/** If `cls` has an outer parameter add one to the method type `tp`. */
def addParam(cls: ClassSymbol, tp: Type): Type =
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Deriving.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ trait Deriving {
//
// ADT: C[A, B] (A, B have same kinds at T, U)
//
// given derived$TC as TC[ C ] // a "natural" instance
// given derived$TC : TC[ C ] // a "natural" instance
//
// ADT: C[A] (A has same kind as U)
//
// given derived$TC as TC[[t, u] =>> C[ u]]
// given derived$TC : TC[[t, u] =>> C[ u]]
//
// (b) The type class and all ADT type parameters are of kind *
//
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ class Namer { typer: Typer =>
protected def localContext(owner: Symbol): FreshContext = ctx.fresh.setOwner(owner).setTree(original)

/** The context with which this completer was created */
given creationContext as Context = ictx
given creationContext: Context = ictx

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

override final def typeSig(sym: Symbol): Type =
val tparamSyms = completerTypeParams(sym)(using ictx)
given ctx as Context = nestedCtx
given ctx: Context = nestedCtx

def abstracted(tp: TypeBounds): TypeBounds =
HKTypeLambda.boundsFromParams(tparamSyms, tp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ object PrepareInlineable {
if (!ctx.isAfterTyper) {
val inlineCtx = ctx
inlined.updateAnnotation(LazyBodyAnnotation {
given ctx as Context = inlineCtx
given ctx: Context = inlineCtx
var inlinedBody = dropInlineIfError(inlined, treeExpr)
if inlined.isInlineMethod then
inlinedBody = dropInlineIfError(inlined,
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ReplCompilerTests extends ReplTest {
| extension (x: T) def > (y: T) = compare(x, y) > 0
|}
|
|given IntOrd as Ord[Int] {
|given IntOrd: Ord[Int] with {
| def compare(x: Int, y: Int) =
| if (x < y) -1 else if (x > y) +1 else 0
|}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/metaprogramming/erased-terms-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ title: "Erased Terms Spec"

3. Functions
* `(erased x1: T1, x2: T2, ..., xN: TN) => y : (erased T1, T2, ..., TN) => R`
* `(given erased x1: T1, x2: T2, ..., xN: TN) => y as (given erased T1, T2, ..., TN) => R`
* `(given erased x1: T1, x2: T2, ..., xN: TN) => y: (given erased T1, T2, ..., TN) => R`
* `(given erased T1) => R <:< erased T1 => R`
* `(given erased T1, T2) => R <:< (erased T1, T2) => R`
* ...
Expand Down
Loading