diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 40fc91f38ffa..d3e01c16ce55 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 40fc91f38ffa1b936f11e31b0cf794882dae9315 +Subproject commit d3e01c16ce553990f62b8b3e783a3fc0af20d290 diff --git a/community-build/community-projects/stdLib213 b/community-build/community-projects/stdLib213 index b7f2511439d1..902738911796 160000 --- a/community-build/community-projects/stdLib213 +++ b/community-build/community-projects/stdLib213 @@ -1 +1 @@ -Subproject commit b7f2511439d14b298e26147ac7aaa02eedb91c25 +Subproject commit 902738911796d1bde386aeea100221112eb241cb diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 1254bdd7c227..a9fff5f11c94 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -392,7 +392,7 @@ object Flags { /** Symbol is a Java default method */ final val DefaultMethod: FlagSet = termFlag(38, "") - final val Implied: FlagSet = commonFlag(39, "implied") + final val Implied: FlagSet = commonFlag(39, "delegate") /** Symbol is an enum class or enum case (if used with case) */ final val Enum: FlagSet = commonFlag(40, "") diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 869d2017f161..7dca85b59152 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 implied from non-implied + case Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) // TODO: distinguish delegate from non-delegate case (_: Thicket) :: Import(_, expr, _) :: _ => buffer.addMemberCompletions(expr) case _ => buffer.addScopeCompletions } diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 4f84231005a7..30658114e0b8 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1266,7 +1266,7 @@ object Parsers { * | SimpleExpr1 ArgumentExprs `=' Expr * | Expr2 * | [‘inline’] Expr2 `match' `{' CaseClauses `}' - * | `implied' `match' `{' ImplicitCaseClauses `}' + * | `delegate' `match' `{' ImplicitCaseClauses `}' * Bindings ::= `(' [Binding {`,' Binding}] `)' * Binding ::= (id | `_') [`:' Type] * Expr2 ::= PostfixExpr [Ascription] @@ -1470,7 +1470,7 @@ object Parsers { */ def impliedMatch(start: Int, imods: Modifiers) = { def markFirstIllegal(mods: List[Mod]) = mods match { - case mod :: _ => syntaxError(em"illegal modifier for implied match", mod.span) + case mod :: _ => syntaxError(em"illegal modifier for delegate match", mod.span) case _ => } imods.mods match { @@ -1485,7 +1485,7 @@ object Parsers { case pat => isVarPattern(pat) } if (!isImplicitPattern(pat)) - syntaxError(em"not a legal pattern for an implied match", pat.span) + syntaxError(em"not a legal pattern for a delegate match", pat.span) } result } @@ -2351,8 +2351,8 @@ object Parsers { type ImportConstr = (Boolean, Tree, List[Tree]) => Tree - /** Import ::= import [implied] [ImportExpr {`,' ImportExpr} - * Export ::= export [implied] [ImportExpr {`,' ImportExpr} + /** Import ::= import [delegate] [ImportExpr {`,' ImportExpr} + * Export ::= export [delegate] [ImportExpr {`,' ImportExpr} */ def importClause(leading: Token, mkTree: ImportConstr): List[Tree] = { val offset = accept(leading) @@ -2383,7 +2383,7 @@ object Parsers { wildcardIdent() :: Nil case FOR => if (!importImplied) - syntaxError(em"`for` qualifier only allowed in `import implied`") + syntaxError(em"`for` qualifier only allowed in `import delegate`") atSpan(in.skipToken()) { var t = infixType() while (in.token == COMMA) { diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index 08ae356c5759..6d8ee46a5d54 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -178,7 +178,7 @@ object Tokens extends TokensCommon { final val FORSOME = 61; enter(FORSOME, "forSome") // TODO: deprecate final val ENUM = 62; enter(ENUM, "enum") final val ERASED = 63; enter(ERASED, "erased") - final val IMPLIED = 64; enter(IMPLIED, "implied") + final val IMPLIED = 64; enter(IMPLIED, "delegate") final val GIVEN = 65; enter(GIVEN, "given") final val EXPORT = 66; enter(EXPORT, "export") final val MACRO = 67; enter(MACRO, "macro") // TODO: remove diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index cd7be73849a6..390ed5029122 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -509,7 +509,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case id :: Nil => toText(id) case _ => "{" ~ Text(selectors map selectorText, ", ") ~ "}" } - keywordText("import ") ~ (keywordText("implied ") provided importImplied) ~ + keywordText("import ") ~ (keywordText("delegate ") provided importImplied) ~ toTextLocal(expr) ~ "." ~ selectorsText case packageDef: PackageDef => packageDefText(packageDef) @@ -815,7 +815,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 &~= ImplicitOrImplied // drop implicit/implied from classes + if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= ImplicitOrImplied // drop implicit/delegate 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/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 5c6bcf63f6e2..b4398b171427 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1317,7 +1317,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => * * T => R <:s U => R * - * Also: If a compared type refers to an implied object or its module class, use + * Also: If a compared type refers to an delegate or its module class, use * the intersection of its parent classes instead. */ def isAsSpecificValueType(tp1: Type, tp2: Type)(implicit ctx: Context) = @@ -1342,22 +1342,22 @@ trait Applications extends Compatibility { self: Typer with Dynamic => (prepare(tp1) relaxed_<:< prepare(tp2)) || viewExists(tp1, tp2) } - /** Widen the result type of synthetic implied methods from the implementation class to the + /** Widen the result type of synthetic delegate methods from the implementation class to the * type that's implemented. Example * - * implied I[X] for T { ... } + * delegate I[X] for T { ... } * * This desugars to * * class I[X] extends T { ... } - * implied def I[X]: I[X] = new I[X] + * 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 implied aliases, which are not synthetic. E.g. + * No such widening is performed for delegate aliases, which are not synthetic. E.g. * - * implied J[X] for T = rhs + * delegate J[X] for T = rhs * - * already has the right result type `T`. Neither is widening performed for implied + * already has the right result type `T`. Neither is widening performed for delegate * objects, since these are anyway taken to be more specific than methods * (by condition 3a above). */ diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index fd07e0f254fe..99fb98fe6b61 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -1158,7 +1158,7 @@ trait Implicits { self: Typer => case fail: SearchFailureType => def hiddenImplicitNote(s: SearchSuccess) = - em"\n\nNote: implied instance ${s.ref.symbol.showLocated} was not considered because it was not imported with an `import implied`." + em"\n\nNote: delegate ${s.ref.symbol.showLocated} was not considered because it was not imported with `import delegate`." 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 d8421cebe32d..2474582ac199 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -28,7 +28,7 @@ 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 importImplied true if this is an implied import + * @param importImplied true if this is a delegate 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. */ diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index d6e34fcd5a4c..6fe1a26327f0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -720,9 +720,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { /** Reduce an inline match * @param mtch the match tree * @param scrutinee the scrutinee expression, assumed to be pure, or - * EmptyTree for an implied match + * EmptyTree for a delegate match * @param scrutType its fully defined type, or - * ImplicitScrutineeTypeRef for an implied match + * ImplicitScrutineeTypeRef for a delegate match * @param typer The current inline typer * @return optionally, if match can be reduced to a matching case: A pair of * bindings for all pattern-bound variables and the RHS of the case. @@ -1036,10 +1036,10 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { def patStr(cdef: untpd.CaseDef) = i"case ${cdef.pat}${guardStr(cdef.guard)}" val msg = if (tree.selector.isEmpty) - em"""cannot reduce implied match with + em"""cannot reduce delegate match with | patterns : ${tree.cases.map(patStr).mkString("\n ")}""" else - em"""cannot reduce inline match with + em"""cannot reduce delegate match with | scrutinee: $sel : ${selType} | patterns : ${tree.cases.map(patStr).mkString("\n ")}""" errorTree(tree, msg) diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 2b089c42761d..e45416e18fa9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -940,7 +940,7 @@ class Namer { typer: Typer => def whyNoForwarder(mbr: SingleDenotation): String = { val sym = mbr.symbol - if (sym.is(ImplicitOrImpliedOrGiven) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}implied" + if (sym.is(ImplicitOrImpliedOrGiven) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a delegate" 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) && diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 9dc5f128bfe9..29294dd68826 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1029,7 +1029,7 @@ class Typer extends Namer tree.selector match { case EmptyTree => if (tree.isInline) { - checkInInlineContext("implied match", tree.posd) + checkInInlineContext("delegate match", tree.posd) val cases1 = tree.cases.mapconserve { case cdef @ CaseDef(pat @ Typed(Ident(nme.WILDCARD), _), _, _) => // case _ : T --> case evidence$n : T diff --git a/compiler/src/dotty/tools/io/ZipArchive.scala b/compiler/src/dotty/tools/io/ZipArchive.scala index fa27ac4245cf..7efee7c4cc71 100644 --- a/compiler/src/dotty/tools/io/ZipArchive.scala +++ b/compiler/src/dotty/tools/io/ZipArchive.scala @@ -126,8 +126,8 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) { override def input: InputStream = { val zipFile = openZipFile() val entry = zipFile.getEntry(name) - val delegate = zipFile.getInputStream(entry) - new FilterInputStream(delegate) { + val `delegate` = zipFile.getInputStream(entry) + new FilterInputStream(`delegate`) { override def close(): Unit = { zipFile.close() } } } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 65f33caa106d..cc28d2deff2f 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("implied for Int = 10") } + fromInitialState { implicit state => run("delegate for Int = 10") } .andThen { implicit state => assertEquals( "def Int_instance: Int", @@ -151,7 +151,7 @@ class ReplCompilerTests extends ReplTest { | def (x: T) > (y: T) = compare(x, y) > 0 |} | - |implied IntOrd for Ord[Int] { + |delegate IntOrd for Ord[Int] { | def compare(x: Int, y: Int) = | if (x < y) -1 else if (x > y) +1 else 0 |} diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 9e55f0c4a0ac..e156394143fa 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -92,9 +92,9 @@ semi ::= ‘;’ | nl {nl} ### Regular keywords ``` -abstract case catch class def do else enum -erased extends false final finally for given if -implicit implied import lazy match new null object +abstract case catch class def delegate do else +enum export extends false final finally for given +if implicit import lazy match new null object package private protected override return super sealed then throw trait true try type val var while with yield @@ -143,7 +143,7 @@ Type ::= FunType | HkTypeParamClause ‘=>>’ Type TypeLambda(ps, t) | MatchType | InfixType -FunType ::= { 'erased' | 'given' } (MonoFunType | PolyFunType) +FunType ::= ['given'] (MonoFunType | PolyFunType) MonoFunType ::= FunArgTypes ‘=>’ Type Function(ts, t) PolyFunType :: = HKTypeParamClause '=>' Type PolyFunction(ps, t) FunArgTypes ::= InfixType @@ -298,8 +298,8 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] | ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’] | {ClsParamClause} {GivenClsParamClause} -ClsParamClause ::= [‘erased’] (‘(’ ClsParams ‘)’ -GivenClsParamClause::= ‘given’ [‘erased’] (‘(’ ClsParams ‘)’ | GivenTypes) +ClsParamClause ::= ‘(’ ClsParams ‘)’ +GivenClsParamClause::= ‘given’ (‘(’ ClsParams ‘)’ | GivenTypes) ClsParams ::= ClsParam {‘,’ ClsParam} ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param @@ -308,12 +308,12 @@ Param ::= id ‘:’ ParamType [‘=’ Expr] DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’] | {DefParamClause} {GivenParamClause} -DefParamClause ::= [‘erased’] (‘(’ DefParams ‘)’ -GivenParamClause ::= ‘given’ [‘erased’] (‘(’ DefParams ‘)’ | GivenTypes) +DefParamClause ::= ‘(’ DefParams ‘)’ +GivenParamClause ::= ‘given’ (‘(’ DefParams ‘)’ | GivenTypes) DefParams ::= DefParam {‘,’ DefParam} DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id. GivenTypes ::= AnnotType {‘,’ AnnotType} -ClosureMods ::= { ‘implicit’ | ‘erased’ | ‘given’} +ClosureMods ::= { ‘implicit’ | ‘given’} ``` ### Bindings and Imports @@ -331,20 +331,19 @@ LocalModifier ::= ‘abstract’ | ‘implicit’ | ‘lazy’ | ‘inline’ - | ‘erased’ AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier] AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’ Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args) -Import ::= ‘import’ [‘implied’] ImportExpr {‘,’ ImportExpr} +Import ::= ‘import’ [‘delegate’] ImportExpr {‘,’ ImportExpr} ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) Import(expr, sels) ImportSelectors ::= ‘{’ {ImportSelector ‘,’} FinalSelector ‘}’ FinalSelector ::= ImportSelector Ident(name) | ‘_’ Pair(id, id) | ‘for’ InfixType {‘,’ InfixType} TypeBoundsTree(EmptyTree, tpt) ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] -Export ::= ‘export’ [‘implied’] ImportExpr {‘,’ ImportExpr} +Export ::= ‘export’ [‘delegate’] ImportExpr {‘,’ ImportExpr} ``` ### Declarations and Definitions @@ -380,16 +379,15 @@ DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef | [‘case’] ‘object’ ObjectDef | ‘enum’ EnumDef - | ‘implied’ InstanceDef + | ‘delegate’ DelegateDef | Export ClassDef ::= id ClassConstr [Template] ClassDef(mods, name, tparams, templ) ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat ConstrMods ::= {Annotation} [AccessModifier] ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template) -InstanceDef ::= [id] [DefTypeParamClause] InstanceBody -InstanceParams ::= [DefTypeParamClause] {GivenParamClause} -InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody] +DelegateDef ::= [id] [DefTypeParamClause] DelegateBody +DelegateBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody] | ‘for’ Type {GivenParamClause} ‘=’ Expr Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats) InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}] diff --git a/docs/docs/reference/changed-features/implicit-resolution.md b/docs/docs/reference/changed-features/implicit-resolution.md index c68686290527..5e8de362f5c8 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 - implied a for A + delegate a for A object o { - implied b for B + delegate b for B type C } diff --git a/docs/docs/reference/contextual/context-bounds.md b/docs/docs/reference/contextual/context-bounds.md index f6420fecdc4e..2593bb355d43 100644 --- a/docs/docs/reference/contextual/context-bounds.md +++ b/docs/docs/reference/contextual/context-bounds.md @@ -5,11 +5,11 @@ title: "Context Bounds" ## Context Bounds -A context bound is a shorthand for expressing a common pattern of a context parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this: +A context bound is a shorthand for expressing the common pattern of an implicit parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this: ```scala def maximum[T: Ord](xs: List[T]): T = xs.reduceLeft(max) ``` -A bound like `: Ord` on a type parameter `T` of a method or class indicates a context parameter `given Ord[T]`. The context parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g., +A bound like `: Ord` on a type parameter `T` of a method or class indicates an implicit parameter `given Ord[T]`. The implicit parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g., ```scala def f[T: C1 : C2, U: C3](x: T) given (y: U, z: V): R ``` diff --git a/docs/docs/reference/contextual/conversions.md b/docs/docs/reference/contextual/conversions.md index 277a2a88a0af..802c27569a61 100644 --- a/docs/docs/reference/contextual/conversions.md +++ b/docs/docs/reference/contextual/conversions.md @@ -3,20 +3,20 @@ layout: doc-page title: "Implicit Conversions" --- -Implicit conversions are defined by implied instances of the `scala.Conversion` class. +Implicit conversions are defined by delegates for the `scala.Conversion` class. This class is defined in package `scala` as follows: ```scala abstract class Conversion[-T, +U] extends (T => U) ``` For example, here is an implicit conversion from `String` to `Token`: ```scala -implied for Conversion[String, Token] { +delegate for Conversion[String, Token] { def apply(str: String): Token = new KeyWord(str) } ``` -Using an implied alias instance this can be expressed more concisely as: +Using an alias delegate this can be expressed more concisely as: ```scala -implied for Conversion[String, Token] = new KeyWord(_) +delegate for Conversion[String, Token] = new KeyWord(_) ``` An implicit conversion is applied automatically by the compiler in three situations: @@ -25,11 +25,11 @@ An implicit conversion is applied automatically by the compiler in three situati 3. In an application `e.m(args)` with `e` of type `T`, if `T` does define some member(s) named `m`, but none of these members can be applied to the arguments `args`. -In the first case, the compiler looks for an implied instance of +In the first case, the compiler looks for a delegate for `scala.Conversion` that maps an argument of type `T` to type `S`. In the second and third -case, it looks for an instance of `scala.Conversion` that maps an argument of type `T` +case, it looks for a delegate for `scala.Conversion` that maps an argument of type `T` to a type that defines a member `m` which can be applied to `args` if present. -If such an instance `C` is found, the expression `e` is replaced by `C.apply(e)`. +If such a delegate `C` is found, the expression `e` is replaced by `C.apply(e)`. ## Examples @@ -37,7 +37,7 @@ If such an instance `C` is found, the expression `e` is replaced by `C.apply(e)` primitive number types to subclasses of `java.lang.Number`. For instance, the conversion from `Int` to `java.lang.Integer` can be defined as follows: ```scala -implied int2Integer for Conversion[Int, java.lang.Integer] = +delegate int2Integer for Conversion[Int, java.lang.Integer] = java.lang.Integer.valueOf(_) ``` @@ -59,9 +59,9 @@ object Completions { // // CompletionArg.fromStatusCode(statusCode) - implied fromString for Conversion[String, CompletionArg] = Error(_) - implied fromFuture for Conversion[Future[HttpResponse], CompletionArg] = Response(_) - implied fromStatusCode for Conversion[Future[StatusCode], CompletionArg] = Status(_) + delegate fromString for Conversion[String, CompletionArg] = Error(_) + delegate fromFuture for Conversion[Future[HttpResponse], CompletionArg] = Response(_) + delegate fromStatusCode for Conversion[Future[StatusCode], CompletionArg] = Status(_) } import CompletionArg._ diff --git a/docs/docs/reference/contextual/derivation.md b/docs/docs/reference/contextual/derivation.md index 7dfc425cb02d..0b3be9689149 100644 --- a/docs/docs/reference/contextual/derivation.md +++ b/docs/docs/reference/contextual/derivation.md @@ -3,18 +3,18 @@ layout: doc-page title: Typeclass Derivation --- -Typeclass derivation is a way to generate implied instances of certain type classes automatically or with minimal code hints. A type class in this sense is any trait or class with a type parameter that describes the type being operated on. Commonly used examples are `Eql`, `Ordering`, `Show`, or `Pickling`. Example: +Typeclass derivation is a way to generate delegates for certain type classes automatically or with minimal code hints. A type class in this sense is any trait or class with a type parameter that describes the type being operated on. Commonly used examples are `Eql`, `Ordering`, `Show`, or `Pickling`. Example: ```scala enum Tree[T] derives Eql, Ordering, Pickling { case Branch(left: Tree[T], right: Tree[T]) case Leaf(elem: T) } ``` -The `derives` clause generates implied instances of the `Eql`, `Ordering`, and `Pickling` traits in the companion object `Tree`: +The `derives` clause generates delegates for the `Eql`, `Ordering`, and `Pickling` traits in the companion object `Tree`: ```scala -implied [T: Eql] for Eql[Tree[T]] = Eql.derived -implied [T: Ordering] for Ordering[Tree[T]] = Ordering.derived -implied [T: Pickling] for Pickling[Tree[T]] = Pickling.derived +delegate [T: Eql] for Eql[Tree[T]] = Eql.derived +delegate [T: Ordering] for Ordering[Tree[T]] = Ordering.derived +delegate [T: Pickling] for Pickling[Tree[T]] = Pickling.derived ``` ### Deriving Types @@ -34,21 +34,27 @@ case class Some[T] extends Option[T] case object None extends Option[Nothing] ``` -The generated typeclass instances are placed in the companion objects `Labelled` and `Option`, respectively. +The generated typeclass delegates are placed in the companion objects `Labelled` and `Option`, respectively. ### Derivable Types A trait or class can appear in a `derives` clause if its companion object defines a method named `derived`. The type and implementation of a `derived` method are arbitrary, but typically it has a definition like this: ```scala - def derived[T] given Generic[T] = ... + def derived[T] given Mirror.Of[T] = ... ``` -That is, the `derived` method takes a context parameter of type `Generic` that determines the _shape_ of the deriving type `T` and it computes the typeclass implementation according to that shape. An implied `Generic` instance is generated automatically for any type that derives a typeclass with a `derived` -method that refers to `Generic`. One can also derive `Generic` alone, which means a `Generic` instance is generated without any other type class instances. E.g.: -```scala -sealed trait ParseResult[T] derives Generic +That is, the `derived` method takes an implicit parameter of (some subtype of) type `Mirror` that defines the shape of the deriving type `T` and it computes the typeclass implementation according +to that shape. A `Mirror` delegate is generated automatically for + + - case classes and objects, + - enums and enum cases, + - sealed traits or classes that have only case classes and case objects as children. ``` + + \ No newline at end of file diff --git a/docs/docs/reference/contextual/extension-methods.md b/docs/docs/reference/contextual/extension-methods.md index c7a84d929fe0..ee8ac4d91356 100644 --- a/docs/docs/reference/contextual/extension-methods.md +++ b/docs/docs/reference/contextual/extension-methods.md @@ -36,7 +36,7 @@ When is an extension method applicable? There are two possibilities. - An extension method is applicable if it is visible under a simple name, by being defined or inherited or imported in a scope enclosing the application. - - An extension method is applicable if it is a member of some implied instance at the point of the application. + - An extension method is applicable if it is a member of some delegate that's eligible at the point of the application. As an example, consider an extension method `longestStrings` on `String` defined in a trait `StringSeqOps`. @@ -48,15 +48,15 @@ trait StringSeqOps { } } ``` -We can make the extension method available by defining an implied instance of `StringSeqOps`, like this: +We can make the extension method available by defining a delegate for `StringSeqOps`, like this: ```scala -implied ops1 for StringSeqOps +delegate ops1 for StringSeqOps ``` Then ```scala List("here", "is", "a", "list").longestStrings ``` -is legal everywhere `ops1` is available as an implied instance. Alternatively, we can define `longestStrings` as a member of a normal object. But then the method has to be brought into scope to be usable as an extension method. +is legal everywhere `ops1` is available as a delegate. Alternatively, we can define `longestStrings` as a member of a normal object. But then the method has to be brought into scope to be usable as an extension method. ```scala object ops2 extends StringSeqOps @@ -69,32 +69,32 @@ Assume a selection `e.m[Ts]` where `m` is not a member of `e`, where the type ar and where `T` is the expected type. The following two rewritings are tried in order: 1. The selection is rewritten to `m[Ts](e)`. - 2. If the first rewriting does not typecheck with expected type `T`, and there is an implied instance `i` - in either the current scope or in the implied scope of `T`, and `i` defines an extension - method named `m`, then selection is expanded to `i.m[Ts](e)`. + 2. If the first rewriting does not typecheck with expected type `T`, and there is a delegate `d` + in either the current scope or in the implicit scope of `T`, and `d` defines an extension + method named `m`, then selection is expanded to `d.m[Ts](e)`. This second rewriting is attempted at the time where the compiler also tries an implicit conversion from `T` to a type containing `m`. If there is more than one way of rewriting, an ambiguity error results. So `circle.circumference` translates to `CircleOps.circumference(circle)`, provided -`circle` has type `Circle` and `CircleOps` is an eligible implied instance (i.e. it is visible at the point of call or it is defined in the companion object of `Circle`). +`circle` has type `Circle` and `CircleOps` is an eligible delegate (i.e. it is visible at the point of call or it is defined in the companion object of `Circle`). -### Implied Instances for Extension Methods +### Delegates for Extension Methods -Implied instances that define extension methods can also be defined without a `for` clause. E.g., +Delegates that define extension methods can also be defined without a `for` clause. E.g., ```scala -implied StringOps { +delegate StringOps { def (xs: Seq[String]) longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) } } -implied { +delegate { def (xs: List[T]) second[T] = xs.tail.head } ``` -If such a representative is anonymous (as in the second clause above), its name is synthesized from the name +If such delegates are anonymous (as in the second clause), their name is synthesized from the name of the first defined extension method. ### Operators diff --git a/docs/docs/reference/contextual/import-implied.md b/docs/docs/reference/contextual/import-implied.md index 137384baf7a7..efca5558a259 100644 --- a/docs/docs/reference/contextual/import-implied.md +++ b/docs/docs/reference/contextual/import-implied.md @@ -1,80 +1,80 @@ --- layout: doc-page -title: "Importing Implied Instances" +title: "Delegate Imports" --- -A special form of import is used to import implied instances. Example: +A special form of import is used to import delegates. Example: ```scala object A { class TC - implied tc for TC + delegate tc for TC def f given TC = ??? } object B { import A._ - import implied A._ + import delegate A._ } ``` In the code above, the `import A._` clause of object `B` will import all members -of `A` _except_ the implied instance `tc`. Conversely, the second import `import implied A._` will import _only_ that implied instance. +of `A` _except_ the delegate `tc`. Conversely, the second import `import delegate A._` will import _only_ that delegate. -Generally, a normal import clause brings all members except implied instances into scope whereas an `import implied` clause brings only implied instances into scope. +Generally, a normal import clause brings all definitions except delegates into scope whereas a delegate import brings only delegates into scope. There are two main benefits arising from these rules: - - It is made clearer where implied instances in scope are coming from. In particular, it is not possible to hide imported implied instances in a long list of regular imports. - - It enables importing all implied instances - without importing anything else. This is particularly important since implied - instances can be anonymous, so the usual recourse of using named imports is not + - It is made clearer where delegates in scope are coming from. + In particular, it is not possible to hide imported delegates in a long list of regular imports. + - It enables importing all delegates + without importing anything else. This is particularly important since delegates + can be anonymous, so the usual recourse of using named imports is not practical. ### Importing By Type -Since implied instances can be anonymous it is not always practical to import them by their name, and wildcard imports are typically used instead. By-type imports provide a more specific alternative to wildcard imports, which makes it clearer what is imported. Example: +Since delegates can be anonymous it is not always practical to import them by their name, and wildcard imports are typically used instead. By-type imports provide a more specific alternative to wildcard imports, which makes it clearer what is imported. Example: ```scala -import implied A.{for TC} +import delegate A.{for TC} ``` -This imports any implied instance in `A` that has a type which conforms tp `TC`. There can be several bounding types following a `for` and bounding types can contain wildcards. +This imports any delegate in `A` that has a type which conforms tp `TC`. There can be several bounding types following a `for` and bounding types can contain wildcards. For instance, assuming the object ```scala object Instances { - implied intOrd for Ordering[Int] - implied [T: Ordering] listOrd for Ordering[List[T]] - implied ec for ExecutionContext = ... - implied im for Monoid[Int] + delegate intOrd for Ordering[Int] + delegate [T: Ordering] listOrd for Ordering[List[T]] + delegate ec for ExecutionContext = ... + delegate im for Monoid[Int] } ``` the import ``` -import implied Instances.{for Ordering[_], ExecutionContext} +import delegate Instances.{for Ordering[_], ExecutionContext} ``` -would import the `intOrd`, `listOrd`, and `ec` instances but leave out the `im` instance, since it fits none of the specified bounds. +would import the `intOrd`, `listOrd`, and `ec` delegates but leave out the `im` delegate, since it fits none of the specified bounds. By-type imports can be mixed with by-name imports. If both are present in an import clause, by-type imports come last. For instance, the import clause ``` -import implied Instances.{im, for Ordering[_]} +import delegate Instances.{im, for Ordering[_]} ``` would import `im`, `intOrd`, and `listOrd` but leave out `ec`. By-type imports cannot be mixed with a wildcard import in the same import clause. ### Migration -The rules for `import implied` above have the consequence that a library +The rules for delegate imports given above have the consequence that a library would have to migrate in lockstep with all its users from old style implicits and -normal imports to implied instances and imports. +normal imports to delegate definitions and imports. The following modifications avoid this hurdle to migration. - 1. An `import implied` also brings old style implicits into scope. So, in Scala 3.0 - an old-style implicit definition can be brought into scope either by a normal import or - by an `import implied`. + 1. A delegate import also brings old style implicits into scope. So, in Scala 3.0 + an old-style implicit definition can be brought into scope either by a normal import or by a delegate import. 2. In Scala 3.1, old-style implicits accessed through a normal import will give a deprecation warning. - 3. In some version after 3.1, an old-style implicit accessed through a normal import + 3. In some version after 3.1, old-style implicits accessed through a normal import will give a compiler error. -These rules mean that library users can use `import implied` to access old-style implicits in Scala 3.0, +These rules mean that library users can use `import delegate` to access old-style implicits in Scala 3.0, and will be gently nudged and then forced to do so in later versions. Libraries can then switch to -implied instances once their user base has migrated. +representation clauses once their user base has migrated. diff --git a/docs/docs/reference/contextual/inferable-by-name-parameters.md b/docs/docs/reference/contextual/inferable-by-name-parameters.md index d5bd56b46d9d..a85eb1b2e81e 100644 --- a/docs/docs/reference/contextual/inferable-by-name-parameters.md +++ b/docs/docs/reference/contextual/inferable-by-name-parameters.md @@ -1,18 +1,18 @@ --- layout: doc-page -title: "By-Name Context Parameters" +title: "Implicit By-Name Parameters" --- -Context parameters can be declared by-name to avoid a divergent inferred expansion. Example: +Implicit parameters can be declared by-name to avoid a divergent inferred expansion. Example: ```scala trait Codec[T] { def write(x: T): Unit } -implied intCodec for Codec[Int] = ??? +delegate intCodec for Codec[Int] = ??? -implied optionCodec[T] for Codec[Option[T]] given (ev: => Codec[T]) { +delegate optionCodec[T] for Codec[Option[T]] given (ev: => Codec[T]) { def write(xo: Option[T]) = xo match { case Some(x) => ev.write(x) case None => @@ -24,29 +24,29 @@ val s = the[Codec[Option[Int]]] s.write(Some(33)) s.write(None) ``` -As is the case for a normal by-name parameter, the argument for the context parameter `ev` +As is the case for a normal by-name parameter, the argument for the implicit parameter `ev` is evaluated on demand. In the example above, if the option value `x` is `None`, it is not evaluated at all. -The synthesized argument for a context parameter is backed by a local val +The synthesized argument for an implicit parameter is backed by a local val if this is necessary to prevent an otherwise diverging expansion. -The precise steps for synthesizing an argument for a by-name context parameter of type `=> T` are as follows. +The precise steps for synthesizing an argument for an implicit by-name parameter of type `=> T` are as follows. - 1. Create a new implied instance of type `T`: + 1. Create a new delegate for type `T`: ```scala - implied lv for T = ??? + delegate lv for T = ??? ``` where `lv` is an arbitrary fresh name. - 1. This instance is not immediately available as candidate for argument inference (making it immediately available could result in a loop in the synthesized computation). But it becomes available in all nested contexts that look again for an inferred argument to a by-name parameter. + 1. This delegate is not immediately available as candidate for argument inference (making it immediately available could result in a loop in the synthesized computation). But it becomes available in all nested contexts that look again for an argument to an implicit by-name parameter. - 1. If this search succeeds with expression `E`, and `E` contains references to the implied instance `lv`, replace `E` by + 1. If this search succeeds with expression `E`, and `E` contains references to the delegate `lv`, replace `E` by ```scala - { implied lv for T = E; lv } + { delegate lv for T = E; lv } ``` Otherwise, return `E` unchanged. @@ -58,7 +58,7 @@ val s = the[Test.Codec[Option[Int]]]( optionCodec[Int](intCodec)) ``` -No local instance was generated because the synthesized argument is not recursive. +No local delegate was generated because the synthesized argument is not recursive. ### Reference diff --git a/docs/docs/reference/contextual/inferable-params.md b/docs/docs/reference/contextual/inferable-params.md index 7a0afbb717c3..212f487fbdd2 100644 --- a/docs/docs/reference/contextual/inferable-params.md +++ b/docs/docs/reference/contextual/inferable-params.md @@ -9,44 +9,44 @@ call trees where the same value is passed over and over again in long call chain functions. Given clauses can help here since they enable the compiler to synthesize repetitive arguments instead of the programmer having to write them explicitly. -For example, given the [implied instances](./instance-defs.md) defined previously, +For example, given the [delegates](./instance-defs.md) defined previously, a maximum function that works for any arguments for which an ordering exists can be defined as follows: ```scala def max[T](x: T, y: T) given (ord: Ord[T]): T = if (ord.compare(x, y) < 1) y else x ``` -Here, `ord` is an _context parameter_ introduced with a `given` clause. +Here, `ord` is an _implicit parameter_ introduced with a `given` clause. The `max` method can be applied as follows: ```scala -max(2, 3) given IntOrd +max(2, 3).given(IntOrd) ``` The `given IntOrd` part passes `IntOrd` as an argument for the `ord` parameter. But the point of -context parameters is that this argument can also be left out (and it usually is). So the following +implicit parameters is that this argument can also be left out (and it usually is). So the following applications are equally valid: ```scala max(2, 3) max(List(1, 2, 3), Nil) ``` -## Anonymous Context Parameters +## Anonymous Given Clauses -In many situations, the name of a context parameter need not be +In many situations, the name of an implicit parameter need not be mentioned explicitly at all, since it is used only in synthesized arguments for -other context parameters. In that case one can avoid defining a parameter name +other implicit parameters. In that case one can avoid defining a parameter name and just provide its type. Example: ```scala def maximum[T](xs: List[T]) given Ord[T]: T = xs.reduceLeft(max) ``` -`maximum` takes a context parameter of type `Ord` only to pass it on as an +`maximum` takes an implicit parameter of type `Ord` only to pass it on as an inferred argument to `max`. The name of the parameter is left out. -Generally, context parameters may be defined either as a parameter list `(p_1: T_1, ..., p_n: T_n)` +Generally, implicit parameters may be defined either as a parameter list `(p_1: T_1, ..., p_n: T_n)` or as a sequence of types, separated by commas. ## Inferring Complex Arguments -Here are two other methods that have a context parameter of type `Ord[T]`: +Here are two other methods that have an implicit parameter of type `Ord[T]`: ```scala def descending[T] given (asc: Ord[T]): Ord[T] = new Ord[T] { def compare(x: T, y: T) = asc.compare(y, x) @@ -73,8 +73,8 @@ def f given (u: Universe) given (x: u.Context) = ... However, all `given` clauses in a definition must come after any normal parameter clauses. Multiple given clauses are matched left-to-right in applications. Example: ```scala -implied global for Universe { type Context = ... } -implied ctx for global.Context { ... } +delegate global for Universe { type Context = ... } +delegate ctx for global.Context { ... } ``` Then the following calls are all valid (and normalize to the last one) ```scala @@ -84,18 +84,17 @@ f ``` But `f given ctx` would give a type error. -## Summoning Implied Instances +## Summoning Delegates -A method `the` in `Predef` returns the implied instance of a given type. For example, -the implied instance of `Ord[List[Int]]` is produced by +A method `the` in `Predef` returns the delegate for a given type. For example, +the delegate for `Ord[List[Int]]` is produced by ```scala -the[Ord[List[Int]]] // reduces to: ListOrd given IntOrd +the[Ord[List[Int]]] // reduces to ListOrd given IntOrd ``` -The `the` method is simply defined as the (non-widening) identity function over a context parameter. +The `the` method is simply defined as the (non-widening) identity function over a implicit parameter. ```scala def the[T] given (x: T): x.type = x ``` -Functions like `the` that have only context parameters are also called _context functions_. ## Syntax @@ -103,10 +102,10 @@ Here is the new syntax of parameters and arguments seen as a delta from the [sta ``` ClsParamClauses ::= ... | {ClsParamClause} {GivenClsParamClause} -GivenClsParamClause ::= ‘given’ [‘erased’] (‘(’ ClsParams ‘)’ | GivenTypes) +GivenClsParamClause ::= ‘given’ (‘(’ ClsParams ‘)’ | GivenTypes) DefParamClauses ::= ... | {DefParamClause} {GivenParamClause} -GivenParamClause ::= ‘given’ [‘erased’] (‘(’ DefParams ‘)’ | GivenTypes) +GivenParamClause ::= ‘given’ (‘(’ DefParams ‘)’ | GivenTypes) GivenTypes ::= AnnotType {‘,’ AnnotType} InfixExpr ::= ... diff --git a/docs/docs/reference/contextual/instance-defs.md b/docs/docs/reference/contextual/instance-defs.md index 89403461f0d4..803f58275d1b 100644 --- a/docs/docs/reference/contextual/instance-defs.md +++ b/docs/docs/reference/contextual/instance-defs.md @@ -1,11 +1,11 @@ --- layout: doc-page -title: "Implied Instances" +title: "Delegates" --- -Implied instances define "canonical" values of given types -that can be synthesized by the compiler as arguments for -[given clauses](./inferable-params.html). Example: +Delegates define "canonical" values of certain types +that serve for synthesizing arguments to [given clauses](./inferable-params.html). Example: + ```scala trait Ord[T] { def compare(x: T, y: T): Int @@ -13,12 +13,12 @@ trait Ord[T] { def (x: T) > (y: T) = compare(x, y) > 0 } -implied IntOrd for Ord[Int] { +delegate IntOrd for Ord[Int] { def compare(x: Int, y: Int) = if (x < y) -1 else if (x > y) +1 else 0 } -implied ListOrd[T] for Ord[List[T]] given (ord: Ord[T]) { +delegate ListOrd[T] for Ord[List[T]] given (ord: Ord[T]) { def compare(xs: List[T], ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -29,59 +29,61 @@ implied ListOrd[T] for Ord[List[T]] given (ord: Ord[T]) { } } ``` -This code defines a trait `Ord` and two implied instance clauses. `IntOrd` defines -an implied instance for the type `Ord[Int]` whereas `ListOrd[T]` defines implied -instances of `Ord[List[T]]` for all types `T` that come with an implied `Ord[T]` instance themselves. -The `given` clause in `ListOrd` defines an _context parameter_. +This code defines a trait `Ord` with two delegate definitions. `IntOrd` defines +a delegate for the type `Ord[Int]` whereas `ListOrd[T]` defines delegates +for `Ord[List[T]]` for all types `T` that come with a delegate for `Ord[T]` themselves. +The `given` clause in `ListOrd` defines an implicit parameter. Given clauses are further explained in the [next section](./inferable-params.html). -## Anonymous Implied Instances +## Anonymous Delegates -The name of an implied instance can be left out. So the implied instance definitions +The name of a delegate can be left out. So the delegate definitions of the last section can also be expressed like this: ```scala -implied for Ord[Int] { ... } -implied [T] for Ord[List[T]] given (ord: Ord[T]) { ... } +delegate for Ord[Int] { ... } +delegate [T] for Ord[List[T]] given (ord: Ord[T]) { ... } ``` -If the name of an instance is missing, the compiler will synthesize a name from +If the name of a delegate is missing, the compiler will synthesize a name from the type(s) in the `for` clause. -## Implied Alias Instances +## Alias Delegates -An implied alias instance defines an implied instance that is equal to some expression. E.g.: +An alias can be used to define a delegate that is equal to some expression. E.g.: ```scala -implied global for ExecutionContext = new ForkJoinPool() +delegate global for ExecutionContext = new ForkJoinPool() ``` -This creates an implied instance `global` of type `ExecutionContext` that resolves to the right hand side `new ForkJoinPool()`. +This creates a delegate `global` of type `ExecutionContext` that resolves to the right hand side `new ForkJoinPool()`. The first time `global` is accessed, a new `ForkJoinPool` is created, which is then returned for this and all subsequent accesses to `global`. -Alias instances may be anonymous, e.g. +Alias delegates can be anonymous, e.g. ```scala -implied for Position = enclosingTree.position +delegate for Position = enclosingTree.position ``` -An implied alias instance can have type parameters and given clauses just like any other implied instance, but it can only implement a single type. +An alias delegate can have type parameters and given clauses just like any other delegate, but it can only implement a single type. -## Creating Implied Instances +## Delegate Instantiation -An implied instance without type parameters or given clause is created on-demand, the first time it is accessed. It is not required to ensure safe publication, which means that different threads might create different representatives for the same `implied` clause. If an implied instance has type parameters or a given clause, its definition is evaluated each time it is applied to arguments. +A delegate without type parameters or given clause is instantiated on-demand, the first +time it is accessed. It is not required to ensure safe publication, which means that +different threads might create different delegates for the same `delegate` clause. +If a `delegate` clause has type parameters or a given clause, a fresh delegate is +created for each reference. ## Syntax -Here is the new syntax of implied instance definitions, seen as a delta from the [standard context free syntax of Scala 3](http://dotty.epfl.ch/docs/internals/syntax.html). +Here is the new syntax of delegate clauses, seen as a delta from the [standard context free syntax of Scala 3](http://dotty.epfl.ch/docs/internals/syntax.html). ``` TmplDef ::= ... - | ‘implied’ InstanceDef -InstanceDef ::= [id] [DefTypeParamClause] InstanceBody -InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody] + | ‘delegate’ DelegateDef +DelegateDef ::= [id] [DefTypeParamClause] DelegateBody +DelegateBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody] | ‘for’ Type {GivenParamClause} ‘=’ Expr ConstrApp ::= SimpleConstrApp | ‘(’ SimpleConstrApp {‘given’ (PrefixExpr | ParArgumentExprs)} ‘)’ SimpleConstrApp ::= AnnotType {ArgumentExprs} GivenParamClause ::= ‘given’ (‘(’ [DefParams] ‘)’ | GivenTypes) GivenTypes ::= AnnotType {‘,’ AnnotType} -ConstrApp ::= SimpleConstrApp - | ‘(’ SimpleConstrApp {‘given’ (PrefixExpr | ParArgumentExprs)} ‘)’ ``` The identifier `id` can be omitted only if either the `for` part or the template body is present. If the `for` part is missing, the template body must define at least one extension method. diff --git a/docs/docs/reference/contextual/motivation.md b/docs/docs/reference/contextual/motivation.md index b625fb550212..0dc0c3db165e 100644 --- a/docs/docs/reference/contextual/motivation.md +++ b/docs/docs/reference/contextual/motivation.md @@ -47,27 +47,27 @@ Existing Scala programmers by and large have gotten used to the status quo and s The following pages introduce a redesign of contextual abstractions in Scala. They introduce four fundamental changes: - 1. [Implied Instances](./instance-defs.html) are a new way to define terms that can be synthesized. They replace the `implicit` modifiers on definitions. The core principle is that, rather than mixing the `implicit` modifier with a large number of features, we have a single way to define terms that can be synthesized for types. + 1. [Delegates](./instance-defs.html) are a new way to define basic terms that can be synthesized. They replace implicit definitions. The core principle of the proposal is that, rather than mixing the `implicit` modifier with a large number of features, we have a single way to define terms that can be synthesized for types. 2. [Given Clauses](./inferable-params.html) are a new syntax for implicit _parameters_ and their _arguments_. Both are introduced with the same keyword, `given`. This unambiguously aligns parameters and arguments, solving a number of language warts. It also allows us to have several implicit parameter sections, and to have implicit parameters followed by normal ones. - 3. [Import Implied](./import-implied.html) is new form of import that specifically imports implicit definitions and nothing else. New-style implied instances _must be_ imported with `import implied`, a plain import will no longer bring them into scope. + 3. [Delegate Imports](./import-implied.html) are a new class of imports that specifically import delegates and nothing else. Delegates _must be_ imported with `import delegate`, a plain import will no longer bring them into scope. - 4. [Implicit Conversions](./conversions.html) are now expressed as implied instances of a standard `Conversion` class. All other forms of implicit conversions will be phased out. + 4. [Implicit Conversions](./conversions.html) are now expressed as delegates of a standard `Conversion` class. All other forms of implicit conversions will be phased out. This section also contains pages describing other language features that are related to context abstraction. These are: - [Context Bounds](./context-bounds.html), which carry over unchanged. - [Extension Methods](./extension-methods.html) replace implicit classes in a way that integrates better with typeclasses. - [Implementing Typeclasses](./typeclasses.html) demonstrates how some common typeclasses can be implemented using the new constructs. - - [Typeclass Derivation](./derivation.html) introduces constructs to automatically derive implied typeclass instances for ADTs. + - [Typeclass Derivation](./derivation.html) introduces constructs to automatically derive typeclass delegates for ADTs. - [Multiversal Equality](./multiversal-equality.html) introduces a special typeclass to support type safe equality. - - [Contextual Functions](./query-types.html) provide a way to abstract over given clauses. - - [By-Name Context Parameters](./inferable-by-name-parameters.html) are an essential tool to define recursive synthesized values without looping. - - [Relationship with Scala 2 Implicits](./relationship-implicits.html) discusses the relationship between old-style implicits and new-style implied instances and given clauses and how to migrate from one to the other. + - [Implicit Function Types](./query-types.html) provide a way to abstract over given clauses. + - [Implicit By-Name Parameters](./inferable-by-name-parameters.html) are an essential tool to define recursive synthesized values without looping. + - [Relationship with Scala 2 Implicits](./relationship-implicits.html) discusses the relationship between old-style implicits and new-style delegates and given clauses and how to migrate from one to the other. -Overall, the new design achieves a better separation of term inference from the rest of the language: There is a single way to define implied instances instead of a multitude of forms all taking an `implicit` modifier. There is a single way to introduce implicit parameters and arguments instead of conflating implicit with normal arguments. There is a separate way to import implied instances that does not allow them to hide in a sea of normal imports. And there is a single way to define an implicit conversion which is clearly marked as such and does not require special syntax. +Overall, the new design achieves a better separation of term inference from the rest of the language: There is a single way to define delegates instead of a multitude of forms all taking an `implicit` modifier. There is a single way to introduce implicit parameters and arguments instead of conflating implicit with normal arguments. There is a separate way to import delegates that does not allow them to hide in a sea of normal imports. And there is a single way to define an implicit conversion which is clearly marked as such and does not require special syntax. This design thus avoids feature interactions and makes the language more consistent and orthogonal. It will make implicits easier to learn and harder to abuse. It will greatly improve the clarity of the 95% of Scala programs that use implicits. It has thus the potential to fulfil the promise of term inference in a principled way that is also accessible and friendly. @@ -78,3 +78,4 @@ Could we achieve the same goals by tweaking existing implicits? After having tri - Third, even if we would somehow succeed with migration, we still have the problem how to teach this. We cannot make existing tutorials go away. Almost all existing tutorials start with implicit conversions, which will go away; they use normal imports, which will go away, and they explain calls to methods with implicit parameters by expanding them to plain applications, which will also go away. This means that we'd have to add modifications and qualifications to all existing literature and courseware, likely causing more confusion with beginners instead of less. By contrast, with a new syntax there is a clear criterion: Any book or courseware that mentions `implicit` is outdated and should be updated. + diff --git a/docs/docs/reference/contextual/multiversal-equality.md b/docs/docs/reference/contextual/multiversal-equality.md index 674fbd8f9bba..5ccdca4cd36c 100644 --- a/docs/docs/reference/contextual/multiversal-equality.md +++ b/docs/docs/reference/contextual/multiversal-equality.md @@ -19,7 +19,8 @@ val y = ... // of type S, but should be T x == y // typechecks, will always yield false ``` -If all the program does with `y` is compare it to other values of type `T`, the program will still typecheck, since values of all types can be compared with each other. +If `y` gets compared to other values of type `T`, +the program will still typecheck, since values of all types can be compared with each other. But it will probably give unexpected results and fail at runtime. Multiversal equality is an opt-in way to make universal equality @@ -30,9 +31,9 @@ that derives `Eql`, e.g. ```scala class T derives Eql ``` -Alternatively, one can also define an `Eql` instance directly, like this: +Alternatively, one can also provide an `Eql` delegate directly, like this: ```scala -implied for Eql[T, T] = Eql.derived +delegate for Eql[T, T] = Eql.derived ``` This definition effectively says that values of type `T` can (only) be compared to other values of type `T` when using `==` or `!=`. The definition @@ -53,30 +54,30 @@ object Eql { } ``` -One can have several `Eql` instances for a type. For example, the four +One can have several `Eql` delegates for a type. For example, the four definitions below make values of type `A` and type `B` comparable with each other, but not comparable to anything else: ```scala -implied for Eql[A, A] = Eql.derived -implied for Eql[B, B] = Eql.derived -implied for Eql[A, B] = Eql.derived -implied for Eql[B, A] = Eql.derived +delegate for Eql[A, A] = Eql.derived +delegate for Eql[B, B] = Eql.derived +delegate for Eql[A, B] = Eql.derived +delegate for Eql[B, A] = Eql.derived ``` -The `scala.Eql` object defines a number of `Eql` instances that together +The `scala.Eql` object defines a number of `Eql` delegates that together define a rule book for what standard types can be compared (more details below). There's also a "fallback" instance named `eqlAny` that allows comparisons -over all types that do not themselves have an `Eql` instance. `eqlAny` is +over all types that do not themselves have an `Eql` delegate. `eqlAny` is defined as follows: ```scala def eqlAny[L, R]: Eql[L, R] = Eql.derived ``` -Even though `eqlAny` is not declared with an `implied` clause, the compiler will still +Even though `eqlAny` is not declared a delegate, the compiler will still construct an `eqlAny` instance as answer to an implicit search for the -type `Eql[L, R]`, unless `L` or `R` have `Eql` instances +type `Eql[L, R]`, unless `L` or `R` have `Eql` delegates defined on them, or the language feature `strictEquality` is enabled The primary motivation for having `eqlAny` is backwards compatibility, @@ -89,20 +90,20 @@ import scala.language.strictEquality ``` or with a command line option `-language:strictEquality`. -## Deriving Eql Instances +## Deriving Eql Delegates -Instead of defining `Eql` instances directly, it is often more convenient to derive them. Example: +Instead of defining `Eql` delegates directly, it is often more convenient to derive them. Example: ```scala class Box[T](x: T) derives Eql ``` By the usual rules if [typeclass derivation](./derivation.html), -this generates the following `Eql` instance in the companion object of `Box`: +this generates the following `Eql` delegate in the companion object of `Box`: ```scala -implied [T, U] for Eql[Box[T], Box[U]] given Eql[T, U] = Eql.derived +delegate [T, U] for Eql[Box[T], Box[U]] given Eql[T, U] = Eql.derived ``` That is, two boxes are comparable with `==` or `!=` if their elements are. Examples: ```scala -new Box(1) == new Box(1L) // ok since `Eql[Int, Long]` is an implied instance +new Box(1) == new Box(1L) // ok since there is a delegate for `Eql[Int, Long]` new Box(1) == new Box("a") // error: can't compare new Box(1) == 1 // error: can't compare ``` @@ -115,7 +116,7 @@ If the `strictEquality` feature is enabled then a comparison using `x == y` or `x != y` between values `x: T` and `y: U` is legal if - 1. there is an implied instance of type `Eql[T, U]`, or + 1. there is a delegate for `Eql[T, U]`, or 2. one of `T`, `U` is `Null`. In the default case where the `strictEquality` feature is not enabled the comparison is @@ -123,24 +124,24 @@ also legal if 1. `T` and `U` the same, or 2. one of `T` and `U`is a subtype of the _lifted_ version of the other type, or - 3. neither `T` nor `U` have a _reflexive `Eql` instance_. + 3. neither `T` nor `U` have a _reflexive `Eql` delegate_. Explanations: - _lifting_ a type `S` means replacing all references to abstract types in covariant positions of `S` by their upper bound, and to replacing all refinement types in covariant positions of `S` by their parent. - - a type `T` has a _reflexive `Eql` instance_ if the implicit search for `Eql[T, T]` + - a type `T` has a _reflexive `Eql` delegate_ if the implicit search for `Eql[T, T]` succeeds. -## Predefined Eql Instances +## Predefined Eql Delegates -The `Eql` object defines implied instances for +The `Eql` object defines delegates for comparing - the primitive types `Byte`, `Short`, `Char`, `Int`, `Long`, `Float`, `Double`, `Boolean`, and `Unit`, - `java.lang.Number`, `java.lang.Boolean`, and `java.lang.Character`, - `scala.collection.Seq`, and `scala.collection.Set`. -Implied instances are defined so that every one of these types has a reflexive `Eql` instance, and the following holds: +Delegates are defined so that every one of these types has a reflexive `Eql` delegate, and the following holds: - Primitive numeric types can be compared with each other. - Primitive numeric types can be compared with subtypes of `java.lang.Number` (and _vice versa_). @@ -190,7 +191,7 @@ Unfortunately, the crucial ability to "lift" equality type checking from simple def contains[U >: T](x: U) given Eql1[U]: Boolean // (2) ``` This version could be applied just as widely as the original `contains(x: Any)` method, -since the `Eql1[Any]` fallback is always available! So we have gained nothing. What got lost in the transition to a single parameter type class was the original rule that `Eql[A, B]` is available only if neither `A` nor `B` have a reflexive `Eql` instance. That rule simply cannot be expressed if there is a single type parameter for `Eql`. +since the `Eql1[Any]` fallback is always available! So we have gained nothing. What got lost in the transition to a single parameter type class was the original rule that `Eql[A, B]` is available only if neither `A` nor `B` have a reflexive `Eql` delegate. That rule simply cannot be expressed if there is a single type parameter for `Eql`. The situation is different under `-language:strictEquality`. In that case, the `Eql[Any, Any]` or `Eql1[Any]` instances would never be available, and the @@ -199,7 +200,7 @@ single and two-parameter versions would indeed coincide for most practical purpo But assuming `-language:strictEquality` immediately and everywhere poses migration problems which might well be unsurmountable. Consider again `contains`, which is in the standard library. Parameterizing it with the `Eql` type class as in (1) is an immediate win since it rules out non-sensical applications while still allowing all sensible ones. So it can be done almost at any time, modulo binary compatibility concerns. On the other hand, parameterizing `contains` with `Eql1` as in (2) would make `contains` -unusable for all types that have not yet declared an `Eql1` instance, including all +unusable for all types that have not yet declared an `Eql1` delegate, including all types coming from Java. This is clearly unacceptable. It would lead to a situation where, rather than migrating existing libraries to use safe equality, the only upgrade path is to have parallel libraries, with the new version only catering to types deriving `Eql1` and the old version dealing with everything else. Such a split of the ecosystem would be very problematic, which means the cure is likely to be worse than the disease. diff --git a/docs/docs/reference/contextual/query-types-spec.md b/docs/docs/reference/contextual/query-types-spec.md index 608ea59c3443..f2f715c46821 100644 --- a/docs/docs/reference/contextual/query-types-spec.md +++ b/docs/docs/reference/contextual/query-types-spec.md @@ -1,6 +1,6 @@ --- layout: doc-page -title: "Contextual Function Types - More Details" +title: "Implicit Function Types - More Details" --- ## Syntax @@ -10,13 +10,13 @@ title: "Contextual Function Types - More Details" Expr ::= ... | `given' FunParams `=>' Expr -Contextual function types associate to the right, e.g. +Implicit function types associate to the right, e.g. `given S => given T => U` is the same as `given S => (given T => U)`. ## Implementation -Contextual function types are shorthands for class types that define `apply` -methods with given clauses. Specifically, the `N`-ary function type +Implicit function types are shorthands for class types that define `apply` +methods with implicit parameters. Specifically, the `N`-ary function type `T1, ..., TN => R` is a shorthand for the class type `ImplicitFunctionN[T1 , ... , TN, R]`. Such class types are assumed to have the following definitions, for any value of `N >= 1`: ```scala @@ -25,23 +25,23 @@ trait ImplicitFunctionN[-T1 , ... , -TN, +R] { def apply given (x1: T1 , ... , xN: TN): R } ``` -Contextual function types erase to normal function types, so these classes are +Implicit function types erase to normal function types, so these classes are generated on the fly for typechecking, but not realized in actual code. -Contextual lambdas `given (x1: T1, ..., xn: Tn) => e` map -context parameters `xi` of types `Ti` to the result of evaluating expression `e`. +Implicit function literals `given (x1: T1, ..., xn: Tn) => e` map +implicit parameters `xi` of types `Ti` to the result of evaluating expression `e`. The scope of each implicit parameter `xi` is `e`. The parameters must have pairwise distinct names. -If the expected type of the contextual lambda is of the form +If the expected type of the implicit function literal is of the form `scala.ImplicitFunctionN[S1, ..., Sn, R]`, the expected type of `e` is `R` and the type `Ti` of any of the parameters `xi` can be omitted, in which case `Ti -= Si` is assumed. If the expected type of the contextual lambda is -some other type, all context parameter types must be explicitly given, and the expected type of `e` is undefined. -The type of the contextual lambda is `scala.ImplicitFunctionN[S1, ...,Sn, T]`, where `T` is the widened += Si` is assumed. If the expected type of the implicit function literal is +some other type, all implicit parameter types must be explicitly given, and the expected type of `e` is undefined. +The type of the implicit function literal is `scala.ImplicitFunctionN[S1, ...,Sn, T]`, where `T` is the widened type of `e`. `T` must be equivalent to a type which does not refer to any of -the context parameters `xi`. +the implicit parameters `xi`. -The contextual lambda is evaluated as the instance creation +The implicit function literal is evaluated as the instance creation expression: ```scala new scala.ImplicitFunctionN[T1, ..., Tn, T] { @@ -51,20 +51,20 @@ new scala.ImplicitFunctionN[T1, ..., Tn, T] { In the case of a single untyped parameter, `given (x) => e` can be abbreviated to `given x => e`. -A context parameter may also be a wildcard represented by an underscore `_`. In +An implicit parameter may also be a wildcard represented by an underscore `_`. In that case, a fresh name for the parameter is chosen arbitrarily. Note: The closing paragraph of the [Anonymous Functions section](https://www.scala-lang.org/files/archive/spec/2.12/06-expressions.html#anonymous-functions) -of Scala 2.12 is subsumed by contextual function types and should be removed. +of Scala 2.12 is subsumed by implicit function types and should be removed. -Contextual lambdas `given (x1: T1, ..., xn: Tn) => e` are +Implicit function literals `given (x1: T1, ..., xn: Tn) => e` are automatically created for any expression `e` whose expected type is `scala.ImplicitFunctionN[T1, ..., Tn, R]`, unless `e` is -itself a contextual lambda. This is analogous to the automatic +itself a implicit function literal. This is analogous to the automatic insertion of `scala.Function0` around expressions in by-name argument position. -Contextual function types generalize to `N > 22` in the same way that function types do, see [the corresponding +Implicit function types generalize to `N > 22` in the same way that function types do, see [the corresponding documentation](https://dotty.epfl.ch/docs/reference/dropped-features/limit22.html). ## Examples @@ -77,4 +77,4 @@ Gist](https://gist.github.com/OlivierBlanvillain/234d3927fe9e9c6fba074b53a7bd9 ### Type Checking -After desugaring no additional typing rules are required for contextual function types. +After desugaring no additional typing rules are required for implicit function types. diff --git a/docs/docs/reference/contextual/query-types.md b/docs/docs/reference/contextual/query-types.md index 013bbd9693d0..fa62fb9cf528 100644 --- a/docs/docs/reference/contextual/query-types.md +++ b/docs/docs/reference/contextual/query-types.md @@ -1,38 +1,37 @@ --- layout: doc-page -title: "Contextual Functions" +title: "Implicit Function Types" --- -_Contextual functions_ are functions with (only) context -parameters. Their types are _contextual function types_. Here is an -example of a contextual function type: +_Implicit functions_ are functions with (only) implicit parameters. +Their types are _implicit function types_. Here is an example of an implicit function type: ```scala type Executable[T] = given ExecutionContext => T ``` -A contextual function is applied to inferred arguments, in -the same way a method with context parameters is applied. For instance: +An implicit function is applied to synthesized arguments, in +the same way a method with a given clause is applied. For instance: ```scala - implied ec for ExecutionContext = ... + delegate ec for ExecutionContext = ... def f(x: Int): Executable[Int] = ... f(2) given ec // explicit argument f(2) // argument is inferred ``` -Conversely, if the expected type of an expression `E` is a contextual function -type `given (T_1, ..., T_n) => U` and `E` is not already a -contextual lambda, `E` is converted to a contextual lambda by rewriting to +Conversely, if the expected type of an expression `E` is an implicit function type +`given (T_1, ..., T_n) => U` and `E` is not already an +implicit function literal, `E` is converted to an implicit function literal by rewriting to ```scala given (x_1: T1, ..., x_n: Tn) => E ``` where the names `x_1`, ..., `x_n` are arbitrary. This expansion is performed before the expression `E` is typechecked, which means that `x_1`, ..., `x_n` -are available as implied instances in `E`. +are available as delegates in `E`. -Like their types, contextual lamndas are written with a `given` prefix. They differ from normal lambdas in two ways: +Like their types, implicit function literals are written with a `given` prefix. They differ from normal function literals in two ways: 1. Their parameters are defined with a given clause. - 2. Their types are contextual function types. + 2. Their types are implicit function types. For example, continuing with the previous definitions, ```scala @@ -46,7 +45,7 @@ For example, continuing with the previous definitions, ``` ### Example: Builder Pattern -Contextual function types have considerable expressive power. For +Implicit function types have considerable expressive power. For instance, here is how they can support the "builder pattern", where the aim is to construct tables like this: ```scala @@ -79,17 +78,17 @@ addition of elements via `add`: case class Cell(elem: String) ``` Then, the `table`, `row` and `cell` constructor methods can be defined -with contextual function types as parameters to avoid the plumbing boilerplate +with implicit function types as parameters to avoid the plumbing boilerplate that would otherwise be necessary. ```scala def table(init: given Table => Unit) = { - implied t for Table + delegate t for Table init t } def row(init: given Row => Unit) given (t: Table) = { - implied r for Row + delegate r for Row init t.add(r) } @@ -112,7 +111,7 @@ With that setup, the table construction code above compiles and expands to: ``` ### Example: Postconditions -As a larger example, here is a way to define constructs for checking arbitrary postconditions using an extension method `ensuring`so that the checked result can be referred to simply by `result`. The example combines opaque aliases, contextual function types, and extension methods to provide a zero-overhead abstraction. +As a larger example, here is a way to define constructs for checking arbitrary postconditions using an extension method `ensuring`so that the checked result can be referred to simply by `result`. The example combines opaque aliases, implicit function types, and extension methods to provide a zero-overhead abstraction. ```scala object PostConditions { @@ -121,7 +120,7 @@ object PostConditions { def result[T] given (r: WrappedResult[T]): T = f def (x: T) ensuring [T](condition: given WrappedResult[T] => Boolean): T = { - implied for WrappedResult[T] = x + delegate for WrappedResult[T] = x assert(condition) x } @@ -132,12 +131,12 @@ object Test { val s = List(1, 2, 3).sum.ensuring(result == 6) } ``` -**Explanations**: We use a contextual function type `given WrappedResult[T] => Boolean` +**Explanations**: We use an implicit function type `given WrappedResult[T] => Boolean` as the type of the condition of `ensuring`. An argument to `ensuring` such as -`(result == 6)` will therefore have an implied instance of type `WrappedResult[T]` in +`(result == 6)` will therefore have a delegate for type `WrappedResult[T]` in scope to pass along to the `result` method. `WrappedResult` is a fresh type, to make sure -that we do not get unwanted implied instances in scope (this is good practice in all cases -where context parameters are involved). Since `WrappedResult` is an opaque type alias, its +that we do not get unwanted delegates in scope (this is good practice in all cases +where implicit parameters are involved). Since `WrappedResult` is an opaque type alias, its values need not be boxed, and since `ensuring` is added as an extension method, its argument does not need boxing either. Hence, the implementation of `ensuring` is as about as efficient as the best possible code one could write by hand: diff --git a/docs/docs/reference/contextual/relationship-implicits.md b/docs/docs/reference/contextual/relationship-implicits.md index deb92c83d871..1a33e5882efc 100644 --- a/docs/docs/reference/contextual/relationship-implicits.md +++ b/docs/docs/reference/contextual/relationship-implicits.md @@ -7,28 +7,28 @@ Many, but not all, of the new contextual abstraction features in Scala 3 can be ## Simulating Contextual Abstraction with Implicits -### Implied Instance Definitions +### Delegates -Implied instance definitions can be mapped to combinations of implicit objects and implicit methods together with normal classes. +Delegate clauses can be mapped to combinations of implicit objects, classes and implicit methods. - 1. Instance definitions without parameters are mapped to implicit objects. E.g., + 1. Delegates without parameters are mapped to implicit objects. E.g., ```scala - implied IntOrd for Ord[Int] { ... } + delegate IntOrd for Ord[Int] { ... } ``` maps to ```scala implicit object IntOrd extends Ord[Int] { ... } ``` - 2. Parameterized instance definitions are mapped to combinations of classes and implicit methods. E.g., + 2. Parameterized delegates are mapped to combinations of classes and implicit methods. E.g., ```scala - implied ListOrd[T] for Ord[List[T]] given (ord: Ord[T]) { ... } + delegate ListOrd[T] for Ord[List[T]] given (ord: Ord[T]) { ... } ``` maps to ```scala class ListOrd[T](implicit ord: Ord[T]) extends Ord[List[T]] { ... } final implicit def ListOrd[T](implicit ord: Ord[T]): ListOrd[T] = new ListOrd[T] ``` - 3. Implied alias instances map to implicit methods. If an alias has neither type parameters nor a given clause, its right-hand side is cached in a variable. There are two cases that can be optimized: + 3. Alias delegates map to implicit methods. If an alias has neither type parameters nor a given clause, its right-hand side is cached in a variable. There are two cases that can be optimized: - If the right hand side is a simple reference, we can use a forwarder to that reference without caching it. @@ -38,11 +38,11 @@ Implied instance definitions can be mapped to combinations of implicit objects a Examples: ```scala - implied global for ExecutionContext = new ForkJoinContext() - implied config for Config = default.config + delegate global for ExecutionContext = new ForkJoinContext() + delegate config for Config = default.config val ctx: Context - implied for Context = ctx + delegate for Context = ctx ``` would map to ```scala @@ -54,35 +54,35 @@ Implied instance definitions can be mapped to combinations of implicit objects a final implicit val config: Config = default.config - final implicit def Context_repr = ctx + final implicit def Context_delegate = ctx ``` -### Anonymous Implied Instances +### Anonymous Delegates -Anonymous instances get compiler synthesized names, which are generated in a reproducible way from the implemented type(s). For example, if the names of the `IntOrd` and `ListOrd` instances above were left out, the following names would be synthesized instead: +Anonymous delegates get compiler synthesized names, which are generated in a reproducible way from the implemented type(s). For example, if the names of the `IntOrd` and `ListOrd` delegates above were left out, the following names would be synthesized instead: ```scala - implied Ord_Int_instance for Ord[Int] { ... } - implied Ord_List_instance[T] for Ord[List[T]] { ... } + delegate Ord_Int_delegate for Ord[Int] { ... } + delegate Ord_List_delegate[T] for Ord[List[T]] { ... } ``` The synthesized type names are formed from - the simple name(s) of the implemented type(s), leaving out any prefixes, - the simple name(s) of the toplevel argument type constructors to these types - - the suffix `_instance`. + - the suffix `_delegate`. -Anonymous instances that define extension methods without also implementing a type +Anonymous delegates that define extension methods without also implementing a type get their name from the name of the first extension method and the toplevel type -constructor of its first parameter. For example, the instance +constructor of its first parameter. For example, the delegate ```scala - implied { + delegate { def (xs: List[T]) second[T] = ... } ``` -gets the synthesized name `second_of_List_T_instance`. +gets the synthesized name `second_of_List_T_delegate`. -### Context Parameters +### Given Clauses -The new context parameter syntax with `given` corresponds largely to Scala-2's implicit parameters. E.g. +Given clauses corresponds largely to Scala-2's implicit parameter clauses. E.g. ```scala def max[T](x: T, y: T) given (ord: Ord[T]): T ``` @@ -91,7 +91,7 @@ would be written def max[T](x: T, y: T)(implicit ord: Ord[T]): T ``` in Scala 2. The main difference concerns applications of such parameters. -Explicit arguments to context parameters _must_ be written using `given`, +Explicit arguments to parameters of given clauses _must_ be written using `given`, mirroring the definition syntax. E.g, `max(2, 3) given IntOrd`. Scala 2 uses normal applications `max(2, 3)(IntOrd)` instead. The Scala 2 syntax has some inherent ambiguities and restrictions which are overcome by the new syntax. For instance, multiple implicit parameter lists are not available in the old syntax, even though they can be simulated using auxiliary objects in the "Aux" pattern. @@ -121,15 +121,15 @@ could be simulated to some degree by def circumference: Double = c.radius * math.Pi * 2 } ``` -Extension methods in implicit instances have no direct counterpart in Scala-2. The only way to simulate these is to make implicit classes available through imports. The Simulacrum macro library can automate this process in some cases. +Extension methods in delegates have no direct counterpart in Scala-2. The only way to simulate these is to make implicit classes available through imports. The Simulacrum macro library can automate this process in some cases. ### Typeclass Derivation Typeclass derivation has no direct counterpart in the Scala 2 language. Comparable functionality can be achieved by macro-based libraries such as Shapeless, Magnolia, or scalaz-deriving. -### Contextual Function Types +### Implicit Function Types -Contextual function types have no analogue in Scala 2. +Implicit function types have no analogue in Scala 2. ### Implicit By-Name Parameters @@ -139,44 +139,45 @@ Implicit by-name parameters are not supported in Scala 2, but can be emulated to ### Implicit Conversions -Implicit conversion methods in Scala 2 can be expressed as implied instances +Implicit conversion methods in Scala 2 can be expressed as delegates of the `scala.Conversion` class in Dotty. E.g. instead of ```scala implicit def stringToToken(str: String): Token = new Keyword(str) ``` one can write ```scala - implied stringToToken for Conversion[String, Token] { + delegate stringToToken for Conversion[String, Token] { def apply(str: String): Token = new KeyWord(str) } ``` ### Implicit Classes -Implicit classes in Scala 2 are often used to define extension methods, which are directly supported in Dotty. Other uses of implicit classes can be simulated by a pair of a regular class and a conversion instance. +Implicit classes in Scala 2 are often used to define extension methods, which are directly supported in Dotty. Other uses of implicit classes can be simulated by a pair of a regular class and a conversion delegate. ### Implicit Values -Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an alias instance. E.g., Scala 2's +Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an alias delegate. +E.g., Scala 2's ```scala lazy implicit val pos: Position = tree.sourcePos ``` can be expressed in Dotty as ```scala lazy val pos: Position = tree.sourcePos - implied for Position = pos + delegate for Position = pos ``` ### Abstract Implicits -An abstract implicit `val` or `def` in Scala 2 can be expressed in Dotty using a regular abstract definition and an implied alias instaance. E.g., Scala 2's +An abstract implicit `val` or `def` in Scala 2 can be expressed in Dotty using a regular abstract definition and an alias delegate. E.g., Scala 2's ```scala implicit def symDeco: SymDeco ``` can be expressed in Dotty as ```scala def symDeco: SymDeco - implied for SymDeco = symDeco + delegate for SymDeco = symDeco ``` ## Implementation Status and Timeline diff --git a/docs/docs/reference/contextual/typeclasses.md b/docs/docs/reference/contextual/typeclasses.md index 943fa78d3484..0275017345f4 100644 --- a/docs/docs/reference/contextual/typeclasses.md +++ b/docs/docs/reference/contextual/typeclasses.md @@ -3,9 +3,9 @@ layout: doc-page title: "Implementing Typeclasses" --- -Implied instances, extension methods and context bounds +Delegates, extension methods and context bounds allow a concise and natural expression of _typeclasses_. Typeclasses are just traits -with canonical implementations defined by implied instances. Here are some examples of standard typeclasses: +with canonical implementations defined by delegates. Here are some examples of standard typeclasses: ### Semigroups and monoids: @@ -20,12 +20,12 @@ object Monoid { def apply[T] given Monoid[T] = the[Monoid[T]] } -implied for Monoid[String] { +delegate for Monoid[String] { def (x: String) combine (y: String): String = x.concat(y) def unit: String = "" } -implied for Monoid[Int] { +delegate for Monoid[Int] { def (x: Int) combine (y: Int): Int = x + y def unit: Int = 0 } @@ -48,14 +48,14 @@ trait Monad[F[_]] extends Functor[F] { def pure[A](x: A): F[A] } -implied ListMonad for Monad[List] { +delegate ListMonad for 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) } -implied ReaderMonad[Ctx] for Monad[[X] =>> Ctx => X] { +delegate ReaderMonad[Ctx] for 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/docs/docs/reference/metaprogramming/macros-spec.md b/docs/docs/reference/metaprogramming/macros-spec.md index ba8ab2b191db..bb1612018bfc 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 - implied AsFunction1[T, U] for Conversion[Expr[T => U], Expr[T] => Expr[U]] { + delegate AsFunction1[T, U] for 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 9d4e8353790d..afef8aa35467 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 an implied value of +The `the` query succeeds because there is a delegate 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 implied scala.quoted._ + import delegate scala.quoted._ def compile(e: Exp, env: Map[String, Expr[Int]]): Expr[Int] = e match { case Num(n) => @@ -251,15 +251,14 @@ The `toExpr` extension method is defined in package `quoted`: ```scala package quoted - implied LiftingOps { + delegate LiftingOps { def (x: T) toExpr[T] given (ev: Liftable[T]): Expr[T] = ev.toExpr(x) } ``` The extension says that values of types implementing the `Liftable` type class can be -converted ("lifted") to `Expr` values using `toExpr`, provided an implied import -of `scala.quoted._` is in scope. +converted ("lifted") to `Expr` values using `toExpr`, provided a delegate import of `scala.quoted._` is in scope. -Dotty comes with implied instance definitions of `Liftable` for +Dotty comes with delegate definitions 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,7 +268,7 @@ 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 - implied for Liftable[Boolean] { + delegate for Liftable[Boolean] { def toExpr(b: Boolean) = if (b) '{ true } else '{ false } } ``` @@ -277,7 +276,7 @@ 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 - implied for Liftable[Int] { + delegate for Liftable[Int] { def toExpr(n: Int): Expr[Int] = n match { case Int.MinValue => '{ Int.MinValue } case _ if n < 0 => '{ - ${ toExpr(n) } } @@ -290,7 +289,7 @@ 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 - implied [T: Liftable] for Liftable[List[T]] { + delegate [T: Liftable] for Liftable[List[T]] { def toExpr(xs: List[T]): Expr[List[T]] = xs match { case head :: tail => '{ ${ toExpr(head) } :: ${ toExpr(tail) } } case Nil => '{ Nil: List[T] } @@ -336,7 +335,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 an implied instance for `Type[T]`: +of `List` applied to the splice of the result of searching for a delegate for `Type[T]`: ```scala '[ List[ ${ the[Type[T]] } ] ] ``` diff --git a/docs/docs/reference/new-types/match-types.md b/docs/docs/reference/new-types/match-types.md index 235bc0f5c346..8c6e0bb60123 100644 --- a/docs/docs/reference/new-types/match-types.md +++ b/docs/docs/reference/new-types/match-types.md @@ -17,7 +17,7 @@ This defines a type that, depending on the scrutinee type `X`, can reduce to one Elem[String] =:= Char Elem[Array[Int]] =:= Int Elem[List[Float]] =:= Float - Elem[Nil] =:= Nothing + Elem[Nil.type] =:= Nothing ``` Here `=:=` is understood to mean that left and right hand sides are mutually subtypes of each other. diff --git a/docs/docs/reference/other-new-features/export.md b/docs/docs/reference/other-new-features/export.md index aebc3ac2ba4b..147626168cb0 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 implied path . { sel_1, ..., sel_n } + export delegate 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 an `implied` instance (or an old-style `implicit` value) - if and only if the export is `implied`. + - it is delegate (or an old-style `implicit` value) + if and only if the export is tagged with `delegate`. 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 implied instances are again `implied` (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 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 cannot be overridden, since they are final. - Export aliases cannot override concrete members in base classes, since they are @@ -106,7 +106,7 @@ TemplateStat ::= ... | Export TopStat ::= ... | Export -Export ::= ‘export’ [‘implied’] ImportExpr {‘,’ ImportExpr} +Export ::= ‘export’ [‘delegate’] 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 25bdc2e8673f..2124763558b5 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 - implied LogarithmOps { + delegate 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 6a79fa5532db..a1e904cafb79 100644 --- a/docs/docs/reference/overview.md +++ b/docs/docs/reference/overview.md @@ -25,17 +25,17 @@ These new constructs directly model core features of DOT, higher-kinded types, a - [Union types](https://dotty.epfl.ch/docs/reference/new-types/union-types.html), - [Type lambdas](https://dotty.epfl.ch/docs/reference/new-types/type-lambdas.html), replacing encodings using structural types and type projection. - - [Context Queries](https://dotty.epfl.ch/docs/reference/contextual/query-types.html) - (_aka_ implicit function types) offering abstraction over inferable parameters. + - [Implicit Function Types](https://dotty.epfl.ch/docs/reference/contextual/query-types.html) + offering abstraction over implicit parameters. ## Simplifications 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](https://dotty.epfl.ch/docs/reference/other-new-features/trait-parameters.html) replace [early initializers](https://dotty.epfl.ch/docs/reference/dropped-features/early-initializers.html) with a more generally useful construct. - - [Implied Instances](https://dotty.epfl.ch/docs/reference/contextual/instance-defs.html) + - [Delegates](https://dotty.epfl.ch/docs/reference/contextual/instance-defs.html) replace implicit objects and defs, focussing on intent over mechanism. - - [Inferable parameters](https://dotty.epfl.ch/docs/reference/contextual/inferable-params.html) replace implicit parameters, avoiding their ambiguities. + - [Given Clauses](https://dotty.epfl.ch/docs/reference/contextual/inferable-params.html) replace implicit parameters, avoiding their ambiguities. - [Extension Methods](https://dotty.epfl.ch/docs/reference/contextual/extension-methods.html) replace implicit classes with a clearer and simpler mechanism. - [Opaque Type Aliases](https://dotty.epfl.ch/docs/reference/other-new-features/opaques.html) replace most uses of value classes while guaranteeing absence of boxing. @@ -50,14 +50,15 @@ These constructs replace existing constructs with the aim of making the language With the exception of early initializers and old-style vararg patterns, all superseded constructs continue to be available in Scala 3.0. The plan is to deprecate and phase them out later. -Value classes (superseded by opaque type aliases) are a special case. There are currently no deprecation plans for value classes, since we might want to bring them back in a more general form if they are supported natively by the JVM as is planned by project Valhalla. +Value classes (superseded by opaque type aliases) ar +e a special case. There are currently no deprecation plans for value classes, since we might want to bring them back in a more general form if they are supported natively by the JVM as is planned by project Valhalla. ## Restrictions These constructs are restricted to make the language safer. - [Implicit Conversions](https://dotty.epfl.ch/docs/reference/contextual/conversions.html): there is only one way to define implicit conversions instead of many, and potentially surprising implicit conversions require a language import. - - [Implied Imports](https://dotty.epfl.ch/docs/reference/contextual/import-implied.html): implicits now require a special form of import, to make the import clearly visible. + - [Delegate Imports](https://dotty.epfl.ch/docs/reference/contextual/import-implied.html): implicits now require a special form of import, to make the import clearly visible. - [Type Projection](https://dotty.epfl.ch/docs/reference/dropped-features/type-projection.html): 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](https://dotty.epfl.ch/docs/reference/contextual/multiversal-equality.html) 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 840e5d4c6de2..98583a89dbca 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -43,13 +43,13 @@ sidebar: subsection: - title: Overview url: docs/reference/contextual/motivation.html - - title: Implied Instances + - title: Delegates url: docs/reference/contextual/instance-defs.html - - title: Inferable Parameters + - title: Given Clauses url: docs/reference/contextual/inferable-params.html - title: Context Bounds url: docs/reference/contextual/context-bounds.html - - title: Implied Imports + - title: Delegate Imports url: docs/reference/contextual/import-implied.html - title: Extension Methods url: docs/reference/contextual/extension-methods.html @@ -59,11 +59,11 @@ sidebar: url: docs/reference/contextual/derivation.html - title: Multiversal Equality url: docs/reference/contextual/multiversal-equality.html - - title: Context Queries + - title: Implicit Function Types url: docs/reference/contextual/query-types.html - title: Implicit Conversions url: docs/reference/contextual/conversions.html - - title: Inferable By-Name Parameters + - title: Implicit By-Name Parameters url: docs/reference/contextual/inferable-by-name-parameters.html - title: Relationship with Scala 2 Implicits url: docs/reference/contextual/relationship-implicits.html diff --git a/library/src-3.x/scala/IArray.scala b/library/src-3.x/scala/IArray.scala index f3e8ee2fda40..98697f41121b 100644 --- a/library/src-3.x/scala/IArray.scala +++ b/library/src-3.x/scala/IArray.scala @@ -7,7 +7,7 @@ import reflect.ClassTag opaque type IArray[+T] = Array[_ <: T] /** Defines extension methods for immutable arrays */ -implied arrayOps { +implicit object arrayOps { /** The selection operation on an immutable array. * diff --git a/library/src-3.x/scala/internal/quoted/Matcher.scala b/library/src-3.x/scala/internal/quoted/Matcher.scala index 9f4a7919e3b9..161127851a83 100644 --- a/library/src-3.x/scala/internal/quoted/Matcher.scala +++ b/library/src-3.x/scala/internal/quoted/Matcher.scala @@ -310,7 +310,7 @@ object Matcher { } } - implied for Env = Set.empty + implicit val env: Env = Set.empty (scrutineeExpr.unseal =#= patternExpr.unseal).asOptionOfTuple.asInstanceOf[Option[Tup]] } diff --git a/library/src-3.x/scala/quoted/Liftable.scala b/library/src-3.x/scala/quoted/Liftable.scala index 027431968952..9587a40a756b 100644 --- a/library/src-3.x/scala/quoted/Liftable.scala +++ b/library/src-3.x/scala/quoted/Liftable.scala @@ -16,17 +16,17 @@ abstract class Liftable[T] { */ object Liftable { - implied for Liftable[Boolean] = new PrimitiveLifable - implied for Liftable[Short] = new PrimitiveLifable - implied for Liftable[Int] = new PrimitiveLifable - implied for Liftable[Long] = new PrimitiveLifable - implied for Liftable[Float] = new PrimitiveLifable - implied for Liftable[Double] = new PrimitiveLifable - implied for Liftable[Char] = new PrimitiveLifable - implied for Liftable[String] = new PrimitiveLifable - implied ClassIsLiftable[T] for Liftable[Class[T]] = new PrimitiveLifable // FIXME: annonymous implied with type parameter not working + implicit val Liftable_Boolean_delegate: Liftable[Boolean] = new PrimitiveLiftable + implicit val Liftable_Short_delegate: Liftable[Short] = new PrimitiveLiftable + implicit val Liftable_Int_delegate: Liftable[Int] = new PrimitiveLiftable + implicit val Liftable_Long_delegate: Liftable[Long] = new PrimitiveLiftable + implicit val Liftable_Float_delegate: Liftable[Float] = new PrimitiveLiftable + implicit val Liftable_Double_delegate: Liftable[Double] = new PrimitiveLiftable + implicit val Liftable_Char_delegate: Liftable[Char] = new PrimitiveLiftable + implicit val Liftable_String_delegate: Liftable[String] = new PrimitiveLiftable + implicit def ClassIsLiftable[T]: Liftable[Class[T]] = new PrimitiveLiftable - private class PrimitiveLifable[T] extends Liftable[T] { + private class PrimitiveLiftable[T] extends Liftable[T] { override def toExpr(x: T): Expr[T] = liftedExpr(x) } diff --git a/library/src-3.x/scala/quoted/Type.scala b/library/src-3.x/scala/quoted/Type.scala index ab580b78db29..d217445d4980 100644 --- a/library/src-3.x/scala/quoted/Type.scala +++ b/library/src-3.x/scala/quoted/Type.scala @@ -15,15 +15,15 @@ package quoted { def (tpe: Type[T]) show[T] given Toolbox: String = the[Toolbox].show(tpe.asInstanceOf[Type[Any]]) } - implied UnitTag for Type[Unit] = new TaggedType[Unit] - implied BooleanTag for Type[Boolean] = new TaggedType[Boolean] - implied ByteTag for Type[Byte] = new TaggedType[Byte] - implied CharTag for Type[Char] = new TaggedType[Char] - implied ShortTag for Type[Short] = new TaggedType[Short] - implied IntTag for Type[Int] = new TaggedType[Int] - implied LongTag for Type[Long] = new TaggedType[Long] - implied FloatTag for Type[Float] = new TaggedType[Float] - implied DoubleTag for Type[Double] = new TaggedType[Double] + implicit val UnitTag: Type[Unit] = new TaggedType[Unit] + implicit val BooleanTag: Type[Boolean] = new TaggedType[Boolean] + implicit val ByteTag: Type[Byte] = new TaggedType[Byte] + implicit val CharTag: Type[Char] = new TaggedType[Char] + implicit val ShortTag: Type[Short] = new TaggedType[Short] + implicit val IntTag: Type[Int] = new TaggedType[Int] + implicit val LongTag: Type[Long] = new TaggedType[Long] + implicit val FloatTag: Type[Float] = new TaggedType[Float] + implicit val DoubleTag: Type[Double] = new TaggedType[Double] } } diff --git a/library/src/scala/Eql.scala b/library/src/scala/Eql.scala index d9ef982e6827..ed62938267d3 100644 --- a/library/src/scala/Eql.scala +++ b/library/src/scala/Eql.scala @@ -12,12 +12,12 @@ sealed trait Eql[-L, -R] * the compiler (see Implicits.synthesizedEq), so they are not included here. */ object Eql { - /** A non-implied universal `Eql` instance. */ + /** A universal `Eql` instance. */ object derived extends Eql[Any, Any] /** A fall-back instance to compare values of any types. - * Even though this method is not declared implied, the compiler will - * compute implied instances as solutions to `Eql[T, U]` queries if + * Even though this method is not declared a delegate, the compiler will + * synthesize implicit arguments as solutions to `Eql[T, U]` queries if * the rules of multiversal equality require it. */ def eqlAny[L, R]: Eql[L, R] = derived diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index 689b9500653c..047d2ffd85a5 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -209,7 +209,7 @@ trait Core { /** Tree representing a pattern match `x match { ... }` in the source code */ type Match = kernel.Match - /** Tree representing a pattern match `implied match { ... }` in the source code */ + /** Tree representing a pattern match `delegate match { ... }` in the source code */ type ImpliedMatch = kernel.ImpliedMatch /** Tree representing a try catch `try x catch { ... } finally { ... }` in the source code */ diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 9a91663dc4af..18e4ba66acb6 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -476,7 +476,7 @@ trait Kernel { def Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match - /** Tree representing a pattern match `implied match { ... }` in the source code */ + /** Tree representing a pattern match `delegate match { ... }` in the source code */ type ImpliedMatch <: Term def matchImplicitMatch(tree: Tree)(implicit ctx: Context): Option[ImpliedMatch] diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index 0d4fd82517b9..f27106fe0a43 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -554,7 +554,7 @@ trait Printers case Import(importImplied, expr, selectors) => this += "import " - if (importImplied) this += "implied " + if (importImplied) this += "delegate " printTree(expr) this += "." printImportSelectors(selectors) @@ -910,7 +910,7 @@ trait Printers inBlock(printCases(cases, lineBreak())) case ImpliedMatch(cases) => - this += highlightKeyword("implied match", color) + this += highlightKeyword("delegate match", color) inBlock(printCases(cases, lineBreak())) case Try(body, cases, finallyOpt) => diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 886facf2f430..adf164a7caf5 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -635,14 +635,14 @@ trait TreeOps extends Core { /** Scala implicit `match` term */ object ImpliedMatch { - /** Creates a pattern match `implied match { }` */ + /** Creates a pattern match `delegate match { }` */ def apply(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch = kernel.ImplicitMatch_apply(cases) def copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch = kernel.ImplicitMatch_copy(original)(cases) - /** Matches a pattern match `implied match { }` */ + /** Matches a pattern match `delegate match { }` */ def unapply(tree: Tree)(implicit ctx: Context): Option[List[CaseDef]] = kernel.matchImplicitMatch(tree).map(_.cases) diff --git a/library/src/scalaShadowing/language.scala b/library/src/scalaShadowing/language.scala index f2d655c0fdcf..c81e833b7f52 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, implied instances of the scala.Conversion class can be + * classes. In particular, delegates 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 { - * implied a2b for Conversion[A, B] { ... } + * delegate a2b for Conversion[A, B] { ... } * } * object C { - * implied b2a for Conversion[B, A] { ... } + * delegate b2a for Conversion[B, A] { ... } * } - * import implied B._ - * import implied C._ + * import delegate B._ + * import delegate 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/invalid/neg/implicitMatch-ambiguous.scala b/tests/invalid/neg/implicitMatch-ambiguous.scala index d898b4025db9..a0b848bf95fd 100644 --- a/tests/invalid/neg/implicitMatch-ambiguous.scala +++ b/tests/invalid/neg/implicitMatch-ambiguous.scala @@ -4,7 +4,7 @@ object Test { implicit val a1: A = new A implicit val a2: A = new A - inline def f: Any = implied match { + inline def f: Any = delegate match { case _: A => ??? // error: ambiguous implicits } diff --git a/tests/invalid/run/typelevel.scala b/tests/invalid/run/typelevel.scala index 1461dc1b3a38..aa712e0e6dbd 100644 --- a/tests/invalid/run/typelevel.scala +++ b/tests/invalid/run/typelevel.scala @@ -153,7 +153,7 @@ object Test extends App { case S[type N] => toInt[N] + 1 } - inline def toInt1[T]: Nat = implied match { + inline def toInt1[T]: Nat = delegate match { case C[type T, type U], T =:= U => case T <:< S[type N] => toInt[N] + 1 } diff --git a/tests/neg-custom-args/conditionalWarnings.scala b/tests/neg-custom-args/conditionalWarnings.scala index af873dee5357..fc6290c93eb7 100644 --- a/tests/neg-custom-args/conditionalWarnings.scala +++ b/tests/neg-custom-args/conditionalWarnings.scala @@ -3,7 +3,7 @@ object Test { @deprecated def foo = ??? - implied for Conversion[String, Int] = _.length + delegate for 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 a878b1112573..5385b8cde5d9 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 { - implied for Conversion[A, B] { + delegate for Conversion[A, B] { def apply(x: A): B = ??? } - implied for Conversion[B, A] { + delegate for Conversion[B, A] { def apply(x: B): A = ??? } } @@ -15,13 +15,13 @@ object A { class C object D { - implied for Conversion[A, C] { + delegate for Conversion[A, C] { def apply(x: A): C = ??? } } object Test { - import implied D._ + import delegate D._ val x1: A = new B val x2: B = new A // error under -Xfatal-warnings -feature diff --git a/tests/neg/derive-eq.scala b/tests/neg/derive-eq.scala index f12761036aee..d1f46f8bd655 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 -implied for Eql[One, Two] = Eql.derived +delegate for 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 f3dc4fcde8ce..9c4ac30bfec8 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 implied --- Error: tests/neg/exports.scala:26:29 -------------------------------------------------------------------------------- -26 | export implied printUnit.status // error: no eligible member - | ^^^^^^ - | no eligible member status at this.printUnit - | this.printUnit.status cannot be exported because it is not implied + | 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 -- [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 2f5f583d39ff..70cfc3e62efc 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] = ??? - implied bitmap for BitMap + delegate bitmap for 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 implied printUnit.status // error: no eligible member + export delegate 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 836b1b14474c..0ea9f09121d0 100644 --- a/tests/neg/extmethod-overload.scala +++ b/tests/neg/extmethod-overload.scala @@ -1,8 +1,8 @@ object Test { - implied A { + delegate A { def (x: Int) |+| (y: Int) = x + y } - implied B { + delegate 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 05c2c17cb4a8..5be4f337b87b 100644 --- a/tests/neg/i5455.scala +++ b/tests/neg/i5455.scala @@ -11,7 +11,7 @@ object Library { def toInt(n: Nat): Int = n } - implied NatOps { + delegate NatOps { def (x: Nat) * (y: Nat): Nat = x * y def (x: Nat) toInt: Int = x } diff --git a/tests/neg/i5978.scala b/tests/neg/i5978.scala index 7543ae141cd7..0d1ee5616d74 100644 --- a/tests/neg/i5978.scala +++ b/tests/neg/i5978.scala @@ -5,9 +5,9 @@ opaque type Position[Buffer] = Int trait TokenParser[Token, R] object TextParser { - implied TP for TokenParser[Char, Position[CharSequence]] {} + delegate TP for TokenParser[Char, Position[CharSequence]] {} - implied FromCharToken for Conversion[Char, Position[CharSequence]] + delegate FromCharToken for Conversion[Char, Position[CharSequence]] given (T: TokenParser[Char, Position[CharSequence]]) = ??? } @@ -22,7 +22,7 @@ object Testcase { val co_x : Position[CharSequence] = 'x' // error { - implied XXX for Conversion[Char, Position[CharSequence]] = co_i + delegate XXX for Conversion[Char, Position[CharSequence]] = co_i val co_y : Position[CharSequence] = 'x' } } diff --git a/tests/neg/implicit-match-ambiguous-bind.scala b/tests/neg/implicit-match-ambiguous-bind.scala index a54374f745d4..fdac7f8261e5 100644 --- a/tests/neg/implicit-match-ambiguous-bind.scala +++ b/tests/neg/implicit-match-ambiguous-bind.scala @@ -2,7 +2,7 @@ object `implicit-match-ambiguous-bind` { case class Box[T](value: T) implicit val ibox: Box[Int] = Box(0) implicit val sbox: Box[String] = Box("") - inline def unbox = implied match { + inline def unbox = delegate match { case b: Box[t] => b.value // error } val unboxed = unbox diff --git a/tests/neg/implicit-params.scala b/tests/neg/implicit-params.scala index dfeb802541d0..edaa13b3f09d 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 - implied C for C(11) - implied D for D(11) + delegate C for C(11) + delegate D for D(11) f(1) f(1) given C diff --git a/tests/neg/implicitMatch-syntax.scala b/tests/neg/implicitMatch-syntax.scala index f6e565e018c1..3e5f8969456a 100644 --- a/tests/neg/implicitMatch-syntax.scala +++ b/tests/neg/implicitMatch-syntax.scala @@ -2,32 +2,32 @@ object Test { import collection.immutable.TreeSet import collection.immutable.HashSet - inline def f1[T] = implied implied match { // error: illegal modifier // error: ';' expected, but 'match' found // error: Declaration of method f1 not allowed here + inline def f1[T] = delegate delegate match { // error: illegal modifier // error: ';' expected, but 'match' found // error: Declaration of method f1 not allowed here case ord: Ordered[T] => new TreeSet[T] case _ => new HashSet[T] } - inline def f2[T] = implied erased match { // error: illegal modifier // error: illegal modifier // error: Declaration of method f1 not allowed here + inline def f2[T] = delegate erased match { // error: illegal modifier // error: illegal modifier // error: Declaration of method f1 not allowed here case ord: Ordered[T] => new TreeSet[T] case _ => new HashSet[T] } - inline def f3[T] = erased implied match { // error: illegal modifier + inline def f3[T] = erased delegate match { // error: illegal modifier case ord: Ordered[T] => new TreeSet[T] case _ => new HashSet[T] } - inline def f4() = implied match { + inline def f4() = delegate match { case Nil => ??? // error: not a legal pattern case x :: xs => ??? // error: not a legal pattern } - inline def f5[T] = locally { implied match { // Ok + inline def f5[T] = locally { delegate match { // Ok case _ => new HashSet[T] }} - def f6[T] = implied match { // error: implied match cannot be used here + def f6[T] = delegate match { // error: delegate match cannot be used here case _ => new HashSet[T] } } \ No newline at end of file diff --git a/tests/neg/implied-for.scala b/tests/neg/implied-for.scala index a5aa18bb59ef..c7c3da59de76 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 { - implied b for B - implied c for C + delegate b for B + delegate c for C } object Test extends App { import A._ - import implied A.{for B} + import delegate 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 2dbbd6763625..b2e5e9b67b06 100644 --- a/tests/neg/import-implied.scala +++ b/tests/neg/import-implied.scala @@ -1,6 +1,6 @@ class TC object A { - implied tc for TC + delegate tc for TC def foo given TC = () } object B { @@ -11,19 +11,19 @@ object B { } object C { import A._ - import implied A.tc + import delegate A.tc foo // ok foo given tc // ok } object D { import A.foo - import implied A._ + import delegate A._ foo // ok foo given tc // ok } object E { import A._ - import implied A._ + import delegate 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 1d943c7b591a..d1d81b63ad3d 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 { - implied isOff for IsOff[Off] = new IsOff[Off] + delegate isOff for IsOff[Off] = new IsOff[Off] } @implicitNotFound("State must be On") class IsOn[S <: State] object IsOn { - implied isOn for IsOn[On] = new IsOn[On] + delegate isOn for IsOn[On] = new IsOn[On] } class Machine[S <: State] { diff --git a/tests/neg/overloading-specifity.scala b/tests/neg/overloading-specifity.scala index d794313b45d4..21b8c18645dd 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 - //implied ctx for Context + //delegate ctx for Context object a { def foo[T](implicit gen: Generic): Show[T] = new Show[T](1) diff --git a/tests/neg/typeclass-derivation2.scala b/tests/neg/typeclass-derivation2.scala index 010d96d9ad62..440a4608d434 100644 --- a/tests/neg/typeclass-derivation2.scala +++ b/tests/neg/typeclass-derivation2.scala @@ -213,7 +213,7 @@ object Show { import scala.compiletime.{erasedValue, error} import TypeLevel._ - inline def tryShow[T](x: T): String = implied match { + inline def tryShow[T](x: T): String = delegate match { case s: Show[T] => s.show(x) } diff --git a/tests/new/test.scala b/tests/new/test.scala index 728f2173d100..a380bf890f95 100644 --- a/tests/new/test.scala +++ b/tests/new/test.scala @@ -4,10 +4,10 @@ trait T { object Test0 { trait A[T] - implied a[T] for A[T] + delegate a[T] for A[T] class B[T] - implied b[T] for B[T] + delegate b[T] for B[T] } class C extends T diff --git a/tests/pending/pos/implicit-match.scala b/tests/pending/pos/implicit-match.scala index b98b55b32187..ffba877f7985 100644 --- a/tests/pending/pos/implicit-match.scala +++ b/tests/pending/pos/implicit-match.scala @@ -1,9 +1,9 @@ -// implied matches that bind parameters don't work yet. +// delegate matches that bind parameters don't work yet. object `implicit-match` { object invariant { case class Box[T](value: T) implicit val box: Box[Int] = Box(0) - inline def unbox <: Any = implied match { + inline def unbox <: Any = delegate match { case b: Box[t] => b.value } val i: Int = unbox @@ -14,7 +14,7 @@ object `implicit-match` { object covariant { case class Box[+T](value: T) implicit val box: Box[Int] = Box(0) - inline def unbox <: Any = implied match { + inline def unbox <: Any = delegate match { case b: Box[t] => b.value } val i: Int = unbox @@ -25,7 +25,7 @@ object `implicit-match` { object contravariant { case class TrashCan[-T](trash: T => Unit) implicit val trashCan: TrashCan[Int] = TrashCan { i => ; } - inline def trash <: Nothing => Unit = implied match { + inline def trash <: Nothing => Unit = delegate match { case c: TrashCan[t] => c.trash } val t1: Int => Unit = trash diff --git a/tests/pos-special/typeclass-scaling.scala b/tests/pos-special/typeclass-scaling.scala index 15e56e06601b..0f4dab284bcc 100644 --- a/tests/pos-special/typeclass-scaling.scala +++ b/tests/pos-special/typeclass-scaling.scala @@ -217,7 +217,7 @@ object typeclasses { import compiletime._ import scala.deriving._ - inline def tryEql[TT](x: TT, y: TT): Boolean = implied match { + inline def tryEql[TT](x: TT, y: TT): Boolean = delegate match { case eq: Eq[TT] => eq.eql(x, y) } @@ -237,7 +237,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => eqlElems[m.MirroredElemTypes](0)(x, y) } else eqlCases[alts1](n + 1)(x, y, ord) @@ -274,7 +274,7 @@ object typeclasses { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = delegate match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -290,14 +290,14 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => pickleElems[m.MirroredElemTypes](0)(buf, x) } else pickleCases[alts1](n + 1)(buf, x, ord) case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = delegate match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -324,7 +324,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt` & T] => unpickleCase[`alt` & T, m.MirroredElemTypes](buf, m) } diff --git a/tests/pos-with-compiler/DecoratorsX.scala b/tests/pos-with-compiler/DecoratorsX.scala index 47a77fa88810..c516aa9b290f 100644 --- a/tests/pos-with-compiler/DecoratorsX.scala +++ b/tests/pos-with-compiler/DecoratorsX.scala @@ -20,11 +20,11 @@ object DecoratorsX { def toTermName: TermName = termName(s) def toText(printer: Printer): Text = Str(s) } - implied for Conversion[String, StringPreName] = new StringPreName(_) + delegate for Conversion[String, StringPreName] = new StringPreName(_) final val MaxFilterRecursions = 1000 - implied { + delegate { def (s: String) splitWhere (f: Char => Boolean, doDropIndex: Boolean): Option[(String, String)] = { def splitAt(idx: Int, doDropIndex: Boolean): Option[(String, String)] = if (idx == -1) None diff --git a/tests/pos/cm/ConfManagement.scala b/tests/pos/cm/ConfManagement.scala index 2a7e37dd0ae1..276918537c9e 100644 --- a/tests/pos/cm/ConfManagement.scala +++ b/tests/pos/cm/ConfManagement.scala @@ -6,8 +6,8 @@ case class Paper(title: String, authors: List[Person], body: String) class Viewers(val persons: Set[Person]) class ConfManagement(papers: List[Paper], realScore: Map[Paper, Int]) { - - private def hasConflict(ps1: Set[Person], ps2: Iterable[Person]) = + + private def hasConflict(ps1: Set[Person], ps2: Iterable[Person]) = ps2.exists(ps1 contains _) def viewers(implicit vs: Viewers): Set[Person] = @@ -20,6 +20,6 @@ class ConfManagement(papers: List[Paper], realScore: Map[Paper, Int]) { def viewRankings(implicit vs: Viewers): List[Paper] = papers.sortBy(score(_)) - def delegate[T](query: Viewers => T, p: Person)(implicit vs: Viewers): T = + def delegateTo[T](query: Viewers => T, p: Person)(implicit vs: Viewers): T = query(new Viewers(viewers + p)) } \ No newline at end of file diff --git a/tests/pos/derive-eq.scala b/tests/pos/derive-eq.scala index 5d590a3342e7..a336aa3af870 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 -implied for Eql[One, Two] = Eql.derived +delegate for 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 798d0411d5ff..5a55303feddc 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) = { - implied for Context = this + delegate for Context = this op } } diff --git a/tests/pos/i2774.scala b/tests/pos/i2774.scala index 0ddd557013d4..82d6184f6e2b 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 - implied for Q = new Q {} + delegate for Q = new Q {} val i1: Int = a given (new T{}) - implied for T = new T {} + delegate for T = new T {} val i2: Int = a val i3: Int = a2 diff --git a/tests/pos/i5915.scala b/tests/pos/i5915.scala index 6dfc7b7425d0..01bc2f689d9c 100644 --- a/tests/pos/i5915.scala +++ b/tests/pos/i5915.scala @@ -2,8 +2,8 @@ trait RunDSL val rdsl = new RunDSL {} -implied RunNNFExpr[B] for RunDSL = rdsl +delegate RunNNFExpr[B] for RunDSL = rdsl -implied RunNNFImpl[B] for RunDSL { +delegate RunNNFImpl[B] for RunDSL { //override def runDSL(b: NNF[B]): B = b.terminal } \ No newline at end of file diff --git a/tests/pos/i5938.scala b/tests/pos/i5938.scala index 2774abf7414d..900b1141f683 100644 --- a/tests/pos/i5938.scala +++ b/tests/pos/i5938.scala @@ -1,8 +1,8 @@ trait Link[T, A] -inline def link[T] = implied match { +inline def link[T] = delegate match { case _: Link[T, s] => - implied match { + delegate match { case stuff: s => stuff } } diff --git a/tests/pos/i5966.scala b/tests/pos/i5966.scala index b8757204913c..1a505b6edbfd 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 - implied myInt for Int = 4 + delegate myInt for Int = 4 foo.apply(1) foo given 2 diff --git a/tests/pos/i5978.scala b/tests/pos/i5978.scala index 4daf73e09fd1..af94fdf53028 100644 --- a/tests/pos/i5978.scala +++ b/tests/pos/i5978.scala @@ -7,16 +7,16 @@ trait TokenParser[Token, R] package p1 { object TextParser { - implied TP for TokenParser[Char, Position[CharSequence]] {} + delegate TP for TokenParser[Char, Position[CharSequence]] {} - implied FromCharToken for Conversion[Char, Position[CharSequence]] + delegate FromCharToken for Conversion[Char, Position[CharSequence]] given (T: TokenParser[Char, Position[CharSequence]])= ??? } object Testcase { def main(args: Array[String]): Unit = { - import implied TextParser._ + import delegate TextParser._ import TextParser._ val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP @@ -25,7 +25,7 @@ package p1 { val co_x : Position[CharSequence] = 'x' { - implied XXX for Conversion[Char, Position[CharSequence]] = co_i + delegate XXX for Conversion[Char, Position[CharSequence]] = co_i val co_y : Position[CharSequence] = 'x' } } @@ -42,7 +42,7 @@ package p2 { object Testcase { def main(args: Array[String]): Unit = { import TextParser._ - import implied TextParser._ + import delegate TextParser._ val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP val tp_i = the[TokenParser[Char, Position[CharSequence]]] @@ -60,7 +60,7 @@ package p3 { object Testcase { def main(args: Array[String]): Unit = { - import implied TextParser._ + import delegate TextParser._ import TextParser._ val co_i: Conversion[Char, Position[CharSequence]] = the[Conversion[Char, Position[CharSequence]]] @@ -68,11 +68,11 @@ package p3 { { val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP val tp_i = the[TokenParser[Char, Position[CharSequence]]] - implied for Conversion[Char, Position[CharSequence]] = co_i + delegate for Conversion[Char, Position[CharSequence]] = co_i val co_x : Position[CharSequence] = 'x' { - implied XXX for Conversion[Char, Position[CharSequence]] = co_i + delegate XXX for Conversion[Char, Position[CharSequence]] = co_i val co_y : Position[CharSequence] = 'x' } } diff --git a/tests/pos/i6014-gadt.scala b/tests/pos/i6014-gadt.scala index 8bbf3f629245..382de8a27582 100644 --- a/tests/pos/i6014-gadt.scala +++ b/tests/pos/i6014-gadt.scala @@ -10,7 +10,7 @@ object Test1 { } object Test2 { - inline def summon[T] = implied match { + inline def summon[T] = delegate match { case t: T => t } @@ -25,7 +25,7 @@ object Test2 { } object Test3 { - inline def summon[T] = implied match { + inline def summon[T] = delegate match { case t: T => t } @@ -42,7 +42,7 @@ object Test3 { } object Test4 { - inline def summon[T] = implied match { + inline def summon[T] = delegate match { case t: T => t } diff --git a/tests/pos/i6373.scala b/tests/pos/i6373.scala index 68a2abb59068..3975d1e4076e 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 - implied ctx for Context = new Context(true) + delegate ctx for Context = new Context(true) f() } diff --git a/tests/pos/implicit-conversion.scala b/tests/pos/implicit-conversion.scala index bffc6745060c..d7d2aa4d87ef 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? - implied for Conversion[String, Int] { + delegate for Conversion[String, Int] { def apply(x: String): Int = Integer.parseInt(toString) } } \ No newline at end of file diff --git a/tests/pos/implicit-match-and-inline-match.scala b/tests/pos/implicit-match-and-inline-match.scala index 3d930a44a281..360f239a5415 100644 --- a/tests/pos/implicit-match-and-inline-match.scala +++ b/tests/pos/implicit-match-and-inline-match.scala @@ -5,7 +5,7 @@ object `implicit-match-and-inline-match` { implicit val ibox: Box[Int] = Box(0) object a { - inline def isTheBoxInScopeAnInt = implied match { + inline def isTheBoxInScopeAnInt = delegate match { case _: Box[t] => inline erasedValue[t] match { case _: Int => true } @@ -14,7 +14,7 @@ object `implicit-match-and-inline-match` { } object b { - inline def isTheBoxInScopeAnInt = implied match { + inline def isTheBoxInScopeAnInt = delegate match { case _: Box[t] => inline 0 match { case _: t => true } diff --git a/tests/pos/implicit-match-nested.scala b/tests/pos/implicit-match-nested.scala index 0365c54d3704..32675edf3084 100644 --- a/tests/pos/implicit-match-nested.scala +++ b/tests/pos/implicit-match-nested.scala @@ -6,8 +6,8 @@ object `implicit-match-nested` { implicit val b1: B[Int] = B[Int]() implicit val b2: B[String] = B[String]() - inline def locateB <: B[_] = implied match { - case _: A[t] => implied match { + inline def locateB <: B[_] = delegate match { + case _: A[t] => delegate match { case b: B[`t`] => b } } diff --git a/tests/pos/implicitFuns.scala b/tests/pos/implicitFuns.scala index 7eb2ca40f58b..9f4b0aef822a 100644 --- a/tests/pos/implicitFuns.scala +++ b/tests/pos/implicitFuns.scala @@ -24,7 +24,7 @@ class ConfManagement(papers: List[Paper], realScore: Map[Paper, Int]) extends Ap def viewRankings: Viewable[List[(String, Int)]] = papers.sortBy(-score(_)).map(p => (p.title, score(p))) - def delegate[T]: (Viewers => T) => Person => Viewable[T] = + def delegateTo[T]: (Viewers => T) => Person => Viewable[T] = query => p => query(new Viewers(viewers + p)) } diff --git a/tests/pos/inline-separate/A_1.scala b/tests/pos/inline-separate/A_1.scala index 67a163f5cb0a..b5eb1437f427 100644 --- a/tests/pos/inline-separate/A_1.scala +++ b/tests/pos/inline-separate/A_1.scala @@ -1,5 +1,5 @@ object A { - inline def summon[T] = implied match { + inline def summon[T] = delegate match { case t: T => t } } diff --git a/tests/pos/inlined-the.scala b/tests/pos/inlined-the.scala index 860ee8e64e1f..4f9791ecde0b 100644 --- a/tests/pos/inlined-the.scala +++ b/tests/pos/inlined-the.scala @@ -5,7 +5,7 @@ object Instances { class C { def f() = { locally { - implied d[T] for D[T] + delegate d[T] for D[T] the[D[Int]] implicit val s: 3 = ??? val a: 3 = the[3] @@ -14,7 +14,7 @@ object Instances { } locally { - implied d[T] for D[T] + delegate d[T] for 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 cbe295ff1ed4..a7d5ec8d72b6 100644 --- a/tests/pos/multiversal.scala +++ b/tests/pos/multiversal.scala @@ -1,7 +1,7 @@ object Test { import scala.Eql - implied [X, Y] for Eql[List[X], List[Y]] given Eql[X, Y] = Eql.derived + delegate [X, Y] for 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 9a8e53238e88..31feca510f76 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 = { - implied for WrappedResult[T] = x + delegate for WrappedResult[T] = x assert(condition) x } diff --git a/tests/pos/reference/instances.scala b/tests/pos/reference/instances.scala index 2be625f1460b..a919c208a5fe 100644 --- a/tests/pos/reference/instances.scala +++ b/tests/pos/reference/instances.scala @@ -32,12 +32,12 @@ class Common { object Instances extends Common { - implied IntOrd for Ord[Int] { + delegate IntOrd for Ord[Int] { def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 } - implied ListOrd[T] for Ord[List[T]] given Ord[T] { + delegate ListOrd[T] for Ord[List[T]] given Ord[T] { def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -48,25 +48,25 @@ object Instances extends Common { } } - implied StringOps { + delegate StringOps { def (xs: Seq[String]) longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) } } - implied ListOps { + delegate ListOps { def (xs: List[T]) second[T] = xs.tail.head } - implied ListMonad for Monad[List] { + delegate ListMonad for 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) } - implied ReaderMonad[Ctx] for Monad[[X] =>> Ctx => X] { + delegate ReaderMonad[Ctx] for 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 = @@ -105,7 +105,7 @@ object Instances extends Common { def (sym: Symbol) name: String } def symDeco: SymDeco - implied for SymDeco = symDeco + delegate for SymDeco = symDeco } object TastyImpl extends TastyAPI { type Symbol = String @@ -119,20 +119,20 @@ object Instances extends Common { class C given (ctx: Context) { def f() = { locally { - implied for Context = this.ctx + delegate for Context = this.ctx println(the[Context].value) } locally { lazy val ctx1 = this.ctx - implied for Context = ctx1 + delegate for Context = ctx1 println(the[Context].value) } locally { - implied d[T] for D[T] + delegate d[T] for D[T] println(the[D[Int]]) } locally { - implied for D[Int] given Context + delegate for D[Int] given Context println(the[D[Int]]) } } @@ -141,7 +141,7 @@ object Instances extends Common { class Token(str: String) object Token { - implied StringToToken for Conversion[String, Token] { + delegate StringToToken for Conversion[String, Token] { def apply(str: String): Token = new Token(str) } } @@ -152,14 +152,14 @@ object Instances extends Common { object PostConditions { opaque type WrappedResult[T] = T - private implied WrappedResult { + private delegate WrappedResult { def apply[T](x: T): WrappedResult[T] = x def (x: WrappedResult[T]) unwrap[T]: T = x } def result[T] given (wrapped: WrappedResult[T]): T = wrapped.unwrap - implied { + delegate { def (x: T) ensuring[T] (condition: given WrappedResult[T] => Boolean): T = { assert(condition given WrappedResult(x)) x @@ -168,12 +168,12 @@ object PostConditions { } object AnonymousInstances extends Common { - implied for Ord[Int] { + delegate for Ord[Int] { def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 } - implied [T: Ord] for Ord[List[T]] { + delegate [T: Ord] for Ord[List[T]] { def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -184,22 +184,22 @@ object AnonymousInstances extends Common { } } - implied { + delegate { def (xs: Seq[String]) longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) } } - implied { + delegate { def (xs: List[T]) second[T] = xs.tail.head } - implied [From, To] for Convertible[List[From], List[To]] given (c: Convertible[From, To]) { + delegate [From, To] for Convertible[List[From], List[To]] given (c: Convertible[From, To]) { def (x: List[From]) convert: List[To] = x.map(c.convert) } - implied for Monoid[String] { + delegate for Monoid[String] { def (x: String) combine (y: String): String = x.concat(y) def unit: String = "" } @@ -249,7 +249,7 @@ object Implicits extends Common { object Test extends App { Instances.test() import PostConditions.result - import implied PostConditions._ + import delegate PostConditions._ val s = List(1, 2, 3).sum s.ensuring(result == 6) } @@ -274,9 +274,9 @@ object Completions { // // CompletionArg.from(statusCode) - implied fromString for Conversion[String, CompletionArg] = Error(_) - implied fromFuture for Conversion[Future[HttpResponse], CompletionArg] = Response(_) - implied fromStatusCode for Conversion[Future[StatusCode], CompletionArg] = Status(_) + delegate fromString for Conversion[String, CompletionArg] = Error(_) + delegate fromFuture for Conversion[Future[HttpResponse], CompletionArg] = Response(_) + delegate fromStatusCode for Conversion[Future[StatusCode], CompletionArg] = Status(_) } import CompletionArg._ diff --git a/tests/pos/reference/opaque.scala b/tests/pos/reference/opaque.scala index 7ffd50a06e6e..35b36806e2a5 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 - implied LogarithmOps { + delegate 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 0d4b1058b089..e640fc1d596d 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 } - implied for Encoder + delegate for Encoder the[Encoder](2) diff --git a/tests/pos/the.scala b/tests/pos/the.scala index 68c399055af8..ca78bc904fb7 100644 --- a/tests/pos/the.scala +++ b/tests/pos/the.scala @@ -2,7 +2,7 @@ object Test { trait Foo { type T; val x: T } - implied intFoo for Foo { + delegate intFoo for Foo { type T = Int val x = 3 } diff --git a/tests/pos/wildcardBoundInference.scala b/tests/pos/wildcardBoundInference.scala index 65553ed93619..1cd3495d652f 100644 --- a/tests/pos/wildcardBoundInference.scala +++ b/tests/pos/wildcardBoundInference.scala @@ -57,13 +57,13 @@ object ObjectProperty { implicit def jfxObjectProperty2sfx[T](p: OP[T]): ObjectProperty[T] = new ObjectProperty[T](p) } -class ObjectProperty[T](val delegate: OP[T]) +class ObjectProperty[T](val deleg: OP[T]) trait TestWildcardBoundInference { - def delegate: Skinnable - def skin: ObjectProperty[Skin[_ /* inferred: <: Skinnable */]] = ObjectProperty.jfxObjectProperty2sfx(delegate.skinProperty) + def deleg: Skinnable + def skin: ObjectProperty[Skin[_ /* inferred: <: Skinnable */]] = ObjectProperty.jfxObjectProperty2sfx(deleg.skinProperty) skin: ObjectProperty[Skin[_ <: Skinnable]] - def skinCheckInference = delegate.skinProperty + def skinCheckInference = deleg.skinProperty skinCheckInference: ObjectProperty[Skin[_ <: Skinnable]] } diff --git a/tests/run/cochis-example.scala b/tests/run/cochis-example.scala index bb106eb2046f..5e8d542fc89e 100644 --- a/tests/run/cochis-example.scala +++ b/tests/run/cochis-example.scala @@ -1,11 +1,11 @@ import Predef.{$conforms => _} trait A { - implied id[X] for (X => X) = x => x + delegate id[X] for (X => X) = x => x def trans[X](x: X) given (f: X => X) = f(x) // (2) } object Test extends A with App{ - implied succ for (Int => Int) = x => x + 1 // (3) + delegate succ for (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/companion-loading.scala b/tests/run/companion-loading.scala index 3a8dca013a30..d0480ff4faf3 100644 --- a/tests/run/companion-loading.scala +++ b/tests/run/companion-loading.scala @@ -19,9 +19,9 @@ implicit object FooAssoc extends Assoc[Foo] { def foo(t: Foo): Int = t.i } -inline def link[T] = implied match { +inline def link[T] = delegate match { case _: Link[T, s] => - implied match { + delegate match { case stuff: s => stuff } } diff --git a/tests/run/derive-multi.scala b/tests/run/derive-multi.scala index b78e48aa3843..a554235d8309 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 -implied for B[One, Two] { +delegate for 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 implied Lst._ + import delegate Lst._ implicitly[A] } diff --git a/tests/run/exports.scala b/tests/run/exports.scala index ea8cf62353f2..7611e9fd1939 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 - implied config for Config + delegate config for Config } class Scanner { @@ -19,7 +19,7 @@ object Test extends App { object Copier { val printer = new Printer export printer._ - export implied printer._ + export delegate printer._ export Scanner.{scan => scanIt, _} val config2 = the[Config] diff --git a/tests/run/extmethod-overload.scala b/tests/run/extmethod-overload.scala index 1f2ce77f292e..638d8598fb5e 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 implied object + // Test with extension methods in delegate object object test1 { - implied Foo { + delegate 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 implied extension methods coming from base class + // Test with delegate 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 } - implied Bar for Foo + delegate Bar for Foo assert((1 |+| 2) == 3) assert((1 |+| "2") == 2) @@ -72,9 +72,9 @@ object Test extends App { } test3 - // Test with implied extension methods coming from implied alias + // Test with delegate extension methods coming from delegate alias object test4 { - implied for test3.Foo = test3.Bar + delegate for 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 } - implied { + delegate { def (x: Int) yy (y: Int) = x - y } diff --git a/tests/run/extmethods2.scala b/tests/run/extmethods2.scala index febfc169bcf4..211c5483c4e3 100644 --- a/tests/run/extmethods2.scala +++ b/tests/run/extmethods2.scala @@ -2,7 +2,7 @@ object Test extends App { class TC - implied StringListOps given TC { + delegate 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/future-flatmap-exec-count.scala b/tests/run/future-flatmap-exec-count.scala index 849beb6b16c8..0c6f69f853b3 100644 --- a/tests/run/future-flatmap-exec-count.scala +++ b/tests/run/future-flatmap-exec-count.scala @@ -41,13 +41,13 @@ object Test { } } - class TestExecutionContext(delegate: ExecutionContext) extends ExecutionContext { + class TestExecutionContext(deleg: ExecutionContext) extends ExecutionContext { def execute(runnable: Runnable): Unit = ??? def reportFailure(t: Throwable): Unit = ??? override def prepare(): ExecutionContext = { - val preparedDelegate = delegate.prepare() + val preparedDelegate = deleg.prepare() return new ExecutionContext { def execute(runnable: Runnable): Unit = { println("execute()") diff --git a/tests/run/i2567.scala b/tests/run/i2567.scala index aef27f2e0cd6..8cf54d63bd07 100644 --- a/tests/run/i2567.scala +++ b/tests/run/i2567.scala @@ -1,5 +1,5 @@ class TC -implied tc for TC +delegate tc for TC class Foo given TC { println("hi") diff --git a/tests/run/implicit-alias.scala b/tests/run/implicit-alias.scala index 56cd96edc951..fc128d537c15 100644 --- a/tests/run/implicit-alias.scala +++ b/tests/run/implicit-alias.scala @@ -5,13 +5,13 @@ object Test extends App { } class TC1 - implied for TC1 + delegate for TC1 class TV(val tc: TC) extends AnyVal trait C { val x: TC - implied for TC = x + delegate for TC = x the[TC] the[TC] } @@ -21,7 +21,7 @@ object Test extends App { locally{ println("= new") - implied t for TC = new TC + delegate t for TC = new TC the[TC] the[TC] } @@ -33,7 +33,7 @@ object Test extends App { locally{ println("= new VC") - implied t for TV = new TV(new TC) + delegate t for TV = new TV(new TC) the[TV] the[TV] } @@ -45,21 +45,21 @@ object Test extends App { val tcc = new TCC locally { println("= x.y") - implied t for TC = tcc.tc + delegate t for TC = tcc.tc the[TC] the[TC] } locally { println("with given") - implied t for TC given TC1 = new TC + delegate t for TC given TC1 = new TC the[TC] the[TC] } locally { println("with type params") - implied t[X] for TC = new TC + delegate t[X] for TC = new TC the[TC] the[TC] } diff --git a/tests/run/implicit-disambiguation.scala b/tests/run/implicit-disambiguation.scala index bc346da76e7e..856d115f0b78 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 = { - implied a for A = the[B] + delegate a for A = the[B] the[A].show } } object Test extends App { - implied b for B - implied c for C + delegate b for B + delegate c for C println(M.f) } diff --git a/tests/run/implicit-specifity.scala b/tests/run/implicit-specifity.scala index cc833cdc24d2..9a10f9cb6b09 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 - implied showInt for Show[Int] = new Show[Int](0) - implied fallback[T] for Show[T] = new Show[T](1) + delegate showInt for Show[Int] = new Show[Int](0) + delegate fallback[T] for Show[T] = new Show[T](1) } class Generic object Generic { - implied gen for Generic = new Generic - implied showGen[T] for Show[T] given Generic = new Show[T](2) + delegate gen for Generic = new Generic + delegate showGen[T] for Show[T] given Generic = new Show[T](2) } class Generic2 object Generic2 { opaque type HiPriority = AnyRef - implied showGen[T] for (Show[T] & HiPriority) = new Show[T](2).asInstanceOf + delegate showGen[T] for (Show[T] & HiPriority) = new Show[T](2).asInstanceOf } class SubGen extends Generic object SubGen { - implied for SubGen + delegate for SubGen } object Contextual { trait Context - implied ctx for Context - implied showGen[T] for Show[T] given Generic = new Show[T](2) - implied showGen[T] for Show[T] given Generic, Context = new Show[T](3) - implied showGen[T] for Show[T] given SubGen = new Show[T](4) + 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) } object Test extends App { diff --git a/tests/run/implied-divergence.scala b/tests/run/implied-divergence.scala index 2557a7433816..e99036cede11 100644 --- a/tests/run/implied-divergence.scala +++ b/tests/run/implied-divergence.scala @@ -2,11 +2,11 @@ // recursions. case class E(x: E | Null) -implied e for E(null) +delegate e for E(null) object Test extends App { - implied f for E(e) given (e: E) + delegate f for 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 9b4486ec33a7..1055d007bec3 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] - implied b for B - implied c for C - implied t for T - implied d for D[Int] + delegate b for B + delegate c for C + delegate t for T + delegate d for D[Int] } object Test extends App { import A._ - import implied A.{t, for B, D[_]} + import delegate A.{t, for B, D[_]} val x1: B = b val x2: T = t @@ -29,14 +29,14 @@ class ExecutionContext class Monoid[T] object Instances { - implied intOrd for Ordering[Int] - implied listOrd[T] for Ordering[List[T]] given Ordering[T] - implied ec for ExecutionContext - implied im for Monoid[Int] + delegate intOrd for Ordering[Int] + delegate listOrd[T] for Ordering[List[T]] given Ordering[T] + delegate ec for ExecutionContext + delegate im for Monoid[Int] } object Test2 { - import implied Instances.{for Ordering[_], ExecutionContext} + import delegate Instances.{for Ordering[_], ExecutionContext} val x = intOrd val y = listOrd[Int] val z = ec @@ -46,7 +46,7 @@ object Test2 { } object Test3 { - import implied Instances.{im, for Ordering[_]} + import delegate 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 1e7b83f376a3..535c72f76df3 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 implied instances below +class Arg[T] // An argument that we use as a given for some delegate instances below /* First, two schemes that require a pre-planned architecture for how and - * where implied instances are defined. + * where delegate instances are defined. * * Traditional scheme: prioritize with location in class hierarchy */ class LowPriorityImplicits { - implied t1[T] for E[T]("low") + delegate t1[T] for E[T]("low") } object NormalImplicits extends LowPriorityImplicits { - implied t2[T]for E[T]("norm") given Arg[T] + delegate t2[T]for E[T]("norm") given Arg[T] } def test1 = { - import implied NormalImplicits._ + import delegate NormalImplicits._ assert(the[E[String]].str == "low") // No Arg available, so only t1 applies - { implied for Arg[String] + { delegate for 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 { implied for Low } + object Low { delegate for Low } class High extends Low - object High { implied for High } + object High { delegate for High } } object Impl2 { - implied t1[T] for E[T]("low") given Priority.Low - implied t2[T] for E[T]("norm") given Priority.High given Arg[T] + delegate t1[T] for E[T]("low") given Priority.Low + delegate t2[T] for E[T]("norm") given Priority.High given Arg[T] } def test2 = { - import implied Impl2._ + import delegate Impl2._ assert(the[E[String]].str == "low") // No Arg available, so only t1 applies - { implied for Arg[String] + { delegate for 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 implied instances, without + * a fallback of lowest priority to a group of existing delegate 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 { - implied t3[T] for E[T]("hi") + delegate t3[T] for E[T]("hi") } def test2a = { - import implied Impl2._ - import implied Impl2a._ + import delegate Impl2._ + import delegate Impl2a._ - implied for Arg[String] + delegate for 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 implied instance, e.g. like this: + * result type of the delegate instance, e.g. like this: */ object Impl3 { - implied t1[T] for E[T]("low") + delegate t1[T] for E[T]("low") } object Override { trait HighestPriority // A marker trait to indicate a higher priority - implied over[T] for E[T]("hi"), HighestPriority + delegate over[T] for E[T]("hi"), HighestPriority } def test3 = { - import implied Impl3._ + import delegate Impl3._ assert(the[E[String]].str == "low") // only t1 is available - { import implied Override._ - import implied Impl3._ + { import delegate Override._ + import delegate 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 - * implied instances that kicks in when none of the other instances are applicable. + * delegate 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 { - implied t1 for E[String]("string") - implied t2[T] for E[T]("generic") given Arg[T] + delegate t1 for E[String]("string") + delegate t2[T] for E[T]("generic") given Arg[T] } object fallback4 { @@ -110,12 +110,12 @@ object fallback4 { } def test4 = { - import implied Impl4._ + import delegate Impl4._ import fallback4._ assert(withFallback[String].str == "string") // t1 is applicable assert(withFallback[Int].str == "fallback") // No applicable instances, pick the default - { implied for Arg[Int] + { delegate for Arg[Int] assert(withFallback[Int].str == "generic") // t2 is applicable } } @@ -133,19 +133,19 @@ object HigherPriority { } object fallback5 { - implied [T] for (E[T] & HigherPriority.Type) given (ev: E[T] = new E[T]("fallback")) = HigherPriority.inject(ev) + delegate [T] for (E[T] & HigherPriority.Type) given (ev: E[T] = new E[T]("fallback")) = HigherPriority.inject(ev) } def test5 = { - import implied Impl4._ - import implied fallback5._ + import delegate Impl4._ + import delegate fallback5._ - // All inferred terms go through the implied instance in fallback5. + // All inferred terms go through the delegate 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 - { implied for Arg[Int] + { delegate for 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 536a307fa271..fcc5edea4336 100644 --- a/tests/run/implied-specifity-2.scala +++ b/tests/run/implied-specifity-2.scala @@ -1,50 +1,50 @@ class Low object Low { - implied low for Low + delegate low for Low } class Medium extends Low object Medium { - implied medium for Medium + delegate medium for Medium } class High extends Medium object High { - implied high for High + delegate high for High } class Foo[T](val i: Int) object Foo { def apply[T] given (fooT: Foo[T]): Int = fooT.i - implied foo[T] for Foo[T](0) given Low - implied foobar[T] for Foo[Bar[T]](1) given Low - implied foobarbaz for Foo[Bar[Baz]](2) given Low + 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 } class Bar[T] object Bar { - implied foobar[T] for Foo[Bar[T]](3) given Medium - implied foobarbaz for Foo[Bar[Baz]](4) given Medium + delegate foobar[T] for Foo[Bar[T]](3) given Medium + delegate foobarbaz for Foo[Bar[Baz]](4) given Medium } class Baz object Baz { - implied baz for Foo[Bar[Baz]](5) given High + delegate baz for Foo[Bar[Baz]](5) given High } class Arg -implied for Arg +delegate for Arg class Bam(val str: String) -implied lo for Bam("lo") given Low -implied hi for Bam("hi") given High given Arg +delegate lo for Bam("lo") given Low +delegate hi for Bam("hi") given High given Arg class Bam2(val str: String) -implied lo2 for Bam2("lo") given Low -implied mid2 for Bam2("mid") given High given Arg -implied hi2 for Bam2("hi") +delegate lo2 for Bam2("lo") given Low +delegate mid2 for Bam2("mid") given High given Arg +delegate hi2 for Bam2("hi") class Arg2 class Red(val str: String) -implied normal for Red("normal") given Arg2 -implied reduced for Red("reduced") given (ev: Arg2 | Low) +delegate normal for Red("normal") given Arg2 +delegate reduced for Red("reduced") given (ev: Arg2 | Low) object Test extends App { assert(Foo[Int] == 0) @@ -54,7 +54,7 @@ object Test extends App { assert(the[Bam2].str == "hi") assert(the[Red].str == "reduced") - { implied for Arg2 + { delegate for Arg2 assert(the[Red].str == "normal") } } \ No newline at end of file diff --git a/tests/run/impliedMatch.scala b/tests/run/impliedMatch.scala index 671caad2f671..6b280b1efad5 100644 --- a/tests/run/impliedMatch.scala +++ b/tests/run/impliedMatch.scala @@ -2,12 +2,12 @@ object Test extends App { import collection.immutable.TreeSet import collection.immutable.HashSet - inline def f1[T]() = implied match { + inline def f1[T]() = delegate match { case ord: Ordering[T] => new TreeSet[T] case _ => new HashSet[T] } - inline def f2[T]() = implied match { + inline def f2[T]() = delegate match { case _: Ordering[T] => new TreeSet[T] case _ => new HashSet[T] } @@ -16,7 +16,7 @@ object Test extends App { class B implicit val b: B = new B - inline def g = implied match { + inline def g = delegate match { case _: A => println("A") case _: B => println("B") } diff --git a/tests/run/instances-anonymous.scala b/tests/run/instances-anonymous.scala index d29771db7b9d..469bd8ca2de3 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) - implied { + delegate { def (c: Circle) circumference: Double = c.radius * math.Pi * 2 } @@ -16,7 +16,7 @@ object Test extends App { println(circle.circumference) - implied { + delegate { 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")) - implied { + delegate { def (xs: Seq[T]) second[T] = xs.tail.head } assert(names.longestStrings.second == "world") - implied { + delegate { def (xs: List[List[T]]) flattened[T] = xs.foldLeft[List[T]](Nil)(_ ++ _) } @@ -45,8 +45,7 @@ object Test extends App { def unit: T } - // An implied declaration: - implied for Monoid[String] { + delegate for Monoid[String] { def (x: String) combine (y: String): String = x.concat(y) def unit: String = "" } @@ -64,13 +63,13 @@ object Test extends App { val minimum: T } - implied for Ord[Int] { + delegate for Ord[Int] { def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 val minimum = Int.MinValue } - implied [T: Ord] for Ord[List[T]] { + delegate [T: Ord] for Ord[List[T]] { def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -102,14 +101,14 @@ object Test extends App { def pure[A](x: A): F[A] } - implied for Monad[List] { + delegate for 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) } - implied [Ctx] for Monad[[X] =>> Ctx => X] { + delegate [Ctx] for 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 711675a51603..587b27cac00b 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) - implied CircleOps { + delegate 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)) - implied StringOps { + delegate 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")) - implied SeqOps { + delegate SeqOps { def (xs: Seq[T]) second[T] = xs.tail.head } assert(names.longestStrings.second == "world") - implied ListListOps { + delegate ListListOps { def (xs: List[List[T]]) flattened[T] = xs.foldLeft[List[T]](Nil)(_ ++ _) } // A right associative op - implied Prepend { + delegate Prepend { def (x: T) ::[T] (xs: Seq[T]) = x +: xs } val ss: Seq[Int] = List(1, 2, 3) @@ -53,8 +53,7 @@ object Test extends App { def unit: T } - // An implied declaration: - implied StringMonoid for Monoid[String] { + delegate StringMonoid for Monoid[String] { def (x: String) combine (y: String): String = x.concat(y) def unit: String = "" } @@ -72,13 +71,13 @@ object Test extends App { val minimum: T } - implied for Ord[Int] { + delegate for Ord[Int] { def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 val minimum = Int.MinValue } - implied ListOrd[T: Ord] for Ord[List[T]] { + delegate ListOrd[T: Ord] for Ord[List[T]] { def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -110,14 +109,14 @@ object Test extends App { def pure[A](x: A): F[A] } - implied ListMonad for Monad[List] { + delegate ListMonad for 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) } - implied ReaderMonad[Ctx] for Monad[[X] =>> Ctx => X] { + delegate ReaderMonad[Ctx] for 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 8f84fcb333de..9b4aa1495594 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 - implied ctx for Context + delegate ctx for 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 8d199a762fd0..10403fbf87cf 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 - implied for Exp[Int] { + delegate for Exp[Int] { def lit(i: Int): Int = i def neg(t: Int): Int = -t def add(l: Int, r: Int): Int = l + r } - implied for Exp[String] { + delegate for 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) - implied for Mult[Int] { + delegate for Mult[Int] { def mul(l: Int, r: Int): Int = l * r } - implied for Mult[String] { + delegate for Mult[String] { def mul(l: String, r: String): String = s"$l * $r" } @@ -87,7 +87,7 @@ object Test extends App { } import Tree._ - implied for Exp[Tree], Mult[Tree] { + delegate for 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 = { - implied for CanThrow + delegate for 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 } - implied for Exp[Wrapped] { + delegate for 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 } - implied [T] for Exp[NCtx => T] given (e: Exp[T]) { + delegate [T] for 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) - implied [T] for Mult[NCtx => T] given (e: Mult[T]) { + delegate [T] for 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 - implied initialize for Exp[IExp] { + delegate initialize for 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) diff --git a/tests/run/typeclass-derivation1.scala b/tests/run/typeclass-derivation1.scala index 3aebb39a43c1..4f3e2f411382 100644 --- a/tests/run/typeclass-derivation1.scala +++ b/tests/run/typeclass-derivation1.scala @@ -38,7 +38,7 @@ object Deriving { } object Eq { - inline def tryEq[T](x: T, y: T) = implied match { + inline def tryEq[T](x: T, y: T) = delegate match { case eq: Eq[T] => eq.equals(x, y) } diff --git a/tests/run/typeclass-derivation2.scala b/tests/run/typeclass-derivation2.scala index c593d21600a9..c6d73443cb33 100644 --- a/tests/run/typeclass-derivation2.scala +++ b/tests/run/typeclass-derivation2.scala @@ -227,7 +227,7 @@ object Eq { import scala.compiletime.{erasedValue, error} import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implied match { + inline def tryEql[T](x: T, y: T) = delegate match { case eq: Eq[T] => eq.eql(x, y) } @@ -288,7 +288,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = delegate match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -321,7 +321,7 @@ object Pickler { case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = delegate match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -382,7 +382,7 @@ object Show { import scala.compiletime.{erasedValue, error} import TypeLevel._ - inline def tryShow[T](x: T): String = implied match { + inline def tryShow[T](x: T): String = delegate match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2a.scala b/tests/run/typeclass-derivation2a.scala index d53092aab1bb..fc5e5bcfff17 100644 --- a/tests/run/typeclass-derivation2a.scala +++ b/tests/run/typeclass-derivation2a.scala @@ -222,7 +222,7 @@ object Eq { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implied match { + inline def tryEql[T](x: T, y: T) = delegate match { case eq: Eq[T] => eq.eql(x, y) } @@ -275,7 +275,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = delegate match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -295,7 +295,7 @@ object Pickler { case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = delegate match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -360,7 +360,7 @@ object Show { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryShow[T](x: T): String = implied match { + inline def tryShow[T](x: T): String = delegate match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2b.scala b/tests/run/typeclass-derivation2b.scala index 70fa42d93a27..b2e0b2f8e441 100644 --- a/tests/run/typeclass-derivation2b.scala +++ b/tests/run/typeclass-derivation2b.scala @@ -94,7 +94,7 @@ object Eq { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implied match { + inline def tryEql[T](x: T, y: T) = delegate match { case eq: Eq[T] => eq.eql(x, y) } @@ -233,7 +233,7 @@ object Eq { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implied match { + inline def tryEql[T](x: T, y: T) = delegate match { case eq: Eq[T] => eq.eql(x, y) } @@ -286,7 +286,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = delegate match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -306,7 +306,7 @@ object Pickler { case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = delegate match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -371,7 +371,7 @@ object Show { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryShow[T](x: T): String = implied match { + inline def tryShow[T](x: T): String = delegate match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2c.scala b/tests/run/typeclass-derivation2c.scala index c5f3172a9ee6..ae8903dd96a7 100644 --- a/tests/run/typeclass-derivation2c.scala +++ b/tests/run/typeclass-derivation2c.scala @@ -54,7 +54,7 @@ object Deriving { type CaseLabel <: String /** The represented value */ - inline def singletonValue = implied match { + inline def singletonValue = delegate match { case ev: ValueOf[T] => ev.value } } @@ -212,7 +212,7 @@ trait Eq[T] { object Eq { import scala.compiletime.erasedValue - inline def tryEql[T](x: T, y: T) = implied match { + inline def tryEql[T](x: T, y: T) = delegate match { case eq: Eq[T] => eq.eql(x, y) } @@ -267,7 +267,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = delegate match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -292,7 +292,7 @@ object Pickler { } else pickleCases[T](g, n + 1)(buf, x, ord) - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = delegate match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -357,7 +357,7 @@ trait Show[T] { object Show { import scala.compiletime.{erasedValue, constValue} - inline def tryShow[T](x: T): String = implied match { + inline def tryShow[T](x: T): String = delegate match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2d.scala b/tests/run/typeclass-derivation2d.scala index f22fb8d6c315..e423bfbcf373 100644 --- a/tests/run/typeclass-derivation2d.scala +++ b/tests/run/typeclass-derivation2d.scala @@ -199,7 +199,7 @@ trait Eq[T] { object Eq { import scala.compiletime.erasedValue - inline def tryEql[T](x: T, y: T) = implied match { + inline def tryEql[T](x: T, y: T) = delegate match { case eq: Eq[T] => eq.eql(x, y) } @@ -219,7 +219,7 @@ object Eq { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => eqlElems[m.ElemTypes](0)(x, y) } else eqlCases[alts1](n + 1)(x, y, ord) @@ -255,7 +255,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = delegate match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -271,14 +271,14 @@ object Pickler { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => pickleElems[m.ElemTypes](0)(buf, x) } else pickleCases[alts1](n + 1)(buf, x, ord) case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = delegate match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -305,7 +305,7 @@ object Pickler { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt` & T] => unpickleCase[`alt` & T, m.ElemTypes](buf, m) } @@ -348,7 +348,7 @@ trait Show[T] { object Show { import scala.compiletime.{erasedValue, constValue} - inline def tryShow[T](x: T): String = implied match { + inline def tryShow[T](x: T): String = delegate match { case s: Show[T] => s.show(x) } @@ -377,7 +377,7 @@ object Show { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => showCase(x, m) } diff --git a/tests/run/typeclass-derivation3.scala b/tests/run/typeclass-derivation3.scala index 1e53d4470649..051060850f7c 100644 --- a/tests/run/typeclass-derivation3.scala +++ b/tests/run/typeclass-derivation3.scala @@ -32,7 +32,7 @@ object typeclasses { import compiletime._ import scala.deriving._ - inline def tryEql[TT](x: TT, y: TT): Boolean = implied match { + inline def tryEql[TT](x: TT, y: TT): Boolean = delegate match { case eq: Eq[TT] => eq.eql(x, y) } @@ -52,7 +52,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => eqlElems[m.MirroredElemTypes](0)(x, y) } else eqlCases[alts1](n + 1)(x, y, ord) @@ -89,7 +89,7 @@ object typeclasses { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = delegate match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -105,14 +105,14 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => pickleElems[m.MirroredElemTypes](0)(buf, x) } else pickleCases[alts1](n + 1)(buf, x, ord) case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = delegate match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -139,7 +139,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt` & T] => unpickleCase[`alt` & T, m.MirroredElemTypes](buf, m) } @@ -183,7 +183,7 @@ object typeclasses { import compiletime._ import deriving._ - inline def tryShow[T](x: T): String = implied match { + inline def tryShow[T](x: T): String = delegate match { case s: Show[T] => s.show(x) } @@ -212,7 +212,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implied match { + delegate match { case m: Mirror.ProductOf[`alt`] => showCase(x, m) }