diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index f56c2675d282..17873cf62ecb 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -480,7 +480,7 @@ object desugar { if (enumCases.isEmpty) ctx.error("Enumerations must constain at least one case", namePos) val enumCompanionRef = TermRefTree() - val enumImport = Import(importDelegate = false, enumCompanionRef, enumCases.flatMap(caseIds)) + val enumImport = Import(importGiven = false, enumCompanionRef, enumCases.flatMap(caseIds)) (enumImport :: enumStats, enumCases, enumCompanionRef) } else (stats, Nil, EmptyTree) @@ -750,7 +750,7 @@ object desugar { // synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] = // new C[Ts](p11, ..., p1N) ... (pM1, ..., pMN) = val implicitWrappers = - if (!mods.isOneOf(DelegateOrImplicit)) + if (!mods.isOneOf(GivenOrImplicit)) Nil else if (ctx.owner.is(Package)) { ctx.error(TopLevelImplicitClass(cdef), cdef.sourcePos) @@ -764,7 +764,7 @@ object desugar { ctx.error(ImplicitCaseClass(cdef), cdef.sourcePos) Nil } - else if (arity != 1 && !mods.is(Delegate)) { + else if (arity != 1 && !mods.is(Given)) { ctx.error(ImplicitClassPrimaryConstructorArity(), cdef.sourcePos) Nil } @@ -778,7 +778,7 @@ object desugar { // implicit wrapper is typechecked in same scope as constructor, so // we can reuse the constructor parameters; no derived params are needed. DefDef(className.toTermName, constrTparams, defParamss, classTypeRef, creatorExpr) - .withMods(companionMods | mods.flags.toTermFlags & DelegateOrImplicit | Synthetic | Final) + .withMods(companionMods | mods.flags.toTermFlags & GivenOrImplicit | Synthetic | Final) .withSpan(cdef.span) :: Nil } @@ -1177,14 +1177,14 @@ object desugar { */ def packageDef(pdef: PackageDef)(implicit ctx: Context): PackageDef = { def isWrappedType(stat: TypeDef): Boolean = - !stat.isClassDef || stat.mods.isOneOf(DelegateOrImplicit) + !stat.isClassDef || stat.mods.isOneOf(GivenOrImplicit) val wrappedTypeNames = pdef.stats.collect { case stat: TypeDef if isWrappedType(stat) => stat.name } def needsObject(stat: Tree) = stat match { case _: ValDef | _: PatDef | _: DefDef | _: Export => true case stat: ModuleDef => - stat.mods.isOneOf(DelegateOrImplicit) || + stat.mods.isOneOf(GivenOrImplicit) || wrappedTypeNames.contains(stat.name.stripModuleClassSuffix.toTypeName) case stat: TypeDef => isWrappedType(stat) case _ => false diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 2c600701911a..e655927c2eb4 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -874,7 +874,7 @@ object TreeInfo { /** The expression has no side effects */ val Pure: PurityLevel = new PurityLevel(3) - /** Running the expression a second time has no side effects. Delegate by `Pure`. */ + /** Running the expression a second time has no side effects. Implied by `Pure`. */ val Idempotent: PurityLevel = new PurityLevel(1) val Impure: PurityLevel = new PurityLevel(0) diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 0d86517c16aa..b5c64669c19e 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -754,7 +754,7 @@ object Trees { def unforced: LazyTree[T] = preRhs protected def force(x: Tree[T @uncheckedVariance]): Unit = preRhs = x - override def disableOverlapChecks = rawMods.is(Delegate) + override def disableOverlapChecks = rawMods.is(Given) // disable order checks for implicit aliases since their given clause follows // their for clause, but the two appear swapped in the DefDef. } @@ -800,7 +800,7 @@ object Trees { * where a selector is either an untyped `Ident`, `name` or * an untyped thicket consisting of `name` and `rename`. */ - case class Import[-T >: Untyped] private[ast] (importDelegate: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile) + case class Import[-T >: Untyped] private[ast] (importGiven: Boolean, expr: Tree[T], selectors: List[Tree[Untyped]])(implicit @constructorOnly src: SourceFile) extends DenotingTree[T] { type ThisTree[-T >: Untyped] = Import[T] } @@ -1188,9 +1188,9 @@ object Trees { case tree: Template if (constr eq tree.constr) && (parents eq tree.parents) && (derived eq tree.derived) && (self eq tree.self) && (body eq tree.unforcedBody) => tree case tree => finalize(tree, untpd.Template(constr, parents, derived, self, body)(sourceFile(tree))) } - def Import(tree: Tree)(importDelegate: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match { - case tree: Import if (importDelegate == tree.importDelegate) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree - case _ => finalize(tree, untpd.Import(importDelegate, expr, selectors)(sourceFile(tree))) + def Import(tree: Tree)(importGiven: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = tree match { + case tree: Import if (importGiven == tree.importGiven) && (expr eq tree.expr) && (selectors eq tree.selectors) => tree + case _ => finalize(tree, untpd.Import(importGiven, expr, selectors)(sourceFile(tree))) } def PackageDef(tree: Tree)(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = tree match { case tree: PackageDef if (pid eq tree.pid) && (stats eq tree.stats) => tree @@ -1331,8 +1331,8 @@ object Trees { cpy.TypeDef(tree)(name, transform(rhs)) case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty => cpy.Template(tree)(transformSub(constr), transform(tree.parents), Nil, transformSub(self), transformStats(tree.body)) - case Import(importDelegate, expr, selectors) => - cpy.Import(tree)(importDelegate, transform(expr), selectors) + case Import(importGiven, expr, selectors) => + cpy.Import(tree)(importGiven, transform(expr), selectors) case PackageDef(pid, stats) => cpy.PackageDef(tree)(transformSub(pid), transformStats(stats)(localCtx)) case Annotated(arg, annot) => diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 821095dde886..f9ad72454038 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -333,8 +333,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { Block(cdef :: Nil, New(cls.typeRef, Nil)) } - def Import(importDelegate: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = - ta.assignType(untpd.Import(importDelegate, expr, selectors), ctx.newImportSymbol(ctx.owner, expr)) + def Import(importGiven: Boolean, expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = + ta.assignType(untpd.Import(importGiven, expr, selectors), ctx.newImportSymbol(ctx.owner, expr)) def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = ta.assignType(untpd.PackageDef(pid, stats), pid) diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 2330b0d7d546..3ccad3370b08 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -165,8 +165,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { case class Lazy()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Lazy) case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline) - - case class Delegate()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Delegate) } /** Modifiers and annotations for definitions @@ -341,7 +339,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { def Template(constr: DefDef, parents: List[Tree], derived: List[Tree], self: ValDef, body: LazyTreeList)(implicit src: SourceFile): Template = if (derived.isEmpty) new Template(constr, parents, self, body) else new DerivingTemplate(constr, parents ++ derived, self, body, derived.length) - def Import(importDelegate: Boolean, expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(importDelegate, expr, selectors) + def Import(importGiven: Boolean, expr: Tree, selectors: List[Tree])(implicit src: SourceFile): Import = new Import(importGiven, expr, selectors) def PackageDef(pid: RefTree, stats: List[Tree])(implicit src: SourceFile): PackageDef = new PackageDef(pid, stats) def Annotated(arg: Tree, annot: Tree)(implicit src: SourceFile): Annotated = new Annotated(arg, annot) diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 36ad47b9e467..1e64f416b3c9 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -13,7 +13,7 @@ import Scopes._ import Uniques._ import ast.Trees._ import ast.untpd -import Flags.DelegateOrGivenOrImplicit +import Flags.GivenOrImplicit import util.{FreshNameCreator, NoSource, SimpleIdentityMap, SourceFile} import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer} import Implicits.ContextualImplicits @@ -214,7 +214,7 @@ object Contexts { implicitsCache = { val implicitRefs: List[ImplicitRef] = if (isClassDefContext) - try owner.thisType.implicitMembers(DelegateOrGivenOrImplicit) + try owner.thisType.implicitMembers(GivenOrImplicit) catch { case ex: CyclicReference => Nil } @@ -404,7 +404,7 @@ object Contexts { case _ => None } ctx.fresh.setImportInfo( - ImportInfo(sym, imp.selectors, impNameOpt, imp.importDelegate)) + ImportInfo(sym, imp.selectors, impNameOpt, imp.importGiven)) } /** Does current phase use an erased types interpretation? */ diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 5cccde7e51c7..b4c3be1f9c24 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -22,7 +22,7 @@ object Flags { type Flag = opaques.Flag - delegate FlagOps { + given FlagOps { def (x: FlagSet) bits: Long = opaques.toBits(x) @@ -338,8 +338,6 @@ object Flags { /** Symbol is a Java default method */ val (_, DefaultMethod @ _, _) = newFlags(38, "") - val (Delegate @ _, _, _) = newFlags(39, "delegate") - /** Symbol is an enum class or enum case (if used with case) */ val (Enum @ _, _, _) = newFlags(40, "") @@ -421,7 +419,7 @@ object Flags { /** Flags representing source modifiers */ private val CommonSourceModifierFlags: FlagSet = - commonFlags(Private, Protected, Final, Case, Implicit, Delegate, Given, Override, JavaStatic) + commonFlags(Private, Protected, Final, Case, Implicit, Given, Override, JavaStatic) val TypeSourceModifierFlags: FlagSet = CommonSourceModifierFlags.toTypeFlags | Abstract | Sealed | Opaque @@ -443,7 +441,7 @@ object Flags { HigherKinded, Param, ParamAccessor, Scala2ExistentialCommon, Mutable, Opaque, Touched, JavaStatic, OuterOrCovariant, LabelOrContravariant, CaseAccessor, - Extension, NonMember, Implicit, Given, Delegate, Permanent, Synthetic, + Extension, NonMember, Implicit, Given, Permanent, Synthetic, SuperAccessorOrScala2x, Inline) /** Flags that are not (re)set when completing the denotation, or, if symbol is @@ -502,14 +500,14 @@ object Flags { /** Flags that can apply to a module val */ val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags | - Override | Final | Method | Implicit | Delegate | Lazy | + Override | Final | Method | Implicit | Given | Lazy | Accessor | AbsOverride | StableRealizable | Captured | Synchronized | Erased /** Flags that can apply to a module class */ val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | Enum /** Flags retained in export forwarders */ - val RetainedExportFlags = Delegate | Given | Implicit | Extension + val RetainedExportFlags = Given | Implicit | Extension // ------- Other flag sets ------------------------------------- @@ -528,10 +526,6 @@ object Flags { val DeferredOrLazyOrMethod: FlagSet = Deferred | Lazy | Method val DeferredOrTermParamOrAccessor: FlagSet = Deferred | ParamAccessor | TermParam // term symbols without right-hand sides val DeferredOrTypeParam: FlagSet = Deferred | TypeParam // type symbols without right-hand sides - val DelegateOrGiven: FlagSet = Delegate | Given - val DelegateOrGivenOrImplicit: FlagSet = Delegate | Given | Implicit - val DelegateOrGivenOrImplicitVal: FlagSet = DelegateOrGivenOrImplicit.toTermFlags - val DelegateOrImplicit: FlagSet = Delegate | Implicit val EnumValue: FlagSet = Enum | JavaStatic | StableRealizable // A Scala enum value val StableOrErased: FlagSet = Erased | StableRealizable // Assumed to be pure val ExtensionMethod: FlagSet = Extension | Method @@ -540,6 +534,7 @@ object Flags { val EffectivelyFinalFlags: FlagSet = Final | Private val FinalOrSealed: FlagSet = Final | Sealed val GivenOrImplicit: FlagSet = Given | Implicit + val GivenOrImplicitVal: FlagSet = GivenOrImplicit.toTermFlags val InlineOrProxy: FlagSet = Inline | InlineProxy // An inline method or inline argument proxy */ val InlineMethod: FlagSet = Inline | Method val InlineParam: FlagSet = Inline | Param @@ -570,7 +565,7 @@ object Flags { val Scala2Trait: FlagSet = Scala2x | Trait val SyntheticArtifact: FlagSet = Synthetic | Artifact val SyntheticCase: FlagSet = Synthetic | Case - val SyntheticDelegateMethod: FlagSet = Synthetic | Delegate | Method + val SyntheticGivenMethod: FlagSet = Synthetic | Given | Method val SyntheticModule: FlagSet = Synthetic | Module val SyntheticOpaque: FlagSet = Synthetic | Opaque val SyntheticTermParam: FlagSet = Synthetic | TermParam diff --git a/compiler/src/dotty/tools/dotc/core/Scopes.scala b/compiler/src/dotty/tools/dotc/core/Scopes.scala index e9071a94957f..e00192938e17 100644 --- a/compiler/src/dotty/tools/dotc/core/Scopes.scala +++ b/compiler/src/dotty/tools/dotc/core/Scopes.scala @@ -409,7 +409,7 @@ object Scopes { var irefs = new mutable.ListBuffer[TermRef] var e = lastEntry while (e ne null) { - if (e.sym.isOneOf(DelegateOrGivenOrImplicit)) { + if (e.sym.isOneOf(GivenOrImplicit)) { val d = e.sym.denot irefs += TermRef(NoPrefix, d.symbol.asTerm).withDenot(d) } diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 045a4f2eb365..b40468716616 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1980,7 +1980,7 @@ object SymDenotations { if (keepOnly eq implicitFilter) if (this.is(Package)) Iterator.empty // implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation` - else info.decls.iterator.filter(_.isOneOf(DelegateOrGivenOrImplicit)) + else info.decls.iterator.filter(_.isOneOf(GivenOrImplicit)) else info.decls.iterator for (sym <- ownSyms) maybeAdd(sym.name) names diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index ce249a40c7a2..b7c205a0c6cf 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -142,7 +142,7 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError { } } // Give up and give generic errors. - else if (cycleSym.isOneOf(DelegateOrGivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm) + else if (cycleSym.isOneOf(GivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm) CyclicReferenceInvolvingImplicit(cycleSym) else CyclicReferenceInvolving(denot) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index eb22e1bb682d..802aad722f69 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -789,12 +789,12 @@ object Types { } /** The set of implicit term members of this type - * @param kind A subset of {Implicit, Delegate} that specifies what kind of implicit should + * @param kind A subset of {Implicit, Given} that specifies what kind of implicit should * be returned */ final def implicitMembers(kind: FlagSet)(implicit ctx: Context): List[TermRef] = track("implicitMembers") { memberDenots(implicitFilter, - (name, buf) => buf ++= member(name).altsWith(_.isOneOf(DelegateOrGivenOrImplicitVal & kind))) + (name, buf) => buf ++= member(name).altsWith(_.isOneOf(GivenOrImplicitVal & kind))) .toList.map(d => TermRef(this, d.symbol.asTerm)) } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala index cf4718fe3961..607c5d6c46ec 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala @@ -57,7 +57,7 @@ Standard-Section: "ASTs" TopLevelStat* Stat = Term ValOrDefDef TYPEDEF Length NameRef (type_Term | Template) Modifier* -- modifiers type name (= type | bounds) | moifiers class name template - IMPORT Length [IMPLIED] qual_Term Selector* -- import implied? qual selectors + IMPORT Length [GIVEN] qual_Term Selector* -- import given? qual selectors ValOrDefDef = VALDEF Length NameRef type_Term rhs_Term? Modifier* -- modifiers val name : type (= rhs)? DEFDEF Length NameRef TypeParam* Params* returnType_Term rhs_Term? Modifier* -- modifiers def name [typeparams] paramss : returnType (= rhs)? @@ -182,7 +182,7 @@ Standard-Section: "ASTs" TopLevelStat* SEALED -- sealed CASE -- case (for classes or objects) IMPLICIT -- implicit - IMPLIED -- implied + GIVEN -- given ERASED -- erased LAZY -- lazy OVERRIDE -- override @@ -206,7 +206,6 @@ Standard-Section: "ASTs" TopLevelStat* DEFAULTparameterized -- Method with default parameters (default arguments are separate methods with DEFAULTGETTER names) STABLE -- Method that is assumed to be stable, i.e. its applications are legal paths EXTENSION -- An extension method - GIVEN -- A new style implicit parameter, introduced with `given` PARAMsetter -- The setter part `x_=` of a var parameter `x` which itself is pickled as a PARAM EXPORTED -- An export forwarder Annotation @@ -249,7 +248,7 @@ Standard Section: "Comments" Comment* object TastyFormat { final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F) - val MajorVersion: Int = 15 + val MajorVersion: Int = 16 val MinorVersion: Int = 0 /** Tags used to serialize names */ @@ -328,9 +327,8 @@ object TastyFormat { final val OPAQUE = 35 final val EXTENSION = 36 final val GIVEN = 37 - final val IMPLIED = 38 - final val PARAMsetter = 39 - final val EXPORTED = 40 + final val PARAMsetter = 38 + final val EXPORTED = 39 // Cat. 2: tag Nat @@ -477,7 +475,7 @@ object TastyFormat { | SEALED | CASE | IMPLICIT - | IMPLIED + | GIVEN | ERASED | LAZY | OVERRIDE @@ -538,7 +536,6 @@ object TastyFormat { case SEALED => "SEALED" case CASE => "CASE" case IMPLICIT => "IMPLICIT" - case IMPLIED => "IMPLIED" case ERASED => "ERASED" case LAZY => "LAZY" case OVERRIDE => "OVERRIDE" diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 78549dd2c61b..1f62b948b0a1 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -528,10 +528,10 @@ class TreePickler(pickler: TastyPickler) { } pickleStats(tree.constr :: rest) } - case Import(importDelegate, expr, selectors) => + case Import(importGiven, expr, selectors) => writeByte(IMPORT) withLength { - if (importDelegate) writeByte(IMPLIED) + if (importGiven) writeByte(GIVEN) pickleTree(expr) pickleSelectors(selectors) } @@ -648,7 +648,7 @@ class TreePickler(pickler: TastyPickler) { if (flags.is(Scala2x)) writeModTag(SCALA2X) if (isTerm) { if (flags.is(Implicit)) writeModTag(IMPLICIT) - if (flags.is(Delegate)) writeModTag(IMPLIED) + if (flags.is(Given)) writeModTag(GIVEN) if (flags.is(Erased)) writeModTag(ERASED) if (flags.is(Lazy, butNot = Module)) writeModTag(LAZY) if (flags.is(AbsOverride)) { writeModTag(ABSTRACT); writeModTag(OVERRIDE) } @@ -658,7 +658,6 @@ class TreePickler(pickler: TastyPickler) { if (flags.is(DefaultParameterized)) writeModTag(DEFAULTparameterized) if (flags.is(StableRealizable)) writeModTag(STABLE) if (flags.is(Extension)) writeModTag(EXTENSION) - if (flags.is(Given)) writeModTag(GIVEN) if (flags.is(ParamAccessor)) writeModTag(PARAMsetter) if (flags.is(Exported)) writeModTag(EXPORTED) assert(!(flags.is(Label))) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 06148af83101..92331ad80bf1 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -605,7 +605,6 @@ class TreeUnpickler(reader: TastyReader, case SEALED => addFlag(Sealed) case CASE => addFlag(Case) case IMPLICIT => addFlag(Implicit) - case IMPLIED => addFlag(Delegate) case ERASED => addFlag(Erased) case LAZY => addFlag(Lazy) case OVERRIDE => addFlag(Override) @@ -948,10 +947,10 @@ class TreeUnpickler(reader: TastyReader, assert(sourcePathAt(start).isEmpty) readByte() readEnd() - val importDelegate = nextByte == IMPLIED - if (importDelegate) readByte() + val importGiven = nextByte == GIVEN + if (importGiven) readByte() val expr = readTerm() - setSpan(start, Import(importDelegate, expr, readSelectors())) + setSpan(start, Import(importGiven, expr, readSelectors())) } def readSelectors()(implicit ctx: Context): List[untpd.Tree] = nextByte match { diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index a2dc5c7a0a82..34f01c86865f 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -1072,7 +1072,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val to = untpd.Ident(toName) if (toName.isEmpty) from else untpd.Thicket(from, untpd.Ident(toName)) }) - Import(importDelegate = false, expr, selectors) + Import(importGiven = false, expr, selectors) case TEMPLATEtree => setSym() diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index d88afe0a60d4..f1de66c5045d 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -121,7 +121,7 @@ object Completion { if (buffer.mode != Mode.None) { path match { case Select(qual, _) :: _ => buffer.addMemberCompletions(qual) - case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish delegate from non-delegate + case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish given from plain imports case (_: Thicket) :: Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) case _ => buffer.addScopeCompletions } diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index c38dabc0304e..170d236a5e16 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -600,7 +600,7 @@ object JavaParsers { } def importCompanionObject(cdef: TypeDef): Tree = - Import(importDelegate = false, Ident(cdef.name.toTermName).withSpan(NoSpan), Ident(nme.WILDCARD) :: Nil) + Import(importGiven = false, Ident(cdef.name.toTermName).withSpan(NoSpan), Ident(nme.WILDCARD) :: Nil) // Importing the companion object members cannot be done uncritically: see // ticket #2377 wherein a class contains two static inner classes, each of which @@ -662,7 +662,7 @@ object JavaParsers { // case nme.WILDCARD => Pair(ident, Ident(null) withPos Span(-1)) // case _ => Pair(ident, ident) // } - val imp = atSpan(start) { Import(importDelegate = false, qual, List(ident)) } + val imp = atSpan(start) { Import(importGiven = false, qual, List(ident)) } imp :: Nil } } diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 43bc7d50058b..9fb346246582 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1486,7 +1486,7 @@ object Parsers { case _ => } imods.mods match { - case (Mod.Implicit() | Mod.Delegate()) :: mods => markFirstIllegal(mods) + case (Mod.Implicit() | Mod.Given()) :: mods => markFirstIllegal(mods) case mods => markFirstIllegal(mods) } val result @ Match(t, cases) = @@ -2407,9 +2407,9 @@ object Parsers { */ def importClause(leading: Token, mkTree: ImportConstr): List[Tree] = { val offset = accept(leading) - val importDelegate = in.token == IMPLIED || in.token == GIVEN - if (importDelegate) in.nextToken() - commaSeparated(importExpr(importDelegate, mkTree)) match { + val importGiven = in.token == IMPLIED || in.token == GIVEN + if (importGiven) in.nextToken() + commaSeparated(importExpr(importGiven, mkTree)) match { case t :: rest => // The first import should start at the start offset of the keyword. val firstPos = @@ -2422,7 +2422,7 @@ object Parsers { /** ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) */ - def importExpr(importDelegate: Boolean, mkTree: ImportConstr): () => Tree = { + def importExpr(importGiven: Boolean, mkTree: ImportConstr): () => Tree = { /** ImportSelectors ::= `{' {ImportSelector `,'} FinalSelector ‘}’ * FinalSelector ::= ImportSelector @@ -2439,7 +2439,7 @@ object Parsers { else id } :: Nil case FOR => - if (!importDelegate) + if (!importGiven) syntaxError(em"`for` qualifier only allowed in `import given`") atSpan(in.skipToken()) { var t = infixType() @@ -2480,13 +2480,13 @@ object Parsers { } val handleImport: Tree => Tree = { tree: Tree => - if (in.token == USCORE) mkTree(importDelegate, tree, wildcardIdent() :: Nil) - else if (in.token == LBRACE) mkTree(importDelegate, tree, inBraces(importSelectors())) + if (in.token == USCORE) mkTree(importGiven, tree, wildcardIdent() :: Nil) + else if (in.token == LBRACE) mkTree(importGiven, tree, inBraces(importSelectors())) else tree } def derived(impExp: Tree, qual: Tree, selectors: List[Tree]) = - mkTree(importDelegate, qual, selectors).withSpan(impExp.span) + mkTree(importGiven, qual, selectors).withSpan(impExp.span) () => { val p = path(thisOK = false, handleImport) @@ -2494,10 +2494,10 @@ object Parsers { case _: Import | _: Export => p case sel @ Select(qual, name) => val selector = atSpan(pointOffset(sel)) { Ident(name) } - mkTree(importDelegate, qual, selector :: Nil).withSpan(sel.span) + mkTree(importGiven, qual, selector :: Nil).withSpan(sel.span) case t => accept(DOT) - mkTree(importDelegate, t, Ident(nme.WILDCARD) :: Nil) + mkTree(importGiven, t, Ident(nme.WILDCARD) :: Nil) } } } @@ -2761,7 +2761,7 @@ object Parsers { case ENUM => enumDef(start, posMods(start, mods | Enum)) case IMPLIED | GIVEN => - instanceDef(in.token == GIVEN, start, mods, atSpan(in.skipToken()) { Mod.Delegate() }) + instanceDef(in.token == GIVEN, start, mods, atSpan(in.skipToken()) { Mod.Given() }) case _ => syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition()) EmptyTree @@ -3174,7 +3174,7 @@ object Parsers { val mods = modifiers(closureMods) mods.mods match { case givenMod :: Nil if !isBindingIntro => - stats += instanceDef(true, start, EmptyModifiers, Mod.Delegate().withSpan(givenMod.span)) + stats += instanceDef(true, start, EmptyModifiers, Mod.Given().withSpan(givenMod.span)) case _ => stats += implicitClosure(in.offset, Location.InBlock, mods) } diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index d7ec980d15ef..108d1afa293b 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -825,7 +825,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { if (ctx.settings.YdebugFlags.value) AnyFlags else if (suppressKw) PrintableFlags(isType) &~ Private else PrintableFlags(isType) - if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= DelegateOrImplicit // drop implicit/delegate from classes + if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= GivenOrImplicit // drop implicit/given from classes val rawFlags = if (sym.exists) sym.flags else mods.flags if (rawFlags.is(Param)) flagMask = flagMask &~ Given val flags = rawFlags & flagMask diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 907c859e5c5c..5145f138da7f 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -585,7 +585,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder val abs = sym.is(Abstract) || sym.is(Deferred) || absOver val over = sym.is(Override) || absOver new api.Modifiers(abs, over, sym.is(Final), sym.is(Sealed), - sym.isOneOf(DelegateOrGivenOrImplicit), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor) + sym.isOneOf(GivenOrImplicit), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor) } def apiAnnotations(s: Symbol): List[api.Annotation] = { diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala index 83655185b515..5b34295e933a 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala @@ -339,10 +339,10 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT tree match { case Match(selector, _) => addPatMatDependency(selector.tpe) - case Import(importDelegate, expr, selectors) => + case Import(importGiven, expr, selectors) => def lookupImported(name: Name) = { val sym = expr.tpe.member(name).symbol - if (sym.is(Delegate) == importDelegate) sym else NoSymbol + if (sym.is(Given) == importGiven) sym else NoSymbol } def addImported(name: Name) = { // importing a name means importing both a term and a type (if they exist) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index a0b230b34799..da6a46f5019c 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -126,7 +126,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. case _ => None } - def Import_implied(self: Import): Boolean = self.importDelegate + def Import_implied(self: Import): Boolean = self.importGiven def Import_expr(self: Import)(implicit ctx: Context): Tree = self.expr def Import_selectors(self: Import)(implicit ctx: Context): List[ImportSelector] = self.selectors @@ -1696,7 +1696,6 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Flags_Case: Flags = core.Flags.Case def Flags_Implicit: Flags = core.Flags.Implicit def Flags_Given: Flags = core.Flags.Given - def Flags_Implied: Flags = core.Flags.Delegate def Flags_Erased: Flags = core.Flags.Erased def Flags_Lazy: Flags = core.Flags.Lazy def Flags_Override: Flags = core.Flags.Override diff --git a/compiler/src/dotty/tools/dotc/transform/CacheAliasImplicits.scala b/compiler/src/dotty/tools/dotc/transform/CacheAliasImplicits.scala index 14339b4aa384..29eae5107ec7 100644 --- a/compiler/src/dotty/tools/dotc/transform/CacheAliasImplicits.scala +++ b/compiler/src/dotty/tools/dotc/transform/CacheAliasImplicits.scala @@ -57,7 +57,7 @@ class CacheAliasImplicits extends MiniPhase with IdentityDenotTransformer { this override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = { val sym = tree.symbol sym.info match { - case ExprType(rhsType) if sym.is(Delegate, butNot = CacheAliasImplicits.NoCacheFlags) => + case ExprType(rhsType) if sym.is(Given, butNot = CacheAliasImplicits.NoCacheFlags) => // If rhs is a simple TermRef, leave a def. tree.rhs.tpe match { case TermRef(pre, _) => diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 20274e8f087d..61336256f20a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1320,7 +1320,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => * * T => R <:s U => R * - * Also: If a compared type refers to an delegate or its module class, use + * Also: If a compared type refers to a given or its module class, use * the intersection of its parent classes instead. */ def isAsSpecificValueType(tp1: Type, tp2: Type)(implicit ctx: Context) = @@ -1338,17 +1338,17 @@ trait Applications extends Compatibility { self: Typer with Dynamic => } } def prepare(tp: Type) = tp.stripTypeVar match { - case tp: NamedType if tp.symbol.is(Module) && tp.symbol.sourceModule.is(Delegate) => + case tp: NamedType if tp.symbol.is(Module) && tp.symbol.sourceModule.is(Given) => flip(tp.widen.widenToParents) case _ => flip(tp) } (prepare(tp1) relaxed_<:< prepare(tp2)) || viewExists(tp1, tp2) } - /** Widen the result type of synthetic delegate methods from the implementation class to the + /** Widen the result type of synthetic given methods from the implementation class to the * type that's implemented. Example * - * delegate I[X] for T { ... } + * given I[X] as T { ... } * * This desugars to * @@ -1356,21 +1356,21 @@ trait Applications extends Compatibility { self: Typer with Dynamic => * implicit def I[X]: I[X] = new I[X] * * To compare specificity we should compare with `T`, not with its implementation `I[X]`. - * No such widening is performed for delegate aliases, which are not synthetic. E.g. + * No such widening is performed for given aliases, which are not synthetic. E.g. * - * delegate J[X] for T = rhs + * given J[X] as T = rhs * - * already has the right result type `T`. Neither is widening performed for delegate + * already has the right result type `T`. Neither is widening performed for given * objects, since these are anyway taken to be more specific than methods * (by condition 3a above). */ - def widenDelegate(tp: Type, alt: TermRef): Type = tp match { + def widenGiven(tp: Type, alt: TermRef): Type = tp match { case mt: MethodType if mt.isImplicitMethod => - mt.derivedLambdaType(mt.paramNames, mt.paramInfos, widenDelegate(mt.resultType, alt)) + mt.derivedLambdaType(mt.paramNames, mt.paramInfos, widenGiven(mt.resultType, alt)) case pt: PolyType => - pt.derivedLambdaType(pt.paramNames, pt.paramInfos, widenDelegate(pt.resultType, alt)) + pt.derivedLambdaType(pt.paramNames, pt.paramInfos, widenGiven(pt.resultType, alt)) case _ => - if (alt.symbol.isAllOf(SyntheticDelegateMethod)) tp.widenToParents + if (alt.symbol.isAllOf(SyntheticGivenMethod)) tp.widenToParents else tp } @@ -1400,8 +1400,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic => if (winsType2) -1 else 0 } - val fullType1 = widenDelegate(alt1.widen, alt1) - val fullType2 = widenDelegate(alt2.widen, alt2) + val fullType1 = widenGiven(alt1.widen, alt1) + val fullType2 = widenGiven(alt2.widen, alt2) val strippedType1 = stripImplicit(fullType1) val strippedType2 = stripImplicit(fullType2) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 57279309e719..93b1754f5e7e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -409,7 +409,7 @@ object Checking { )) fail(ParamsNoInline(sym.owner)) - if (sym.isOneOf(DelegateOrImplicit)) { + if (sym.isOneOf(GivenOrImplicit)) { if (sym.owner.is(Package)) fail(TopLevelCantBeImplicit(sym)) if (sym.isType) @@ -1129,7 +1129,7 @@ trait Checking { val cases = for (stat <- impl.body if isCase(stat)) yield untpd.Ident(stat.symbol.name.toTermName) - val caseImport: Import = Import(importDelegate = false, ref(cdef.symbol), cases) + val caseImport: Import = Import(importGiven = false, ref(cdef.symbol), cases) val caseCtx = enumCtx.importContext(caseImport, caseImport.symbol) for (stat <- impl.body) checkCaseOrDefault(stat, caseCtx) case _ => diff --git a/compiler/src/dotty/tools/dotc/typer/Deriving.scala b/compiler/src/dotty/tools/dotc/typer/Deriving.scala index 03281d9cbca1..9e78304fa686 100644 --- a/compiler/src/dotty/tools/dotc/typer/Deriving.scala +++ b/compiler/src/dotty/tools/dotc/typer/Deriving.scala @@ -50,11 +50,11 @@ trait Deriving { this: Typer => if (ctx.denotNamed(instanceName).exists) ctx.error(i"duplicate typeclass derivation for $clsName", pos) else { - // If we set the Synthetic flag here widenDelegate will widen too far and the + // If we set the Synthetic flag here widenGiven will widen too far and the // derived instance will have too low a priority to be selected over a freshly // derived instance at the summoning site. synthetics += - ctx.newSymbol(ctx.owner, instanceName, Delegate | Method, info, coord = pos.span) + ctx.newSymbol(ctx.owner, instanceName, Given | Method, info, coord = pos.span) .entered } } diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index afec539ec79e..9c34f6c6c494 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -235,7 +235,7 @@ object Implicits { implicits.println(i"implicits of type $tp = ${companionRefs.toList}%, %") @threadUnsafe lazy val refs: List[ImplicitRef] = { val buf = new mutable.ListBuffer[TermRef] - for (companion <- companionRefs) buf ++= companion.implicitMembers(DelegateOrGivenOrImplicit) + for (companion <- companionRefs) buf ++= companion.implicitMembers(GivenOrImplicit) buf.toList } @@ -1206,7 +1206,7 @@ trait Implicits { self: Typer => case fail: SearchFailureType => def hiddenImplicitNote(s: SearchSuccess) = - em"\n\nNote: delegate ${s.ref.symbol.showLocated} was not considered because it was not imported with `import delegate`." + em"\n\nNote: given instance ${s.ref.symbol.showLocated} was not considered because it was not imported with `import given`." def FindHiddenImplicitsCtx(ctx: Context): Context = if (ctx == NoContext) ctx diff --git a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala index 84f091f26414..7b15990a0fdf 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -15,11 +15,11 @@ import Decorators._ object ImportInfo { /** The import info for a root import from given symbol `sym` */ - def rootImport(refFn: () => TermRef, importDelegate: Boolean = false)(implicit ctx: Context): ImportInfo = { + def rootImport(refFn: () => TermRef, importGiven: Boolean = false)(implicit ctx: Context): ImportInfo = { val selectors = untpd.Ident(nme.WILDCARD) :: Nil def expr(implicit ctx: Context) = tpd.Ident(refFn()) - def imp(implicit ctx: Context) = tpd.Import(importDelegate = importDelegate, expr, selectors) - new ImportInfo(imp.symbol, selectors, None, importDelegate = importDelegate, isRootImport = true) + def imp(implicit ctx: Context) = tpd.Import(importGiven = importGiven, expr, selectors) + new ImportInfo(imp.symbol, selectors, None, importGiven = importGiven, isRootImport = true) } } @@ -28,13 +28,13 @@ object ImportInfo { * @param selectors The selector clauses * @param symNameOpt Optionally, the name of the import symbol. None for root imports. * Defined for all explicit imports from ident or select nodes. - * @param importDelegate true if this is a delegate import + * @param importGiven true if this is a given import * @param isRootImport true if this is one of the implicit imports of scala, java.lang, * scala.Predef or dotty.DottyPredef in the start context, false otherwise. */ class ImportInfo(symf: given Context => Symbol, val selectors: List[untpd.Tree], symNameOpt: Option[TermName], - val importDelegate: Boolean, + val importGiven: Boolean, val isRootImport: Boolean = false) extends Showable { // Dotty deviation: we cannot use a lazy val here for the same reason @@ -114,7 +114,7 @@ class ImportInfo(symf: given Context => Symbol, val selectors: List[untpd.Tree], } private def implicitFlags(implicit ctx: Context) = - if (importDelegate || ctx.mode.is(Mode.FindHiddenImplicits)) DelegateOrGivenOrImplicit + if (importGiven || ctx.mode.is(Mode.FindHiddenImplicits)) GivenOrImplicit else Implicit /** The implicit references imported by this import clause */ diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 2da2d70e6433..bf282476389a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1158,7 +1158,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { case Some(x) => x > 1 || x == 1 && !boundSym.is(Method) case none => true } - } && !(boundSym.isAllOf(InlineMethod) && boundSym.isOneOf(DelegateOrImplicit)) + } && !(boundSym.isAllOf(InlineMethod) && boundSym.isOneOf(GivenOrImplicit)) val inlineBindings = new TreeMap { override def transform(t: Tree)(implicit ctx: Context) = t match { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 298de4e5fdba..13ac4fc40f9c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -342,7 +342,7 @@ class Namer { typer: Typer => tree match { case tree: TypeDef if tree.isClassDef => val name = checkNoConflict(tree.name).asTypeName - val flags = checkFlags(tree.mods.flags &~ DelegateOrImplicit) + val flags = checkFlags(tree.mods.flags &~ GivenOrImplicit) val cls = createOrRefine[ClassSymbol](tree, name, flags, ctx.owner, cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree), @@ -949,7 +949,7 @@ class Namer { typer: Typer => def whyNoForwarder(mbr: SingleDenotation): String = { val sym = mbr.symbol - if (sym.isOneOf(DelegateOrGivenOrImplicit) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a delegate" + if (sym.isOneOf(GivenOrImplicit) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a given instance" else if (!sym.isAccessibleFrom(path.tpe)) "is not accessible" else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) SKIP else if (cls.derivesFrom(sym.owner) && @@ -1107,7 +1107,7 @@ class Namer { typer: Typer => val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes if (ptype.typeParams.isEmpty) ptype else { - if (denot.is(ModuleClass) && denot.sourceModule.isOneOf(DelegateOrImplicit)) + if (denot.is(ModuleClass) && denot.sourceModule.isOneOf(GivenOrImplicit)) missingType(denot.symbol, "parent ")(creationContext) fullyDefinedType(typedAheadExpr(parent).tpe, "class parent", parent.span) } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 1cad2d388b65..00289794ee73 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -184,7 +184,7 @@ class Typer extends Namer val pre = imp.site var reqd = required var excl = EmptyFlags - if (imp.importDelegate) reqd |= Delegate else excl |= Delegate + if (imp.importGiven) reqd |= Given else excl |= Given var denot = pre.memberBasedOnFlags(name, reqd, excl).accessibleFrom(pre)(refctx) if (checkBounds && imp.wildcardBound.exists) denot = denot.filterWithPredicate(mbr => @@ -1423,7 +1423,7 @@ class Typer extends Namer if (body1.tpe.isInstanceOf[TermRef]) pt1 else body1.tpe.underlyingIfRepeated(isJava = false) val sym = ctx.newPatternBoundSymbol(tree.name, symTp, tree.span) - if (pt == defn.ImplicitScrutineeTypeRef) sym.setFlag(Delegate) + if (pt == defn.ImplicitScrutineeTypeRef) sym.setFlag(Given) if (ctx.mode.is(Mode.InPatternAlternative)) ctx.error(i"Illegal variable ${sym.name} in pattern alternative", tree.sourcePos) assignType(cpy.Bind(tree)(tree.name, body1), sym) @@ -1468,7 +1468,7 @@ class Typer extends Namer def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedValDef") { val ValDef(name, tpt, _) = vdef completeAnnotations(vdef, sym) - if (sym.isOneOf(DelegateOrImplicit)) checkImplicitConversionDefOK(sym) + if (sym.isOneOf(GivenOrImplicit)) checkImplicitConversionDefOK(sym) val tpt1 = checkSimpleKinded(typedType(tpt)) val rhs1 = vdef.rhs match { case rhs @ Ident(nme.WILDCARD) => rhs withType tpt1.tpe @@ -1513,7 +1513,7 @@ class Typer extends Namer val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef]) val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef]) vparamss1.foreach(checkNoForwardDependencies) - if (sym.isOneOf(DelegateOrImplicit)) checkImplicitConversionDefOK(sym) + if (sym.isOneOf(GivenOrImplicit)) checkImplicitConversionDefOK(sym) val tpt1 = checkSimpleKinded(typedType(tpt)) val rhsCtx = ctx.fresh @@ -1781,7 +1781,7 @@ class Typer extends Namer untpd.cpy.TypeBoundsTree(sel)(sel.lo, untpd.TypedSplice(typedType(tpt))) case sel => sel } - assignType(cpy.Import(imp)(imp.importDelegate, expr1, selectors1), sym) + assignType(cpy.Import(imp)(imp.importGiven, expr1, selectors1), sym) } def typedPackageDef(tree: untpd.PackageDef)(implicit ctx: Context): Tree = track("typedPackageDef") { diff --git a/compiler/src/dotty/tools/repl/ReplCompiler.scala b/compiler/src/dotty/tools/repl/ReplCompiler.scala index bdeaed7f6bb6..3e7445a71b24 100644 --- a/compiler/src/dotty/tools/repl/ReplCompiler.scala +++ b/compiler/src/dotty/tools/repl/ReplCompiler.scala @@ -48,9 +48,9 @@ class ReplCompiler extends Compiler { def importPreviousRun(id: Int)(implicit ctx: Context) = { // we first import the wrapper object id val path = nme.EMPTY_PACKAGE ++ "." ++ objectNames(id) - def importWrapper(c: Context, importDelegate: Boolean) = { + def importWrapper(c: Context, importGiven: Boolean) = { val importInfo = ImportInfo.rootImport(() => - c.requiredModuleRef(path), importDelegate) + c.requiredModuleRef(path), importGiven) c.fresh.setNewScope.setImportInfo(importInfo) } val ctx0 = importWrapper(importWrapper(ctx, false), true) diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 65d65629d8e8..ad9be3401bfc 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -129,7 +129,7 @@ class ReplCompilerTests extends ReplTest { } @Test def i5897 = - fromInitialState { implicit state => run("delegate for Int = 10") } + fromInitialState { implicit state => run("given as Int = 10") } .andThen { implicit state => assertEquals( "def Int_given: Int", @@ -151,7 +151,7 @@ class ReplCompilerTests extends ReplTest { | def (x: T) > (y: T) = compare(x, y) > 0 |} | - |delegate IntOrd for Ord[Int] { + |given IntOrd as Ord[Int] { | def compare(x: Int, y: Int) = | if (x < y) -1 else if (x > y) +1 else 0 |} diff --git a/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala index 30b5d6f627b2..45892061d0c3 100644 --- a/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala +++ b/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala @@ -14,7 +14,7 @@ class DocImplicitsPhase extends MiniPhase { override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = { if ( - tree.symbol.isOneOf(Flags.DelegateOrImplicit) && // has to have an implicit flag + tree.symbol.isOneOf(Flags.GivenOrImplicit) && // has to have an implicit flag tree.symbol.owner.isStaticOwner && // owner has to be static (e.g. top-level `object`) tree.vparamss.length > 0 && tree.vparamss(0).length == 1 // should only take one arg, since it has to be a transformation diff --git a/docs/docs/reference/changed-features/implicit-resolution.md b/docs/docs/reference/changed-features/implicit-resolution.md index 5e8de362f5c8..00ba944b3d6d 100644 --- a/docs/docs/reference/changed-features/implicit-resolution.md +++ b/docs/docs/reference/changed-features/implicit-resolution.md @@ -43,10 +43,10 @@ affect implicits on the language level. Example: package p - delegate a for A + given a as A object o { - delegate b for B + given b as B type C } diff --git a/docs/docs/reference/contextual/derivation.md b/docs/docs/reference/contextual/derivation.md index 779ef568ab1e..73f636cae16e 100644 --- a/docs/docs/reference/contextual/derivation.md +++ b/docs/docs/reference/contextual/derivation.md @@ -215,15 +215,15 @@ a mirror over that array, and finally uses the `reify` method in `Reflected` to ### How to Write Generic Typeclasses -Based on the machinery developed so far it becomes possible to define type classes generically. This means that the `derived` method will compute a type class delegate for any ADT that has a `Generic` delegate, recursively. +Based on the machinery developed so far it becomes possible to define type classes generically. This means that the `derived` method will compute a type class instance for any ADT that has a given `Generic` instance, recursively. The implementation of these methods typically uses three new type-level constructs in Dotty: inline methods, inline matches, and implicit matches. As an example, here is one possible implementation of a generic `Eql` type class, with explanations. Let's assume `Eql` is defined by the following trait: ```scala trait Eql[T] { def eql(x: T, y: T): Boolean } ``` -We need to implement a method `Eql.derived` that produces a delegate for `Eql[T]` provided -there exists a delegate for `Generic[T]`. Here's a possible solution: +We need to implement a method `Eql.derived` that produces a given instance for `Eql[T]` provided +a given `Generic[T]`. Here's a possible solution: ```scala inline def derived[T] given (ev: Generic[T]): Eql[T] = new Eql[T] { def eql(x: T, y: T): Boolean = { @@ -239,7 +239,7 @@ there exists a delegate for `Generic[T]`. Here's a possible solution: } } ``` -The implementation of the inline method `derived` creates a delegate for `Eql[T]` and implements its `eql` method. The right-hand side of `eql` mixes compile-time and runtime elements. In the code above, runtime elements are marked with a number in parentheses, i.e +The implementation of the inline method `derived` creates a given instance for `Eql[T]` and implements its `eql` method. The right-hand side of `eql` mixes compile-time and runtime elements. In the code above, runtime elements are marked with a number in parentheses, i.e `(1)`, `(2)`, `(3)`. Compile-time calls that expand to runtime code are marked with a number in brackets, i.e. `[4]`, `[5]`. The implementation of `eql` consists of the following steps. 1. Map the compared values `x` and `y` to their mirrors using the `reflect` method of the implicitly passed `Generic` `(1)`, `(2)`. @@ -310,16 +310,16 @@ The last, and in a sense most interesting part of the derivation is the comparis case ev: Eql[T] => ev.eql(x, y) // (15) case _ => - error("No `Eql` delegate was found for $T") + error("No `Eql` instance was found for $T") } ``` -`tryEql` is an inline method that takes an element type `T` and two element values of that type as arguments. It is defined using an `implicit match` that tries to find a delegate for `Eql[T]`. If a delegate `ev` is found, it proceeds by comparing the arguments using `ev.eql`. On the other hand, if no delegate is found -this signals a compilation error: the user tried a generic derivation of `Eql` for a class with an element type that does not have an `Eql` delegate itself. The error is signaled by +`tryEql` is an inline method that takes an element type `T` and two element values of that type as arguments. It is defined using an `implicit match` that tries to find a given instance for `Eql[T]`. If an instance `ev` is found, it proceeds by comparing the arguments using `ev.eql`. On the other hand, if no instance is found +this signals a compilation error: the user tried a generic derivation of `Eql` for a class with an element type that does not have an `Eql` instance itself. The error is signaled by calling the `error` method defined in `scala.compiletime`. **Note:** At the moment our error diagnostics for metaprogramming does not support yet interpolated string arguments for the `scala.compiletime.error` method that is called in the second case above. As an alternative, one can simply leave off the second case, then a missing typeclass would result in a "failure to reduce match" error. -**Example:** Here is a slightly polished and compacted version of the code that's generated by inline expansion for the derived `Eql` delegate for class `Tree`. +**Example:** Here is a slightly polished and compacted version of the code that's generated by inline expansion for the derived `Eql` instance for class `Tree`. ```scala given [T] as Eql[Tree[T]] where (elemEq: Eql[T]) { @@ -341,21 +341,21 @@ given [T] as Eql[Tree[T]] where (elemEq: Eql[T]) { } ``` -One important difference between this approach and Scala-2 typeclass derivation frameworks such as Shapeless or Magnolia is that no automatic attempt is made to generate typeclass delegates for elements recursively using the generic derivation framework. There must be a delegate for `Eql[T]` (which can of course be produced in turn using `Eql.derived`), or the compilation will fail. The advantage of this more restrictive approach to typeclass derivation is that it avoids uncontrolled transitive typeclass derivation by design. This keeps code sizes smaller, compile times lower, and is generally more predictable. +One important difference between this approach and Scala-2 typeclass derivation frameworks such as Shapeless or Magnolia is that no automatic attempt is made to generate typeclass instances for elements recursively using the generic derivation framework. There must be a given instance for `Eql[T]` (which can of course be produced in turn using `Eql.derived`), or the compilation will fail. The advantage of this more restrictive approach to typeclass derivation is that it avoids uncontrolled transitive typeclass derivation by design. This keeps code sizes smaller, compile times lower, and is generally more predictable. -### Deriving Delegates Elsewhere +### Deriving Instances Elsewhere -Sometimes one would like to derive a typeclass delegate for an ADT after the ADT is defined, without being able to change the code of the ADT itself. -To do this, simply define a delegate with the `derived` method of the typeclass as right-hand side. E.g, to implement `Ordering` for `Option`, define: +Sometimes one would like to derive a typeclass instance for an ADT after the ADT is defined, without being able to change the code of the ADT itself. +To do this, simply define an instance with the `derived` method of the typeclass as right-hand side. E.g, to implement `Ordering` for `Option`, define: ```scala -delegate [T: Ordering]: Ordering[Option[T]] = Ordering.derived +instance [T: Ordering] as Ordering[Option[T]] = Ordering.derived ``` Usually, the `Ordering.derived` clause has an implicit parameter of type `Generic[Option[T]]`. Since the `Option` trait has a `derives` clause, -the necessary delegate is already present in the companion object of `Option`. -If the ADT in question does not have a `derives` clause, a `Generic` delegate +the necessary instance is already present in the companion object of `Option`. +If the ADT in question does not have a `derives` clause, a `Generic` instance would still be synthesized by the compiler at the point where `derived` is called. -This is similar to the situation with type tags or class tags: If no delegate +This is similar to the situation with type tags or class tags: If no instance is found, the compiler will synthesize one. ### Syntax @@ -371,7 +371,7 @@ ConstrApps ::= ConstrApp {‘with’ ConstrApp} ### Discussion The typeclass derivation framework is quite small and low-level. There are essentially -two pieces of infrastructure in the compiler-generated `Generic` delegates: +two pieces of infrastructure in the compiler-generated `Generic` instances: - a type representing the shape of an ADT, - a way to map between ADT instances and generic mirrors. diff --git a/docs/docs/reference/features-classification.md b/docs/docs/reference/features-classification.md index 5be6f3972481..bd52e5e2e605 100644 --- a/docs/docs/reference/features-classification.md +++ b/docs/docs/reference/features-classification.md @@ -36,7 +36,7 @@ Since these are additions, there's generally no migration cost for old code. An These constructs replace existing constructs with the aim of making the language safer and simpler to use, and to promote uniformity in code style. - [Trait Parameters](other-new-features/trait-parameters.md) replace [early initializers](dropped-features/early-initializers.md) with a more generally useful construct. - - [Delegates](contextual/delegates.md) + - [Given Instances](contextual/delegates.md) replace implicit objects and defs, focussing on intent over mechanism. - [Given Clauses](contextual/given-clauses.md) replace implicit parameters, avoiding their ambiguities. - [Extension Methods](contextual/extension-methods.md) replace implicit classes with a clearer and simpler mechanism. @@ -71,7 +71,7 @@ For the next several versions, old features will remain available and deprecatio These constructs are restricted to make the language safer. - [Implicit Conversions](contextual/conversions.md): there is only one way to define implicit conversions instead of many, and potentially surprising implicit conversions require a language import. - - [Delegate Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible. + - [Given Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible. - [Type Projection](dropped-features/type-projection.md): only classes can be used as prefix `C` of a type projection `C#A`. Type projection on abstract types is no longer supported since it is unsound. - [Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`. - [@infix and @alpha](https://github.com/lampepfl/dotty/pull/5975) diff --git a/docs/docs/reference/metaprogramming/macros-spec.md b/docs/docs/reference/metaprogramming/macros-spec.md index bb1612018bfc..6864a187a0eb 100644 --- a/docs/docs/reference/metaprogramming/macros-spec.md +++ b/docs/docs/reference/metaprogramming/macros-spec.md @@ -190,7 +190,7 @@ With the right extractors, the "AsFunction" conversion that maps expressions over functions to functions over expressions can be implemented in user code: ```scala - delegate AsFunction1[T, U] for Conversion[Expr[T => U], Expr[T] => Expr[U]] { + given AsFunction1[T, U] as Conversion[Expr[T => U], Expr[T] => Expr[U]] { def apply(f: Expr[T => U]): Expr[T] => Expr[U] = (x: Expr[T]) => f match { case Lambda(g) => g(x) diff --git a/docs/docs/reference/metaprogramming/macros.md b/docs/docs/reference/metaprogramming/macros.md index b3d7c575e32f..0282f3931375 100644 --- a/docs/docs/reference/metaprogramming/macros.md +++ b/docs/docs/reference/metaprogramming/macros.md @@ -194,7 +194,7 @@ would be rewritten to def reflect[T: Type, U: Type](f: Expr[T] => Expr[U]): Expr[T => U] = '{ (x: ${ the[Type[T]] }) => ${ f('x) } } ``` -The `the` query succeeds because there is a delegate of +The `the` query succeeds because there is a given instance of type `Type[T]` available (namely the given parameter corresponding to the context bound `: Type`), and the reference to that value is phase-correct. If that was not the case, the phase inconsistency for @@ -224,7 +224,7 @@ Here’s a compiler that maps an expression given in the interpreted language to quoted Scala code of type `Expr[Int]`. The compiler takes an environment that maps variable names to Scala `Expr`s. ```scala - import delegate scala.quoted._ + import given scala.quoted._ def compile(e: Exp, env: Map[String, Expr[Int]]): Expr[Int] = e match { case Num(n) => @@ -251,15 +251,15 @@ The `toExpr` extension method is defined in package `quoted`: ```scala package quoted - delegate ExprOps { + given ExprOps { def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x) ... } ``` The extension says that values of types implementing the `Liftable` type class can be -converted ("lifted") to `Expr` values using `toExpr`, provided a delegate import of `scala.quoted._` is in scope. +converted ("lifted") to `Expr` values using `toExpr`, provided a given import of `scala.quoted._` is in scope. -Dotty comes with delegate definitions of `Liftable` for +Dotty comes with given instances of `Liftable` for several types including `Boolean`, `String`, and all primitive number types. For example, `Int` values can be converted to `Expr[Int]` values by wrapping the value in a `Literal` tree node. This makes use @@ -269,8 +269,8 @@ in the sense that they could all be defined in a user program without knowing anything about the representation of `Expr` trees. For instance, here is a possible instance of `Liftable[Boolean]`: ```scala - delegate for Liftable[Boolean] { - def toExpr(b: Boolean) = + given as Liftable[Boolean] { + def toExpr(b: Boolean) given QuoteContext: Expr[Boolean] = if (b) '{ true } else '{ false } } ``` @@ -278,8 +278,8 @@ Once we can lift bits, we can work our way up. For instance, here is a possible implementation of `Liftable[Int]` that does not use the underlying tree machinery: ```scala - delegate for Liftable[Int] { - def toExpr(n: Int) = n match { + given as Liftable[Int] { + def toExpr(n: Int) given QuoteContext: Expr[Int] = n match { case Int.MinValue => '{ Int.MinValue } case _ if n < 0 => '{ - ${ toExpr(-n) } } case 0 => '{ 0 } @@ -291,8 +291,8 @@ tree machinery: Since `Liftable` is a type class, its instances can be conditional. For example, a `List` is liftable if its element type is: ```scala - delegate [T: Liftable] for Liftable[List[T]] { - def toExpr(xs: List[T]) = xs match { + given [T: Liftable] as Liftable[List[T]] { + def toExpr(xs: List[T]) given QuoteContext: Expr[List[T]] = xs match { case head :: tail => '{ ${ toExpr(head) } :: ${ toExpr(tail) } } case Nil => '{ Nil: List[T] } } @@ -337,7 +337,7 @@ implicit search. For instance, to implement the[Type[List[T]]] ``` where `T` is not defined in the current stage, we construct the type constructor -of `List` applied to the splice of the result of searching for a delegate for `Type[T]`: +of `List` applied to the splice of the result of searching for a given instance for `Type[T]`: ```scala '[ List[ ${ the[Type[T]] } ] ] ``` diff --git a/docs/docs/reference/other-new-features/export.md b/docs/docs/reference/other-new-features/export.md index cefc43683dab..358eb41af04a 100644 --- a/docs/docs/reference/other-new-features/export.md +++ b/docs/docs/reference/other-new-features/export.md @@ -43,7 +43,7 @@ They can be accessed inside `Copier` as well as from outside: An export clause has the same format as an import clause. Its general form is: ```scala export path . { sel_1, ..., sel_n } - export delegate path . { sel_1, ..., sel_n } + export given path . { sel_1, ..., sel_n } ``` It consists of a qualifier expression `path`, which must be a stable identifier, followed by one or more selectors `sel_i` that identify what gets an alias. Selectors can be @@ -61,14 +61,14 @@ A member is _eligible_ if all of the following holds: - its owner is not a base class of the class(*) containing the export clause, - it is accessible at the export clause, - it is not a constructor, nor the (synthetic) class part of an object, - - it is delegate (or an old-style `implicit` value) - if and only if the export is tagged with `delegate`. + - it is a given instance (or an old-style `implicit` value) + if and only if the export is tagged with `given`. It is a compile-time error if a simple or renaming selector does not identify any eligible members. Type members are aliased by type definitions, and term members are aliased by method definitions. Export aliases copy the type and value parameters of the members they refer to. -Export aliases are always `final`. Aliases of delegates are again defines as delegates (and aliases of old-style implicits are `implicit`). There are no other modifiers that can be given to an alias. This has the following consequences for overriding: +Export aliases are always `final`. Aliases of given instances are again defined as givens (and aliases of old-style implicits are `implicit`). There are no other modifiers that can be given to an alias. This has the following consequences for overriding: - Export aliases cannot be overridden, since they are final. - Export aliases cannot override concrete members in base classes, since they are @@ -105,7 +105,7 @@ TemplateStat ::= ... | Export TopStat ::= ... | Export -Export ::= ‘export’ [‘delegate’] ImportExpr {‘,’ ImportExpr} +Export ::= ‘export’ [‘given’] ImportExpr {‘,’ ImportExpr} ``` ### Elaboration of Export Clauses diff --git a/docs/docs/reference/other-new-features/opaques.md b/docs/docs/reference/other-new-features/opaques.md index 2124763558b5..282c8456e7dd 100644 --- a/docs/docs/reference/other-new-features/opaques.md +++ b/docs/docs/reference/other-new-features/opaques.md @@ -20,7 +20,7 @@ object Logarithms { } // Extension methods define opaque types' public APIs - delegate LogarithmOps { + given LogarithmOps { def (x: Logarithm) toDouble: Double = math.exp(x) def (x: Logarithm) + (y: Logarithm): Logarithm = Logarithm(math.exp(x) + math.exp(y)) def (x: Logarithm) * (y: Logarithm): Logarithm = Logarithm(x + y) diff --git a/docs/docs/reference/overview.md b/docs/docs/reference/overview.md index 0c916e15f757..7365ac97c0e5 100644 --- a/docs/docs/reference/overview.md +++ b/docs/docs/reference/overview.md @@ -33,7 +33,7 @@ These new constructs directly model core features of DOT, higher-kinded types, a These constructs replace existing constructs with the aim of making the language safer and simpler to use, and to promote uniformity in code style. - [Trait Parameters](other-new-features/trait-parameters.md) replace [early initializers](dropped-features/early-initializers.md) with a more generally useful construct. - - [Delegates](contextual/delegates.md) + - [Given Instances](contextual/delegates.md) replace implicit objects and defs, focussing on intent over mechanism. - [Given Clauses](contextual/given-clauses.md) replace implicit parameters, avoiding their ambiguities. - [Extension Methods](contextual/extension-methods.md) replace implicit classes with a clearer and simpler mechanism. @@ -58,7 +58,7 @@ e a special case. There are currently no deprecation plans for value classes, si These constructs are restricted to make the language safer. - [Implicit Conversions](contextual/conversions.md): there is only one way to define implicit conversions instead of many, and potentially surprising implicit conversions require a language import. - - [Delegate Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible. + - [Given Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible. - [Type Projection](dropped-features/type-projection.md): only classes can be used as prefix `C` of a type projection `C#A`. Type projection on abstract types is no longer supported since it is unsound. - [Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`. - [@infix and @alpha](https://github.com/lampepfl/dotty/pull/5975) diff --git a/docs/sidebar.yml b/docs/sidebar.yml index c78c57766068..403657a7d7b7 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -43,13 +43,13 @@ sidebar: subsection: - title: Overview url: docs/reference/contextual/motivation.html - - title: Delegates + - title: Given Instances url: docs/reference/contextual/delegates.html - title: Given Clauses url: docs/reference/contextual/given-clauses.html - title: Context Bounds url: docs/reference/contextual/context-bounds.html - - title: Delegate Imports + - title: Given Imports url: docs/reference/contextual/import-delegate.html - title: Extension Methods url: docs/reference/contextual/extension-methods.html diff --git a/library/src/scala/Eql.scala b/library/src/scala/Eql.scala index ed62938267d3..341a291f6d77 100644 --- a/library/src/scala/Eql.scala +++ b/library/src/scala/Eql.scala @@ -16,7 +16,7 @@ object Eql { object derived extends Eql[Any, Any] /** A fall-back instance to compare values of any types. - * Even though this method is not declared a delegate, the compiler will + * Even though this method is not declared as given, the compiler will * synthesize implicit arguments as solutions to `Eql[T, U]` queries if * the rules of multiversal equality require it. */ diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index d26988d55008..be8035f9574d 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -17,15 +17,15 @@ trait Liftable[T] { */ object Liftable { - delegate Liftable_Boolean_delegate for Liftable[Boolean] = new PrimitiveLiftable - delegate Liftable_Byte_delegate for Liftable[Byte] = new PrimitiveLiftable - delegate Liftable_Short_delegate for Liftable[Short] = new PrimitiveLiftable - delegate Liftable_Int_delegate for Liftable[Int] = new PrimitiveLiftable - delegate Liftable_Long_delegate for Liftable[Long] = new PrimitiveLiftable - delegate Liftable_Float_delegate for Liftable[Float] = new PrimitiveLiftable - delegate Liftable_Double_delegate for Liftable[Double] = new PrimitiveLiftable - delegate Liftable_Char_delegate for Liftable[Char] = new PrimitiveLiftable - delegate Liftable_String_delegate for Liftable[String] = new PrimitiveLiftable + given Liftable_Boolean_delegate as Liftable[Boolean] = new PrimitiveLiftable + given Liftable_Byte_delegate as Liftable[Byte] = new PrimitiveLiftable + given Liftable_Short_delegate as Liftable[Short] = new PrimitiveLiftable + given Liftable_Int_delegate as Liftable[Int] = new PrimitiveLiftable + given Liftable_Long_delegate as Liftable[Long] = new PrimitiveLiftable + given Liftable_Float_delegate as Liftable[Float] = new PrimitiveLiftable + given Liftable_Double_delegate as Liftable[Double] = new PrimitiveLiftable + given Liftable_Char_delegate as Liftable[Char] = new PrimitiveLiftable + given Liftable_String_delegate as Liftable[String] = new PrimitiveLiftable private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] { /** Lift a primitive value `n` into `'{ n }` */ diff --git a/library/src/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala index 59d077cfaf08..12dcbb0706e0 100644 --- a/library/src/scala/quoted/Type.scala +++ b/library/src/scala/quoted/Type.scala @@ -17,15 +17,15 @@ package quoted { /** Some basic type tags, currently incomplete */ object Type { - delegate UnitTag for Type[Unit] = new TaggedType[Unit] - delegate BooleanTag for Type[Boolean] = new TaggedType[Boolean] - delegate ByteTag for Type[Byte] = new TaggedType[Byte] - delegate CharTag for Type[Char] = new TaggedType[Char] - delegate ShortTag for Type[Short] = new TaggedType[Short] - delegate IntTag for Type[Int] = new TaggedType[Int] - delegate LongTag for Type[Long] = new TaggedType[Long] - delegate FloatTag for Type[Float] = new TaggedType[Float] - delegate DoubleTag for Type[Double] = new TaggedType[Double] + given UnitTag as Type[Unit] = new TaggedType[Unit] + given BooleanTag as Type[Boolean] = new TaggedType[Boolean] + given ByteTag as Type[Byte] = new TaggedType[Byte] + given CharTag as Type[Char] = new TaggedType[Char] + given ShortTag as Type[Short] = new TaggedType[Short] + given IntTag as Type[Int] = new TaggedType[Int] + given LongTag as Type[Long] = new TaggedType[Long] + given FloatTag as Type[Float] = new TaggedType[Float] + given DoubleTag as Type[Double] = new TaggedType[Double] } } diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index ae24cfd49616..7c802744c5bd 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -1383,7 +1383,6 @@ trait Kernel { def Flags_Case: Flags def Flags_Implicit: Flags def Flags_Given: Flags - def Flags_Implied: Flags def Flags_Erased: Flags def Flags_Lazy: Flags def Flags_Override: Flags diff --git a/library/src/scala/tasty/reflect/TreeUtils.scala b/library/src/scala/tasty/reflect/TreeUtils.scala index 8a6ff0d46f7b..a86dd3e6c719 100644 --- a/library/src/scala/tasty/reflect/TreeUtils.scala +++ b/library/src/scala/tasty/reflect/TreeUtils.scala @@ -286,7 +286,7 @@ trait TreeUtils /** Bind the `rhs` to a `val` and use it in `body` */ def let(rhs: Term)(body: Ident => Term): Term = { import scala.quoted.QuoteContext - delegate for QuoteContext = new QuoteContext(this) + given as QuoteContext = new QuoteContext(this) type T // TODO probably it is better to use the Sealed contruct rather than let the user create their own existential type implicit val rhsTpe: quoted.Type[T] = rhs.tpe.seal.asInstanceOf[quoted.Type[T]] val rhsExpr = rhs.seal.cast[T] diff --git a/library/src/scalaShadowing/language.scala b/library/src/scalaShadowing/language.scala index c81e833b7f52..c3d521bc4708 100644 --- a/library/src/scalaShadowing/language.scala +++ b/library/src/scalaShadowing/language.scala @@ -107,7 +107,7 @@ object language { * }}} * * Implicit values of other types are not affected, and neither are implicit - * classes. In particular, delegates of the scala.Conversion class can be + * classes. In particular, given instances of the scala.Conversion class can be * defined without having to import the language feature. * * The language import is also required to enable _uses_ of implicit conversions @@ -119,13 +119,13 @@ object language { * class A * class B * object B { - * delegate a2b for Conversion[A, B] { ... } + * given a2b as Conversion[A, B] { ... } * } * object C { - * delegate b2a for Conversion[B, A] { ... } + * given b2a as Conversion[B, A] { ... } * } - * import delegate B._ - * import delegate C._ + * import given B._ + * import given C._ * val x: A = new B // language import required * val x: B = new A // no import necessary since a2b is co-defined with B * }}} diff --git a/tests/neg-custom-args/conditionalWarnings.scala b/tests/neg-custom-args/conditionalWarnings.scala index fc6290c93eb7..a1ad6f9cef33 100644 --- a/tests/neg-custom-args/conditionalWarnings.scala +++ b/tests/neg-custom-args/conditionalWarnings.scala @@ -3,7 +3,7 @@ object Test { @deprecated def foo = ??? - delegate for Conversion[String, Int] = _.length + given as Conversion[String, Int] = _.length foo // error diff --git a/tests/neg-custom-args/implicit-conversions.scala b/tests/neg-custom-args/implicit-conversions.scala index 5385b8cde5d9..ace8362cfb52 100644 --- a/tests/neg-custom-args/implicit-conversions.scala +++ b/tests/neg-custom-args/implicit-conversions.scala @@ -3,11 +3,11 @@ class B object A { - delegate for Conversion[A, B] { + given as Conversion[A, B] { def apply(x: A): B = ??? } - delegate for Conversion[B, A] { + given as Conversion[B, A] { def apply(x: B): A = ??? } } @@ -15,13 +15,13 @@ object A { class C object D { - delegate for Conversion[A, C] { + given as Conversion[A, C] { def apply(x: A): C = ??? } } object Test { - import delegate D._ + import given D._ val x1: A = new B val x2: B = new A // error under -Xfatal-warnings -feature diff --git a/tests/neg/cannot-reduce-delegate-match.scala b/tests/neg/cannot-reduce-delegate-match.scala index e4286d831b40..9c8a78fa9f58 100644 --- a/tests/neg/cannot-reduce-delegate-match.scala +++ b/tests/neg/cannot-reduce-delegate-match.scala @@ -6,7 +6,7 @@ object Test { } { - delegate for Int = 9 + given as Int = 9 bar() } diff --git a/tests/neg/derive-eq.scala b/tests/neg/derive-eq.scala index d1f46f8bd655..748741c59f8f 100644 --- a/tests/neg/derive-eq.scala +++ b/tests/neg/derive-eq.scala @@ -2,7 +2,7 @@ case class One() derives Eql case class Two() derives Eql -delegate for Eql[One, Two] = Eql.derived +given as Eql[One, Two] = Eql.derived enum Lst[T] derives Eql { case Cons(x: T, xs: Lst[T]) diff --git a/tests/neg/exports.check b/tests/neg/exports.check index 27ea9b0ea6a0..b29ff65e9c2a 100644 --- a/tests/neg/exports.check +++ b/tests/neg/exports.check @@ -11,12 +11,12 @@ 25 | export printUnit.bitmap // error: no eligible member | ^^^^^^ | no eligible member bitmap at this.printUnit - | this.printUnit.bitmap cannot be exported because it is a delegate --- Error: tests/neg/exports.scala:26:30 -------------------------------------------------------------------------------- -26 | export delegate printUnit.status // error: no eligible member - | ^^^^^^ - | no eligible member status at this.printUnit - | this.printUnit.status cannot be exported because it is not a delegate + | this.printUnit.bitmap cannot be exported because it is a given instance +-- Error: tests/neg/exports.scala:26:27 -------------------------------------------------------------------------------- +26 | export given printUnit.status // error: no eligible member + | ^^^^^^ + | no eligible member status at this.printUnit + | this.printUnit.status cannot be exported because it is not a given instance -- [E120] Duplicate Symbol Error: tests/neg/exports.scala:23:33 -------------------------------------------------------- 23 | export printUnit.{stat => _, _} // error: double definition | ^ diff --git a/tests/neg/exports.scala b/tests/neg/exports.scala index c1e144e0e51e..e94cb3a246ce 100644 --- a/tests/neg/exports.scala +++ b/tests/neg/exports.scala @@ -5,7 +5,7 @@ type PrinterType def print(bits: BitMap): Unit = ??? def status: List[String] = ??? - delegate bitmap for BitMap + given bitmap as BitMap } class Scanner { @@ -23,7 +23,7 @@ export printUnit.{stat => _, _} // error: double definition export scanUnit._ // error: double definition export printUnit.bitmap // error: no eligible member - export delegate printUnit.status // error: no eligible member + export given printUnit.status // error: no eligible member def status: List[String] = printUnit.status ++ scanUnit.status } diff --git a/tests/neg/extmethod-overload.scala b/tests/neg/extmethod-overload.scala index 0ea9f09121d0..ec53eaff7651 100644 --- a/tests/neg/extmethod-overload.scala +++ b/tests/neg/extmethod-overload.scala @@ -1,8 +1,8 @@ object Test { - delegate A { + given A { def (x: Int) |+| (y: Int) = x + y } - delegate B { + given B { def (x: Int) |+| (y: String) = x + y.length } assert((1 |+| 2) == 3) // error ambiguous diff --git a/tests/neg/i5455.scala b/tests/neg/i5455.scala index 5be4f337b87b..3da226778f18 100644 --- a/tests/neg/i5455.scala +++ b/tests/neg/i5455.scala @@ -11,7 +11,7 @@ object Library { def toInt(n: Nat): Int = n } - delegate NatOps { + given NatOps { def (x: Nat) * (y: Nat): Nat = x * y def (x: Nat) toInt: Int = x } diff --git a/tests/neg/implicit-params.scala b/tests/neg/implicit-params.scala index edaa13b3f09d..bb9ef7507698 100644 --- a/tests/neg/implicit-params.scala +++ b/tests/neg/implicit-params.scala @@ -11,8 +11,8 @@ object Test { def h(x: Int) given () = x // error - delegate C for C(11) - delegate D for D(11) + given C as C(11) + given D as D(11) f(1) f(1) given C diff --git a/tests/neg/implied-for.scala b/tests/neg/implied-for.scala index c7c3da59de76..3e7c6426ed76 100644 --- a/tests/neg/implied-for.scala +++ b/tests/neg/implied-for.scala @@ -3,13 +3,13 @@ class B extends T class C extends T object A { - delegate b for B - delegate c for C + given b as B + given c as C } object Test extends App { import A._ - import delegate A.{for B} + import given A.{for B} val x: B = b // OK println(c) // error: not found diff --git a/tests/neg/import-implied.scala b/tests/neg/import-implied.scala index b2e5e9b67b06..cd7ed5a69983 100644 --- a/tests/neg/import-implied.scala +++ b/tests/neg/import-implied.scala @@ -1,6 +1,6 @@ class TC object A { - delegate tc for TC + given tc as TC def foo given TC = () } object B { @@ -11,19 +11,19 @@ object B { } object C { import A._ - import delegate A.tc + import given A.tc foo // ok foo given tc // ok } object D { import A.foo - import delegate A._ + import given A._ foo // ok foo given tc // ok } object E { import A._ - import delegate A._ + import given A._ foo // ok foo given tc // ok } diff --git a/tests/neg/machine-state-encoding-with-implicit-match.scala b/tests/neg/machine-state-encoding-with-implicit-match.scala index d1d81b63ad3d..de56f3b1145e 100644 --- a/tests/neg/machine-state-encoding-with-implicit-match.scala +++ b/tests/neg/machine-state-encoding-with-implicit-match.scala @@ -7,13 +7,13 @@ final class Off extends State @implicitNotFound("State must be Off") class IsOff[S <: State] object IsOff { - delegate isOff for IsOff[Off] = new IsOff[Off] + given isOff as IsOff[Off] = new IsOff[Off] } @implicitNotFound("State must be On") class IsOn[S <: State] object IsOn { - delegate isOn for IsOn[On] = new IsOn[On] + given isOn as IsOn[On] = new IsOn[On] } class Machine[S <: State] { diff --git a/tests/neg/overloading-specifity.scala b/tests/neg/overloading-specifity.scala index 21b8c18645dd..840bc322d7b5 100644 --- a/tests/neg/overloading-specifity.scala +++ b/tests/neg/overloading-specifity.scala @@ -12,7 +12,7 @@ object Generic { object Test extends App { trait Context - //delegate ctx for Context + //given ctx as Context object a { def foo[T](implicit gen: Generic): Show[T] = new Show[T](1) diff --git a/tests/new/test.scala b/tests/new/test.scala index a380bf890f95..5ed1ce33c96f 100644 --- a/tests/new/test.scala +++ b/tests/new/test.scala @@ -4,10 +4,10 @@ trait T { object Test0 { trait A[T] - delegate a[T] for A[T] + given a[T] as A[T] class B[T] - delegate b[T] for B[T] + given b[T] as B[T] } class C extends T diff --git a/tests/pos-macros/i6803b/Macro_1.scala b/tests/pos-macros/i6803b/Macro_1.scala index bf0170d16bbe..137a9bb6674c 100644 --- a/tests/pos-macros/i6803b/Macro_1.scala +++ b/tests/pos-macros/i6803b/Macro_1.scala @@ -8,7 +8,7 @@ object AsObject { final class LineNo(val lineNo: Int) object LineNo { def unsafe(i: Int): LineNo = new LineNo(i) - inline delegate x for LineNo = ${impl} + inline given x as LineNo = ${impl} private def impl given (qctx: QuoteContext): Expr[LineNo] = { import qctx.tasty._ '{unsafe(${rootPosition.startLine})} diff --git a/tests/pos/combine.scala b/tests/pos/combine.scala index 6c64da676f0f..5887cfb359dd 100644 --- a/tests/pos/combine.scala +++ b/tests/pos/combine.scala @@ -1,8 +1,8 @@ trait Semigroup[A] { def (x: A) combine (y: A): A } -delegate for Semigroup[Int] = ??? -delegate [A, B] for Semigroup[(A, B)] given Semigroup[A], Semigroup[B] = ??? +given as Semigroup[Int] = ??? +given [A, B] as Semigroup[(A, B)] given Semigroup[A], Semigroup[B] = ??? object Test extends App { ((1, 1)) combine ((2, 2)) // doesn't compile ((1, 1): (Int, Int)) combine (2, 2) // compiles diff --git a/tests/pos/derive-eq.scala b/tests/pos/derive-eq.scala index a336aa3af870..379e068078c2 100644 --- a/tests/pos/derive-eq.scala +++ b/tests/pos/derive-eq.scala @@ -2,7 +2,7 @@ case class One() derives Eql case class Two() derives Eql -delegate for Eql[One, Two] = Eql.derived +given as Eql[One, Two] = Eql.derived enum Lst[T] derives Eql { case Cons(x: T, xs: Lst[T]) diff --git a/tests/pos/givenIn.scala b/tests/pos/givenIn.scala index 5a55303feddc..3957d181332d 100644 --- a/tests/pos/givenIn.scala +++ b/tests/pos/givenIn.scala @@ -3,7 +3,7 @@ object Test { class Context { inline def givenIn[T](op: => given Context => T) = { - delegate for Context = this + given as Context = this op } } diff --git a/tests/pos/i2774.scala b/tests/pos/i2774.scala index 82d6184f6e2b..d286ce593c61 100644 --- a/tests/pos/i2774.scala +++ b/tests/pos/i2774.scala @@ -2,9 +2,9 @@ object Test { trait T; trait Q val a: given T => given Q => Int = 1 - delegate for Q = new Q {} + given as Q = new Q {} val i1: Int = a given (new T{}) - delegate for T = new T {} + given as T = new T {} val i2: Int = a val i3: Int = a2 diff --git a/tests/pos/i4380b.scala b/tests/pos/i4380b.scala index a5d83e4f2829..4d3d5b1d00aa 100644 --- a/tests/pos/i4380b.scala +++ b/tests/pos/i4380b.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { - delegate for QuoteContext = ??? + given as QuoteContext = ??? def step(k: (String => Expr[Unit])): Expr[Unit] = '{} def meth(): Unit = '{ (i: Int) => ${ step(el => '{} ) } diff --git a/tests/pos/i5915.scala b/tests/pos/i5915.scala index 01bc2f689d9c..9822f4b93d76 100644 --- a/tests/pos/i5915.scala +++ b/tests/pos/i5915.scala @@ -2,8 +2,8 @@ trait RunDSL val rdsl = new RunDSL {} -delegate RunNNFExpr[B] for RunDSL = rdsl +given RunNNFExpr[B] as RunDSL = rdsl -delegate RunNNFImpl[B] for RunDSL { +given RunNNFImpl[B] as RunDSL { //override def runDSL(b: NNF[B]): B = b.terminal } \ No newline at end of file diff --git a/tests/pos/i5966.scala b/tests/pos/i5966.scala index 1a505b6edbfd..f8dec53d42b2 100644 --- a/tests/pos/i5966.scala +++ b/tests/pos/i5966.scala @@ -1,6 +1,6 @@ object Test { def foo = given (v: Int) => (x: Int) => v + x - delegate myInt for Int = 4 + given myInt as Int = 4 foo.apply(1) foo given 2 diff --git a/tests/pos/i6373.scala b/tests/pos/i6373.scala index 3975d1e4076e..18267431816a 100644 --- a/tests/pos/i6373.scala +++ b/tests/pos/i6373.scala @@ -6,7 +6,7 @@ object Test { inline def f(): Contextual[Boolean] = the[Context].t - delegate ctx for Context = new Context(true) + given ctx as Context = new Context(true) f() } diff --git a/tests/pos/implicit-conversion.scala b/tests/pos/implicit-conversion.scala index d7d2aa4d87ef..13bc63b5d031 100644 --- a/tests/pos/implicit-conversion.scala +++ b/tests/pos/implicit-conversion.scala @@ -1,6 +1,6 @@ object Test { // a problematic implicit conversion, should we flag it? - delegate for Conversion[String, Int] { + given as Conversion[String, Int] { def apply(x: String): Int = Integer.parseInt(toString) } } \ No newline at end of file diff --git a/tests/pos/implicit-scope.scala b/tests/pos/implicit-scope.scala index ca4524066f0b..2ab01de5cd4d 100644 --- a/tests/pos/implicit-scope.scala +++ b/tests/pos/implicit-scope.scala @@ -9,7 +9,7 @@ object A { type FlagSet = opaques.FlagSet def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits) - delegate FlagOps { + given FlagOps { def (xs: FlagSet) bits: Long = opaques.toBits(xs) def (xs: FlagSet) | (ys: FlagSet): FlagSet = FlagSet(xs.bits | ys.bits) } diff --git a/tests/pos/inlined-the.scala b/tests/pos/inlined-the.scala index 4f9791ecde0b..d25a0ff4a1f6 100644 --- a/tests/pos/inlined-the.scala +++ b/tests/pos/inlined-the.scala @@ -5,7 +5,7 @@ object Instances { class C { def f() = { locally { - delegate d[T] for D[T] + given d[T] as D[T] the[D[Int]] implicit val s: 3 = ??? val a: 3 = the[3] @@ -14,7 +14,7 @@ object Instances { } locally { - delegate d[T] for D[T] + given d[T] as D[T] the2[D[Int]] implicit val s: 3 = ??? val a: 3 = the2[3] diff --git a/tests/pos/multiversal.scala b/tests/pos/multiversal.scala index a7d5ec8d72b6..ac2a5958acec 100644 --- a/tests/pos/multiversal.scala +++ b/tests/pos/multiversal.scala @@ -1,7 +1,7 @@ object Test { import scala.Eql - delegate [X, Y] for Eql[List[X], List[Y]] given Eql[X, Y] = Eql.derived + given [X, Y] as Eql[List[X], List[Y]] given Eql[X, Y] = Eql.derived val b: Byte = 1 val c: Char = 2 diff --git a/tests/pos/postconditions.scala b/tests/pos/postconditions.scala index 31feca510f76..e4db602591d8 100644 --- a/tests/pos/postconditions.scala +++ b/tests/pos/postconditions.scala @@ -4,7 +4,7 @@ object PostConditions { def result[T] given (r: WrappedResult[T]): T = r def (x: T) ensuring [T](condition: given WrappedResult[T] => Boolean): T = { - delegate for WrappedResult[T] = x + given as WrappedResult[T] = x assert(condition) x } diff --git a/tests/pos/quote-1.scala b/tests/pos/quote-1.scala index f7c1fe6f0c22..d957cc081b58 100644 --- a/tests/pos/quote-1.scala +++ b/tests/pos/quote-1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { - delegate for QuoteContext = ??? + given as QuoteContext = ??? def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val y: $t = $x diff --git a/tests/pos/quote-lift.scala b/tests/pos/quote-lift.scala index b89369e6b9ac..3db9c5995df6 100644 --- a/tests/pos/quote-lift.scala +++ b/tests/pos/quote-lift.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { - delegate for QuoteContext = ??? + given as QuoteContext = ??? '{ ${implicitly[Liftable[Int]].toExpr(1)} } diff --git a/tests/pos/quote-liftable.scala b/tests/pos/quote-liftable.scala index 3467a983c326..9e60b1f45f33 100644 --- a/tests/pos/quote-liftable.scala +++ b/tests/pos/quote-liftable.scala @@ -2,7 +2,7 @@ import scala.quoted._ def test given QuoteContext = { - delegate for QuoteContext = ??? + given as QuoteContext = ??? implicit def IntIsLiftable: Liftable[Int] = new { def toExpr(n: Int) = n match { diff --git a/tests/pos/quoted-inline-quote.scala b/tests/pos/quoted-inline-quote.scala index 6d5b4c7072e5..165c1a90629a 100644 --- a/tests/pos/quoted-inline-quote.scala +++ b/tests/pos/quoted-inline-quote.scala @@ -2,6 +2,6 @@ import scala.quoted._ class Foo { inline def foo(x: Expr[String]) given QuoteContext = '{ println(${x}) } - delegate for QuoteContext = ??? + given as QuoteContext = ??? foo('{"abc"}) } diff --git a/tests/pos/reference/opaque.scala b/tests/pos/reference/opaque.scala index 35b36806e2a5..d69bb5b04b6c 100644 --- a/tests/pos/reference/opaque.scala +++ b/tests/pos/reference/opaque.scala @@ -12,7 +12,7 @@ object Logarithms { } // Extension methods define opaque types' public APIs - delegate LogarithmOps { + given LogarithmOps { def (x: Logarithm) toDouble: Double = math.exp(x) def (x: Logarithm) + (y: Logarithm): Logarithm = Logarithm(math.exp(x) + math.exp(y)) def (x: Logarithm) * (y: Logarithm): Logarithm = Logarithm(x + y) diff --git a/tests/pos/the-given.scala b/tests/pos/the-given.scala index e640fc1d596d..6f293aa63506 100644 --- a/tests/pos/the-given.scala +++ b/tests/pos/the-given.scala @@ -1,7 +1,7 @@ object Test { class Encoder { def apply(x: Int): Int = x } - delegate for Encoder + given as Encoder the[Encoder](2) diff --git a/tests/pos/the.scala b/tests/pos/the.scala index ca78bc904fb7..aeddc4dec24f 100644 --- a/tests/pos/the.scala +++ b/tests/pos/the.scala @@ -2,7 +2,7 @@ object Test { trait Foo { type T; val x: T } - delegate intFoo for Foo { + given intFoo as Foo { type T = Int val x = 3 } diff --git a/tests/run-macros/i6765-b/Macro_1.scala b/tests/run-macros/i6765-b/Macro_1.scala index b1977d73c388..b0cebf1dbb0b 100644 --- a/tests/run-macros/i6765-b/Macro_1.scala +++ b/tests/run-macros/i6765-b/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import delegate scala.quoted._ +import given scala.quoted._ inline def foo = ${fooImpl} diff --git a/tests/run-macros/i6765/Macro_1.scala b/tests/run-macros/i6765/Macro_1.scala index de5709fd9b05..267b1091bf82 100644 --- a/tests/run-macros/i6765/Macro_1.scala +++ b/tests/run-macros/i6765/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ -import delegate scala.quoted._ +import given scala.quoted._ -delegate for Toolbox = Toolbox.make(getClass.getClassLoader) +given as Toolbox = Toolbox.make(getClass.getClassLoader) inline def foo = ${fooImpl} diff --git a/tests/run-macros/tasty-macro-positions/quoted_1.scala b/tests/run-macros/tasty-macro-positions/quoted_1.scala index 39912aa373bf..b32977a22cbf 100644 --- a/tests/run-macros/tasty-macro-positions/quoted_1.scala +++ b/tests/run-macros/tasty-macro-positions/quoted_1.scala @@ -29,7 +29,7 @@ object Macros { } def posStr(qctx: QuoteContext)(pos: qctx.tasty.Position): Expr[String] = { - delegate for QuoteContext = qctx + given as QuoteContext = qctx import qctx.tasty._ s"${pos.sourceFile.jpath.getFileName.toString}:[${pos.start}..${pos.end}]".toExpr } diff --git a/tests/run-with-compiler/i6281.scala b/tests/run-with-compiler/i6281.scala index 1f329b658daf..b7290c96b17d 100644 --- a/tests/run-with-compiler/i6281.scala +++ b/tests/run-with-compiler/i6281.scala @@ -20,7 +20,7 @@ object Test extends App { def reify[A] given Type[A]: STM[A, L] => Expr[Stm[A, L]] def reflect[A] given Type[A]: Expr[Stm[A, L]] => STM[A, L] } - delegate empty for Effects[HNil] { + given empty as Effects[HNil] { def reify[A] given Type[A] = m => m def reflect[A] given Type[A] = m => m } diff --git a/tests/run/cochis-example.scala b/tests/run/cochis-example.scala index 5e8d542fc89e..15c4f059695a 100644 --- a/tests/run/cochis-example.scala +++ b/tests/run/cochis-example.scala @@ -1,11 +1,11 @@ import Predef.{$conforms => _} trait A { - delegate id[X] for (X => X) = x => x + given id[X] as (X => X) = x => x def trans[X](x: X) given (f: X => X) = f(x) // (2) } object Test extends A with App{ - delegate succ for (Int => Int) = x => x + 1 // (3) + given succ as (Int => Int) = x => x + 1 // (3) def bad[X](x: X): X = trans[X](x) // (4) unstable definition ! val v1 = bad [Int] (3) // (5) evaluates to 3 assert(v1 == 3) diff --git a/tests/run/derive-multi.scala b/tests/run/derive-multi.scala index a554235d8309..a8a9a70dc416 100644 --- a/tests/run/derive-multi.scala +++ b/tests/run/derive-multi.scala @@ -17,7 +17,7 @@ object B { case class One() derives A, B case class Two() derives A, B -delegate for B[One, Two] { +given as B[One, Two] { println("derived: B[One, Two]") } @@ -30,7 +30,7 @@ case class Triple[S, T, U] derives A, B object Test1 { import Lst._ - import delegate Lst._ + import given Lst._ implicitly[A] } diff --git a/tests/run/exports.scala b/tests/run/exports.scala index 7611e9fd1939..3c8fcc9c4432 100644 --- a/tests/run/exports.scala +++ b/tests/run/exports.scala @@ -7,7 +7,7 @@ object Test extends App { class Printer { def print() = println("printing") object cfg extends Config - delegate config for Config + given config as Config } class Scanner { @@ -19,7 +19,7 @@ object Test extends App { object Copier { val printer = new Printer export printer._ - export delegate printer._ + export given printer._ export Scanner.{scan => scanIt, _} val config2 = the[Config] diff --git a/tests/run/extmethod-overload.scala b/tests/run/extmethod-overload.scala index 638d8598fb5e..97e54e51676d 100644 --- a/tests/run/extmethod-overload.scala +++ b/tests/run/extmethod-overload.scala @@ -19,10 +19,10 @@ object Test extends App { assert(h(1)(1)(2) == 2) assert(h(1)(1)("two") == 3) - // Test with extension methods in delegate object + // Test with extension methods in given object object test1 { - delegate Foo { + given Foo { def (x: Int) |+| (y: Int) = x + y def (x: Int) |+| (y: String) = x + y.length @@ -52,7 +52,7 @@ object Test extends App { } test2 - // Test with delegate extension methods coming from base class + // Test with given extension methods coming from base class object test3 { class Foo { def (x: Int) |+| (y: Int) = x + y @@ -61,7 +61,7 @@ object Test extends App { def (xs: List[T]) +++ [T] (ys: List[T]): List[T] = xs ++ ys ++ ys def (xs: List[T]) +++ [T] (ys: Iterator[T]): List[T] = xs ++ ys ++ ys } - delegate Bar for Foo + given Bar as Foo assert((1 |+| 2) == 3) assert((1 |+| "2") == 2) @@ -72,9 +72,9 @@ object Test extends App { } test3 - // Test with delegate extension methods coming from delegate alias + // Test with extension methods coming from given alias object test4 { - delegate for test3.Foo = test3.Bar + given as test3.Foo = test3.Bar assert((1 |+| 2) == 3) assert((1 |+| "2") == 2) @@ -97,7 +97,7 @@ object Test extends App { def (x: Int) yy (y: Int) = x + y } - delegate { + given { def (x: Int) yy (y: Int) = x - y } diff --git a/tests/run/extmethods2.scala b/tests/run/extmethods2.scala index 211c5483c4e3..d2977a6a25e9 100644 --- a/tests/run/extmethods2.scala +++ b/tests/run/extmethods2.scala @@ -2,7 +2,7 @@ object Test extends App { class TC - delegate StringListOps given TC { + given StringListOps given TC { type T = List[String] def (x: T) foo (y: T) = (x ++ y, the[TC]) def (x: T) bar (y: Int) = (x(0)(y), the[TC]) diff --git a/tests/run/i2567.scala b/tests/run/i2567.scala index 8cf54d63bd07..a99f2df55d95 100644 --- a/tests/run/i2567.scala +++ b/tests/run/i2567.scala @@ -1,5 +1,5 @@ class TC -delegate tc for TC +given tc as TC class Foo given TC { println("hi") diff --git a/tests/run/implicit-alias.scala b/tests/run/implicit-alias.scala index fc128d537c15..166d0febef0d 100644 --- a/tests/run/implicit-alias.scala +++ b/tests/run/implicit-alias.scala @@ -5,13 +5,14 @@ object Test extends App { } class TC1 - delegate for TC1 + + given as TC1 class TV(val tc: TC) extends AnyVal trait C { val x: TC - delegate for TC = x + given as TC = x the[TC] the[TC] } @@ -21,7 +22,7 @@ object Test extends App { locally{ println("= new") - delegate t for TC = new TC + given t as TC = new TC the[TC] the[TC] } @@ -33,7 +34,7 @@ object Test extends App { locally{ println("= new VC") - delegate t for TV = new TV(new TC) + given t as TV = new TV(new TC) the[TV] the[TV] } @@ -45,21 +46,21 @@ object Test extends App { val tcc = new TCC locally { println("= x.y") - delegate t for TC = tcc.tc + given t as TC = tcc.tc the[TC] the[TC] } locally { println("with given") - delegate t for TC given TC1 = new TC + given t as TC given TC1 = new TC the[TC] the[TC] } locally { println("with type params") - delegate t[X] for TC = new TC + given t[X] as TC = new TC the[TC] the[TC] } diff --git a/tests/run/implicit-disambiguation.scala b/tests/run/implicit-disambiguation.scala index 856d115f0b78..f5ab370dc920 100644 --- a/tests/run/implicit-disambiguation.scala +++ b/tests/run/implicit-disambiguation.scala @@ -9,12 +9,12 @@ class C extends A { } object M { def f given B, C : String = { - delegate a for A = the[B] + given a as A = the[B] the[A].show } } object Test extends App { - delegate b for B - delegate c for C + given b as B + given c as C println(M.f) } diff --git a/tests/run/implicit-specifity.scala b/tests/run/implicit-specifity.scala index 9a10f9cb6b09..c59c7cadd11b 100644 --- a/tests/run/implicit-specifity.scala +++ b/tests/run/implicit-specifity.scala @@ -2,32 +2,32 @@ case class Show[T](val i: Int) object Show { def apply[T](implicit st: Show[T]): Int = st.i - delegate showInt for Show[Int] = new Show[Int](0) - delegate fallback[T] for Show[T] = new Show[T](1) + given showInt as Show[Int] = new Show[Int](0) + given fallback[T] as Show[T] = new Show[T](1) } class Generic object Generic { - delegate gen for Generic = new Generic - delegate showGen[T] for Show[T] given Generic = new Show[T](2) + given gen as Generic = new Generic + given showGen[T] as Show[T] given Generic = new Show[T](2) } class Generic2 object Generic2 { opaque type HiPriority = AnyRef - delegate showGen[T] for (Show[T] & HiPriority) = new Show[T](2).asInstanceOf + given showGen[T] as (Show[T] & HiPriority) = new Show[T](2).asInstanceOf } class SubGen extends Generic object SubGen { - delegate for SubGen + given as SubGen } object Contextual { trait Context - delegate ctx for Context - delegate showGen[T] for Show[T] given Generic = new Show[T](2) - delegate showGen[T] for Show[T] given Generic, Context = new Show[T](3) - delegate showGen[T] for Show[T] given SubGen = new Show[T](4) + given ctx as Context + given showGen[T] as Show[T] given Generic = new Show[T](2) + given showGen[T] as Show[T] given Generic, Context = new Show[T](3) + given showGen[T] as Show[T] given SubGen = new Show[T](4) } object Test extends App { diff --git a/tests/run/implied-divergence.scala b/tests/run/implied-divergence.scala index e99036cede11..0c1720a7e8f8 100644 --- a/tests/run/implied-divergence.scala +++ b/tests/run/implied-divergence.scala @@ -2,11 +2,11 @@ // recursions. case class E(x: E | Null) -delegate e for E(null) +given e as E(null) object Test extends App { - delegate f for E(e) given (e: E) + given f as E(e) given (e: E) assert(the[E].toString == "E(E(null))") diff --git a/tests/run/implied-for.scala b/tests/run/implied-for.scala index 1055d007bec3..b82332bb6a8f 100644 --- a/tests/run/implied-for.scala +++ b/tests/run/implied-for.scala @@ -6,15 +6,15 @@ object A { class C extends T class D[T] - delegate b for B - delegate c for C - delegate t for T - delegate d for D[Int] + given b as B + given c as C + given t as T + given d as D[Int] } object Test extends App { import A._ - import delegate A.{t, for B, D[_]} + import given A.{t, for B, D[_]} val x1: B = b val x2: T = t @@ -29,14 +29,14 @@ class ExecutionContext class Monoid[T] object Instances { - delegate intOrd for Ordering[Int] - delegate listOrd[T] for Ordering[List[T]] given Ordering[T] - delegate ec for ExecutionContext - delegate im for Monoid[Int] + given intOrd as Ordering[Int] + given listOrd[T] as Ordering[List[T]] given Ordering[T] + given ec as ExecutionContext + given im as Monoid[Int] } object Test2 { - import delegate Instances.{for Ordering[_], ExecutionContext} + import given Instances.{for Ordering[_], ExecutionContext} val x = intOrd val y = listOrd[Int] val z = ec @@ -46,7 +46,7 @@ object Test2 { } object Test3 { - import delegate Instances.{im, for Ordering[_]} + import given Instances.{im, for Ordering[_]} val x = intOrd val y = listOrd[Int] val z = im diff --git a/tests/run/implied-priority.scala b/tests/run/implied-priority.scala index 535c72f76df3..a3dad3134586 100644 --- a/tests/run/implied-priority.scala +++ b/tests/run/implied-priority.scala @@ -3,26 +3,26 @@ class E[T](val str: String) // The type for which we infer terms below -class Arg[T] // An argument that we use as a given for some delegate instances below +class Arg[T] // An argument that we use as a given for some given instances below /* First, two schemes that require a pre-planned architecture for how and - * where delegate instances are defined. + * where given instances are defined. * * Traditional scheme: prioritize with location in class hierarchy */ class LowPriorityImplicits { - delegate t1[T] for E[T]("low") + given t1[T] as E[T]("low") } object NormalImplicits extends LowPriorityImplicits { - delegate t2[T]for E[T]("norm") given Arg[T] + given t2[T]as E[T]("norm") given Arg[T] } def test1 = { - import delegate NormalImplicits._ + import given NormalImplicits._ assert(the[E[String]].str == "low") // No Arg available, so only t1 applies - { delegate for Arg[String] + { given as Arg[String] assert(the[E[String]].str == "norm") // Arg available, t2 takes priority } } @@ -31,28 +31,28 @@ def test1 = { */ object Priority { class Low - object Low { delegate for Low } + object Low { given as Low } class High extends Low - object High { delegate for High } + object High { given as High } } object Impl2 { - delegate t1[T] for E[T]("low") given Priority.Low - delegate t2[T] for E[T]("norm") given Priority.High given Arg[T] + given t1[T] as E[T]("low") given Priority.Low + given t2[T] as E[T]("norm") given Priority.High given Arg[T] } def test2 = { - import delegate Impl2._ + import given Impl2._ assert(the[E[String]].str == "low") // No Arg available, so only t1 applies - { delegate for Arg[String] + { given as Arg[String] assert(the[E[String]].str == "norm") // Arg available, t2 takes priority } } /* The remaining tests show how we can add an override of highest priority or - * a fallback of lowest priority to a group of existing delegate instances, without + * a fallback of lowest priority to a group of existing given instances, without * needing to change the location or definition of those instances. * * First, consider the problem how to define an override of highest priority. @@ -60,49 +60,49 @@ def test2 = { * an alternative without implicit arguments would override all of them. */ object Impl2a { - delegate t3[T] for E[T]("hi") + given t3[T] as E[T]("hi") } def test2a = { - import delegate Impl2._ - import delegate Impl2a._ + import given Impl2._ + import given Impl2a._ - delegate for Arg[String] + given as Arg[String] assert(the[E[String]].str == "hi") } /* If that solution is not applicable, we can define an override by refining the - * result type of the delegate instance, e.g. like this: + * result type of the given instance, e.g. like this: */ object Impl3 { - delegate t1[T] for E[T]("low") + given t1[T] as E[T]("low") } object Override { trait HighestPriority // A marker trait to indicate a higher priority - delegate over[T] for E[T]("hi"), HighestPriority + given over[T] as E[T]("hi"), HighestPriority } def test3 = { - import delegate Impl3._ + import given Impl3._ assert(the[E[String]].str == "low") // only t1 is available - { import delegate Override._ - import delegate Impl3._ + { import given Override._ + import given Impl3._ assert(the[E[String]].str == "hi") // `over` takes priority since its result type is a subtype of t1's. } } /* Now consider the dual problem: How to install a fallback with lower priority than existing - * delegate instances that kicks in when none of the other instances are applicable. + * given instances that kicks in when none of the other instances are applicable. * We get there in two stages. The first stage is by defining an explicit `withFallback` method * that takes the right implicit and returns it. This can be achieved using an implicit parameter * with a default argument. */ object Impl4 { - delegate t1 for E[String]("string") - delegate t2[T] for E[T]("generic") given Arg[T] + given t1 as E[String]("string") + given t2[T] as E[T]("generic") given Arg[T] } object fallback4 { @@ -110,12 +110,12 @@ object fallback4 { } def test4 = { - import delegate Impl4._ + import given Impl4._ import fallback4._ assert(withFallback[String].str == "string") // t1 is applicable assert(withFallback[Int].str == "fallback") // No applicable instances, pick the default - { delegate for Arg[Int] + { given as Arg[Int] assert(withFallback[Int].str == "generic") // t2 is applicable } } @@ -133,19 +133,19 @@ object HigherPriority { } object fallback5 { - delegate [T] for (E[T] & HigherPriority.Type) given (ev: E[T] = new E[T]("fallback")) = HigherPriority.inject(ev) + given [T] as (E[T] & HigherPriority.Type) given (ev: E[T] = new E[T]("fallback")) = HigherPriority.inject(ev) } def test5 = { - import delegate Impl4._ - import delegate fallback5._ + import given Impl4._ + import given fallback5._ - // All inferred terms go through the delegate instance in fallback5. + // All inferred terms go through the given instance in fallback5. // They differ in what implicit argument is synthesized for that instance. assert(the[E[String]].str == "string") // t1 is applicable assert(the[E[Int]].str == "fallback") // No applicable instances, pick the default - { delegate for Arg[Int] + { given as Arg[Int] assert(the[E[Int]].str == "generic") // t2 is applicable } } diff --git a/tests/run/implied-specifity-2.scala b/tests/run/implied-specifity-2.scala index fcc5edea4336..98cd01ed6c87 100644 --- a/tests/run/implied-specifity-2.scala +++ b/tests/run/implied-specifity-2.scala @@ -1,50 +1,51 @@ class Low object Low { - delegate low for Low + given low as Low } class Medium extends Low object Medium { - delegate medium for Medium + given medium as Medium } class High extends Medium object High { - delegate high for High + given high as High } class Foo[T](val i: Int) object Foo { def apply[T] given (fooT: Foo[T]): Int = fooT.i - delegate foo[T] for Foo[T](0) given Low - delegate foobar[T] for Foo[Bar[T]](1) given Low - delegate foobarbaz for Foo[Bar[Baz]](2) given Low + given foo[T] as Foo[T](0) given Low + given foobar[T] as Foo[Bar[T]](1) given Low + given foobarbaz as Foo[Bar[Baz]](2) given Low } class Bar[T] object Bar { - delegate foobar[T] for Foo[Bar[T]](3) given Medium - delegate foobarbaz for Foo[Bar[Baz]](4) given Medium + given foobar[T] as Foo[Bar[T]](3) given Medium + given foobarbaz as Foo[Bar[Baz]](4) given Medium } class Baz object Baz { - delegate baz for Foo[Bar[Baz]](5) given High + given baz as Foo[Bar[Baz]](5) given High } class Arg -delegate for Arg + +given as Arg class Bam(val str: String) -delegate lo for Bam("lo") given Low -delegate hi for Bam("hi") given High given Arg +given lo as Bam("lo") given Low +given hi as Bam("hi") given High given Arg class Bam2(val str: String) -delegate lo2 for Bam2("lo") given Low -delegate mid2 for Bam2("mid") given High given Arg -delegate hi2 for Bam2("hi") +given lo2 as Bam2("lo") given Low +given mid2 as Bam2("mid") given High given Arg +given hi2 as Bam2("hi") class Arg2 class Red(val str: String) -delegate normal for Red("normal") given Arg2 -delegate reduced for Red("reduced") given (ev: Arg2 | Low) +given normal as Red("normal") given Arg2 +given reduced as Red("reduced") given (ev: Arg2 | Low) object Test extends App { assert(Foo[Int] == 0) @@ -54,7 +55,7 @@ object Test extends App { assert(the[Bam2].str == "hi") assert(the[Red].str == "reduced") - { delegate for Arg2 + { given as Arg2 assert(the[Red].str == "normal") } } \ No newline at end of file diff --git a/tests/run/instances-anonymous.scala b/tests/run/instances-anonymous.scala index 469bd8ca2de3..53a43ec041b3 100644 --- a/tests/run/instances-anonymous.scala +++ b/tests/run/instances-anonymous.scala @@ -8,7 +8,7 @@ object Test extends App { case class Circle(x: Double, y: Double, radius: Double) - delegate { + given { def (c: Circle) circumference: Double = c.radius * math.Pi * 2 } @@ -16,7 +16,7 @@ object Test extends App { println(circle.circumference) - delegate { + given { def (xs: Seq[String]) longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) @@ -25,13 +25,13 @@ object Test extends App { val names = List("hi", "hello", "world") assert(names.longestStrings == List("hello", "world")) - delegate { + given { def (xs: Seq[T]) second[T] = xs.tail.head } assert(names.longestStrings.second == "world") - delegate { + given { def (xs: List[List[T]]) flattened[T] = xs.foldLeft[List[T]](Nil)(_ ++ _) } @@ -45,7 +45,7 @@ object Test extends App { def unit: T } - delegate for Monoid[String] { + given as Monoid[String] { def (x: String) combine (y: String): String = x.concat(y) def unit: String = "" } @@ -63,13 +63,13 @@ object Test extends App { val minimum: T } - delegate for Ord[Int] { + given as Ord[Int] { def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 val minimum = Int.MinValue } - delegate [T: Ord] for Ord[List[T]] { + given [T: Ord] as Ord[List[T]] { def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -101,14 +101,14 @@ object Test extends App { def pure[A](x: A): F[A] } - delegate for Monad[List] { + given as Monad[List] { def (xs: List[A]) flatMap[A, B] (f: A => List[B]): List[B] = xs.flatMap(f) def pure[A](x: A): List[A] = List(x) } - delegate [Ctx] for Monad[[X] =>> Ctx => X] { + given [Ctx] as Monad[[X] =>> Ctx => X] { def (r: Ctx => A) flatMap[A, B] (f: A => Ctx => B): Ctx => B = ctx => f(r(ctx))(ctx) def pure[A](x: A): Ctx => A = diff --git a/tests/run/instances.scala b/tests/run/instances.scala index 587b27cac00b..759bcc99abd3 100644 --- a/tests/run/instances.scala +++ b/tests/run/instances.scala @@ -8,7 +8,7 @@ object Test extends App { case class Circle(x: Double, y: Double, radius: Double) - delegate CircleOps { + given CircleOps { def (c: Circle) circumference: Double = c.radius * math.Pi * 2 } @@ -16,7 +16,7 @@ object Test extends App { assert(circle.circumference == CircleOps.circumference(circle)) - delegate StringOps { + given StringOps { def (xs: Seq[String]) longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) @@ -25,18 +25,18 @@ object Test extends App { val names = List("hi", "hello", "world") assert(names.longestStrings == List("hello", "world")) - delegate SeqOps { + given SeqOps { def (xs: Seq[T]) second[T] = xs.tail.head } assert(names.longestStrings.second == "world") - delegate ListListOps { + given ListListOps { def (xs: List[List[T]]) flattened[T] = xs.foldLeft[List[T]](Nil)(_ ++ _) } // A right associative op - delegate Prepend { + given Prepend { def (x: T) ::[T] (xs: Seq[T]) = x +: xs } val ss: Seq[Int] = List(1, 2, 3) @@ -53,7 +53,7 @@ object Test extends App { def unit: T } - delegate StringMonoid for Monoid[String] { + given StringMonoid as Monoid[String] { def (x: String) combine (y: String): String = x.concat(y) def unit: String = "" } @@ -71,13 +71,13 @@ object Test extends App { val minimum: T } - delegate for Ord[Int] { + given as Ord[Int] { def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 val minimum = Int.MinValue } - delegate ListOrd[T: Ord] for Ord[List[T]] { + given ListOrd[T: Ord] as Ord[List[T]] { def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -109,14 +109,14 @@ object Test extends App { def pure[A](x: A): F[A] } - delegate ListMonad for Monad[List] { + given ListMonad as Monad[List] { def (xs: List[A]) flatMap[A, B] (f: A => List[B]): List[B] = xs.flatMap(f) def pure[A](x: A): List[A] = List(x) } - delegate ReaderMonad[Ctx] for Monad[[X] =>> Ctx => X] { + given ReaderMonad[Ctx] as Monad[[X] =>> Ctx => X] { def (r: Ctx => A) flatMap[A, B] (f: A => Ctx => B): Ctx => B = ctx => f(r(ctx))(ctx) def pure[A](x: A): Ctx => A = diff --git a/tests/run/overloading-specifity.scala b/tests/run/overloading-specifity.scala index 9b4aa1495594..7a98ef27e9a1 100644 --- a/tests/run/overloading-specifity.scala +++ b/tests/run/overloading-specifity.scala @@ -10,7 +10,7 @@ object Generic { object Test extends App { trait Context - delegate ctx for Context + given ctx as Context object b { def foo[T](implicit gen: Generic): Show[T] = new Show[T](1) diff --git a/tests/run/tagless.scala b/tests/run/tagless.scala index 10403fbf87cf..217c13a1251a 100644 --- a/tests/run/tagless.scala +++ b/tests/run/tagless.scala @@ -40,13 +40,13 @@ object Test extends App { add(lit(8), neg(add(lit(1), lit(2)))) // Base operations as typeclasses - delegate for Exp[Int] { + given as Exp[Int] { def lit(i: Int): Int = i def neg(t: Int): Int = -t def add(l: Int, r: Int): Int = l + r } - delegate for Exp[String] { + given as Exp[String] { def lit(i: Int): String = i.toString def neg(t: String): String = s"(-$t)" def add(l: String, r: String): String = s"($l + $r)" @@ -67,11 +67,11 @@ object Test extends App { def tfm1[T: Exp : Mult] = add(lit(7), neg(mul(lit(1), lit(2)))) def tfm2[T: Exp : Mult] = mul(lit(7), tf1) - delegate for Mult[Int] { + given as Mult[Int] { def mul(l: Int, r: Int): Int = l * r } - delegate for Mult[String] { + given as Mult[String] { def mul(l: String, r: String): String = s"$l * $r" } @@ -87,7 +87,7 @@ object Test extends App { } import Tree._ - delegate for Exp[Tree], Mult[Tree] { + given as Exp[Tree], Mult[Tree] { def lit(i: Int): Tree = Node("Lit", Leaf(i.toString)) def neg(t: Tree): Tree = Node("Neg", t) def add(l: Tree, r: Tree): Tree = Node("Add", l , r) @@ -108,7 +108,7 @@ object Test extends App { private class Exc(msg: String) extends Exception(msg) def _throw(msg: String) given CanThrow: Nothing = throw new Exc(msg) def _try[T](op: Maybe[T])(handler: String => T): T = { - delegate for CanThrow + given as CanThrow try op catch { case ex: Exception => handler(ex.getMessage) @@ -153,7 +153,7 @@ object Test extends App { def value[T] given Exp[T]: T } - delegate for Exp[Wrapped] { + given as Exp[Wrapped] { def lit(i: Int) = new Wrapped { def value[T] given (e: Exp[T]): T = e.lit(i) } @@ -196,7 +196,7 @@ object Test extends App { // Added operation: negation pushdown enum NCtx { case Pos, Neg } - delegate [T] for Exp[NCtx => T] given (e: Exp[T]) { + given [T] as Exp[NCtx => T] given (e: Exp[T]) { import NCtx._ def lit(i: Int) = { case Pos => e.lit(i) @@ -216,7 +216,7 @@ object Test extends App { println(pushNeg(tf1[NCtx => String])) println(pushNeg(pushNeg(pushNeg(tf1))): String) - delegate [T] for Mult[NCtx => T] given (e: Mult[T]) { + given [T] as Mult[NCtx => T] given (e: Mult[T]) { import NCtx._ def mul(l: NCtx => T, r: NCtx => T): NCtx => T = { case Pos => e.mul(l(Pos), r(Pos)) @@ -230,7 +230,7 @@ object Test extends App { import IExp._ // Going from type class encoding to ADT encoding - delegate initialize for Exp[IExp] { + given initialize as Exp[IExp] { def lit(i: Int): IExp = Lit(i) def neg(t: IExp): IExp = Neg(t) def add(l: IExp, r: IExp): IExp = Add(l, r)