diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index a118e95bb5a8..878b58f5040f 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -222,7 +222,10 @@ object desugar { val epbuf = ListBuffer[ValDef]() def desugarContextBounds(rhs: Tree): Tree = rhs match { case ContextBounds(tbounds, cxbounds) => - epbuf ++= makeImplicitParameters(cxbounds, Implicit, forPrimaryConstructor = isPrimaryConstructor) + val iflag = cxbounds match + case (_: untpd.Function) :: Nil => Implicit // it's a view bound + case _ => Given + epbuf ++= makeImplicitParameters(cxbounds, iflag, forPrimaryConstructor = isPrimaryConstructor) tbounds case LambdaTypeTree(tparams, body) => cpy.LambdaTypeTree(rhs)(tparams, desugarContextBounds(body)) diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index eab6cccc4ff4..bfe1dbd874f5 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -471,7 +471,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { def makeAndType(left: Tree, right: Tree)(implicit ctx: Context): AppliedTypeTree = AppliedTypeTree(ref(defn.andType.typeRef), left :: right :: Nil) - def makeParameter(pname: TermName, tpe: Tree, mods: Modifiers = EmptyModifiers, isBackquoted: Boolean = false)(implicit ctx: Context): ValDef = { + def makeParameter(pname: TermName, tpe: Tree, mods: Modifiers, isBackquoted: Boolean = false)(implicit ctx: Context): ValDef = { val vdef = ValDef(pname, tpe, EmptyTree) if (isBackquoted) vdef.pushAttachment(Backquoted, ()) vdef.withMods(mods | Param) diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index b804a11a6ede..abce7ce42993 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -412,6 +412,7 @@ object StdNames { val array_length : N = "array_length" val array_update : N = "array_update" val arraycopy: N = "arraycopy" + val as: N = "as" val asTerm: N = "asTerm" val asModule: N = "asModule" val asMethod: N = "asMethod" diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 2c848aa5728e..0780f9d4a9e5 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -203,11 +203,11 @@ object Parsers { def isBindingIntro: Boolean = { in.token match { case USCORE => true - case IDENTIFIER | BACKQUOTED_IDENT => in.lookaheadIn(BitSet(ARROW)) + case IDENTIFIER | BACKQUOTED_IDENT => in.lookaheadIn(BitSet(ARROW, CTXARROW)) case LPAREN => val lookahead = in.LookaheadScanner() lookahead.skipParens() - lookahead.token == ARROW + lookahead.token == ARROW || lookahead.token == CTXARROW case _ => false } } && !in.isSoftModifierInModifierPosition @@ -344,6 +344,15 @@ object Parsers { offset } + def accept(name: Name): Int = { + val offset = in.offset + if !isIdent(name) then + syntaxErrorOrIncomplete(em"`$name` expected") + if isIdent(name) then + in.nextToken() + offset + } + def reportMissing(expected: Token): Unit = syntaxError(ExpectedTokenButFound(expected, in.token)) @@ -445,34 +454,34 @@ object Parsers { /** Convert tree to formal parameter list */ - def convertToParams(tree: Tree): List[ValDef] = tree match { + def convertToParams(tree: Tree, mods: Modifiers): List[ValDef] = tree match { case Parens(t) => - convertToParam(t) :: Nil + convertToParam(t, mods) :: Nil case Tuple(ts) => - ts.map(convertToParam(_)) + ts.map(convertToParam(_, mods)) case t: Typed => in.errorOrMigrationWarning( em"parentheses are required around the parameter of a lambda${rewriteNotice("-language:Scala2Compat")}", t.span) patch(source, t.span.startPos, "(") patch(source, t.span.endPos, ")") - convertToParam(t) :: Nil + convertToParam(t, mods) :: Nil case t => - convertToParam(t) :: Nil + convertToParam(t, mods) :: Nil } /** Convert tree to formal parameter */ - def convertToParam(tree: Tree, expected: String = "formal parameter"): ValDef = tree match { + def convertToParam(tree: Tree, mods: Modifiers, expected: String = "formal parameter"): ValDef = tree match { case id @ Ident(name) => - makeParameter(name.asTermName, TypeTree(), isBackquoted = isBackquoted(id)).withSpan(tree.span) + makeParameter(name.asTermName, TypeTree(), mods, isBackquoted = isBackquoted(id)).withSpan(tree.span) case Typed(id @ Ident(name), tpt) => - makeParameter(name.asTermName, tpt, isBackquoted = isBackquoted(id)).withSpan(tree.span) + makeParameter(name.asTermName, tpt, mods, isBackquoted = isBackquoted(id)).withSpan(tree.span) case Typed(Splice(Ident(name)), tpt) => - makeParameter(("$" + name).toTermName, tpt).withSpan(tree.span) + makeParameter(("$" + name).toTermName, tpt, mods).withSpan(tree.span) case _ => syntaxError(s"not a legal $expected", tree.span) - makeParameter(nme.ERROR, tree) + makeParameter(nme.ERROR, tree, mods) } /** Convert (qual)ident to type identifier @@ -902,7 +911,6 @@ object Parsers { /** Are the next tokens a prefix of a formal parameter or given type? * @pre: current token is LPAREN - * TODO: Drop once syntax has stabilized */ def followingIsParamOrGivenType() = val lookahead = in.LookaheadScanner() @@ -920,22 +928,6 @@ object Parsers { else false else false - /** Are the next tokens a prefix of a formal parameter? - * @pre: current token is LPAREN - */ - def followingIsParam() = - val lookahead = in.LookaheadScanner() - lookahead.nextToken() - if startParamTokens.contains(lookahead.token) then true - else if lookahead.token == IDENTIFIER then - if lookahead.name == nme.inline then - lookahead.nextToken() - if lookahead.token == IDENTIFIER then - lookahead.nextToken() - lookahead.token == COLON - else false - else false - /** Are the next token the "GivenSig" part of a given definition, * i.e. an identifier followed by type and value parameters, followed by `:`? * @pre The current token is an identifier @@ -946,10 +938,13 @@ object Parsers { lookahead.nextToken() while lookahead.token == LPAREN || lookahead.token == LBRACKET do lookahead.skipParens() - if lookahead.token == COLON then + if lookahead.token == COLON then // TODO: remove lookahead.nextToken() !lookahead.isAfterLineEnd - else lookahead.token == SUBTYPE + else + lookahead.token == SUBTYPE // TODO: remove + || lookahead.isIdent(nme.as) + || lookahead.token == WITH && lookahead.ch != Chars.LF // TODO: remove LF test def followingIsExtension() = val lookahead = in.LookaheadScanner() @@ -1346,17 +1341,22 @@ object Parsers { * | MatchType * | InfixType * FunType ::= (MonoFunType | PolyFunType) - * MonoFunType ::= FunArgTypes ‘=>’ Type + * MonoFunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type * PolyFunType ::= HKTypeParamClause '=>' Type * FunArgTypes ::= InfixType - * | `(' [ [ ‘[given]’ ‘['erased'] FunArgType {`,' FunArgType } ] `)' - * | '(' [ ‘[given]’ ‘['erased'] TypedFunParam {',' TypedFunParam } ')' + * | `(' [ [ ‘['erased'] FunArgType {`,' FunArgType } ] `)' + * | '(' [ ‘['erased'] TypedFunParam {',' TypedFunParam } ')' */ def typ(): Tree = { val start = in.offset var imods = Modifiers() def functionRest(params: List[Tree]): Tree = - atSpan(start, accept(ARROW)) { + atSpan(start, in.offset) { + if in.token == CTXARROW then + in.nextToken() + imods |= Given + else + accept(ARROW) val t = typ() if (imods.isOneOf(Given | Erased)) new FunctionWithMods(params, t, imods) else Function(params, t) @@ -1393,7 +1393,7 @@ object Parsers { } openParens.change(LPAREN, -1) accept(RPAREN) - if (isValParamList || in.token == ARROW) + if isValParamList || in.token == ARROW || in.token == CTXARROW then functionRest(ts) else { val ts1 = @@ -1437,7 +1437,7 @@ object Parsers { else infixType() in.token match { - case ARROW => functionRest(t :: Nil) + case ARROW | CTXARROW => functionRest(t :: Nil) case MATCH => matchType(t) case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t case _ => @@ -1761,14 +1761,14 @@ object Parsers { t end condExpr - /** Expr ::= [`implicit'] FunParams =>' Expr + /** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr * | Expr1 * FunParams ::= Bindings * | id * | `_' * ExprInParens ::= PostfixExpr `:' Type * | Expr - * BlockResult ::= [‘implicit’] FunParams =>' Block + * BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block * | Expr1 * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr] * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr] @@ -1812,9 +1812,10 @@ object Parsers { finally placeholderParams = saved val t = expr1(location) - if (in.token == ARROW) { + if (in.token == ARROW || in.token == CTXARROW) { placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder - wrapPlaceholders(closureRest(start, location, convertToParams(t))) + val paramMods = if in.token == CTXARROW then Modifiers(Given) else EmptyModifiers + wrapPlaceholders(closureRest(start, location, convertToParams(t, paramMods))) } else if (isWildcard(t)) { placeholderParams = placeholderParams ::: saved @@ -2066,7 +2067,7 @@ object Parsers { def closureRest(start: Int, location: Location.Value, params: List[Tree]): Tree = atSpan(start, in.offset) { - accept(ARROW) + if in.token == CTXARROW then in.nextToken() else accept(ARROW) Function(params, if (location == Location.InBlock) block() else expr()) } @@ -2108,6 +2109,7 @@ object Parsers { * | SimpleExpr `.' MatchClause * | SimpleExpr (TypeArgs | NamedTypeArgs) * | SimpleExpr1 ArgumentExprs + * | SimpleExpr ContextArguments * Quoted ::= ‘'’ ‘{’ Block ‘}’ * | ‘'’ ‘[’ Type ‘]’ */ @@ -2176,6 +2178,8 @@ object Parsers { case DOT => in.nextToken() simpleExprRest(selector(t), canApply = true) + case DOTWITH => + simpleExprRest(contextArguments(t), canApply = true) case LBRACKET => val tapp = atSpan(startOffset(t), in.offset) { TypeApply(t, typeArgs(namedOK = true, wildOK = false)) } simpleExprRest(tapp, canApply = true) @@ -2252,7 +2256,7 @@ object Parsers { else fn } - /** ParArgumentExprss ::= {ParArgumentExprs} + /** ParArgumentExprss ::= {ParArgumentExprs | ContextArguments} * * Special treatment for arguments to primary constructor annotations. * (...) is considered an argument only if it does not look like a formal @@ -2277,6 +2281,8 @@ object Parsers { parArgumentExprss( atSpan(startOffset(fn)) { mkApply(fn, parArgumentExprs()) } ) + else if in.token == DOTWITH then + parArgumentExprss(contextArguments(fn)) else fn } @@ -2306,6 +2312,14 @@ object Parsers { else Block(stats, EmptyTree) } + /** ContextArguments ::= ‘.’ ‘with’ ArgumentExprs */ + def contextArguments(t: Tree): Tree = + if in.token == DOTWITH then + atSpan(t.span.start, in.skipToken()) { + Apply(t, argumentExprs()._1).setGivenApply() + } + else t + /** Guard ::= if PostfixExpr */ def guard(): Tree = @@ -2788,28 +2802,23 @@ object Parsers { def typeParamClauseOpt(ownerKind: ParamOwner.Value): List[TypeDef] = if (in.token == LBRACKET) typeParamClause(ownerKind) else Nil - def typesToGivenParams(tps: List[Tree], ofClass: Boolean, nparams: Int): List[ValDef] = + /** AnnotTypes ::= AnnotType {‘,’ AnnotType} + * Types ::= Type {‘,’ Type} + */ + def givenTypes(parseType: () => Tree, nparams: Int, ofClass: Boolean): List[ValDef] = + val tps = commaSeparated(parseType) var counter = nparams def nextIdx = { counter += 1; counter } val paramFlags = if ofClass then Private | Local | ParamAccessor else Param - val tps1 = tps match - case Tuple(tps1) :: Nil => tps1 - case _ => tps - tps1.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given)) - - /** OLD: GivenTypes ::= AnnotType {‘,’ AnnotType} - * NEW: GivenTypes ::= Type {‘,’ Type} - */ - def givenTypes(ofClass: Boolean, nparams: Int): List[ValDef] = - typesToGivenParams(commaSeparated(typ), ofClass, nparams) + tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given)) /** ClsParamClause ::= ‘(’ [‘erased’] ClsParams ‘)’ - * GivenClsParamClause::= ‘(’ ‘given’ [‘erased’] (ClsParams | GivenTypes) ‘)’ + * GivenClsParamClause::= 'with' (‘(’ (ClsParams | Types) ‘)’ | AnnotTypes) * ClsParams ::= ClsParam {‘,’ ClsParam} * ClsParam ::= {Annotation} * * DefParamClause ::= ‘(’ [‘erased’] DefParams ‘)’ - * GivenParamClause ::= ‘(’ ‘given’ [‘erased’] (DefParams | GivenTypes) ‘)’ + * GivenParamClause ::= ‘with’ (‘(’ (DefParams | Types) ‘)’ | AnnotTypes) * DefParams ::= DefParam {‘,’ DefParam} * DefParam ::= {Annotation} [‘inline’] Param * @@ -2822,9 +2831,10 @@ object Parsers { ofCaseClass: Boolean = false, // owner is a case class prefix: Boolean = false, // clause precedes name of an extension method givenOnly: Boolean = false, // only given parameters allowed - firstClause: Boolean = false // clause is the first in regular list of clauses + firstClause: Boolean = false, // clause is the first in regular list of clauses + prefixMods: Modifiers = EmptyModifiers // is `Given` if this is a with clause ): List[ValDef] = { - var impliedMods: Modifiers = EmptyModifiers + var impliedMods: Modifiers = prefixMods def impliedModOpt(token: Token, mod: () => Mod): Boolean = if in.token == token then @@ -2894,22 +2904,28 @@ object Parsers { impliedModOpt(GIVEN, () => Mod.Given()) impliedModOpt(ERASED, () => Mod.Erased()) if givenOnly && !impliedMods.is(Given) then - syntaxError(ExpectedTokenButFound(GIVEN, in.token)) + syntaxError("Normal parameter clause cannot follow context parameter clause") val isParams = !impliedMods.is(Given) || startParamTokens.contains(in.token) || isIdent && (in.name == nme.inline || in.lookaheadIn(BitSet(COLON))) if isParams then commaSeparated(() => param()) - else givenTypes(ofClass, nparams) + else givenTypes(typ, nparams, ofClass) checkVarArgsRules(clause) clause } } /** ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’] - * | {ClsParamClause} {GivenClsParamClause} + * | ClsParamClause ClsParamClauses + * | ClsParamClauses1 + * ClsParamClauses1 ::= WithClsParamClause ClsParamClauses + * | AnnotTypes ClsParamClauses1ClsParamClauses * DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’] - * | {DefParamClause} {GivenParamClause} + * | DefParamClause DefParamClauses + * | DefParamClauses1 + * DefParamClauses1 ::= WithCaramClause DefParamClauses + * | AnnotTypes DeParamClauses1 * * @return The parameter definitions */ @@ -2919,6 +2935,12 @@ object Parsers { def recur(firstClause: Boolean, nparams: Int): List[List[ValDef]] = newLineOptWhenFollowedBy(LPAREN) + val prefixMods = + if in.token == WITH && in.ch != Chars.LF then // TODO: remove LF test + in.nextToken() + Modifiers(Given) + else + EmptyModifiers if in.token == LPAREN then val paramsStart = in.offset val params = paramClause( @@ -2926,11 +2948,20 @@ object Parsers { ofClass = ofClass, ofCaseClass = ofCaseClass, givenOnly = givenOnly, - firstClause = firstClause) + firstClause = firstClause, + prefixMods = prefixMods) val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit) + val isGivenClause = prefixMods.is(Given) + || params.nonEmpty && params.head.mods.flags.is(Given) params :: ( if lastClause then Nil else recur(firstClause = false, nparams + params.length)) + else if prefixMods.is(Given) then + val params = givenTypes(annotType, nparams, ofClass) + params :: ( + if in.token == WITH then recur(firstClause = false, nparams + params.length) + else Nil + ) else Nil end recur @@ -2963,7 +2994,6 @@ object Parsers { /** ImportExpr ::= StableId ‘.’ ImportSpec * ImportSpec ::= id * | ‘_’ - * | ‘given’ * | ‘{’ ImportSelectors) ‘}’ */ def importExpr(mkTree: ImportConstr): () => Tree = { @@ -2985,15 +3015,16 @@ object Parsers { val selector = if isWildcard then val id = wildcardSelectorId() - val bound = - if selToken == USCORE && in.token == COLON then + if selToken == USCORE then ImportSelector(id) + else atSpan(startOffset(id)) { + if in.token == USCORE then in.nextToken() - infixType() - else if selToken == GIVEN && in.token != RBRACE && in.token != COMMA then - infixType() + ImportSelector(id) + else if in.token != RBRACE && in.token != COMMA then + ImportSelector(id, bound = infixType()) else - EmptyTree - ImportSelector(id, bound = bound) + ImportSelector(id) // TODO: drop + } else val from = termIdent() if !idOK then syntaxError(i"named imports cannot follow wildcard imports") @@ -3426,12 +3457,12 @@ object Parsers { syntaxError(i"extension clause can only define methods", stat.span) } - /** GivenDef ::= [GivenSig (‘:’ | <:)] {FunArgTypes ‘=>’} AnnotType ‘=’ Expr - * | [GivenSig ‘:’] {FunArgTypes ‘=>’} ConstrApps [TemplateBody] - * GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause} - * ExtParamClause ::= [DefTypeParamClause] DefParamClause - * ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’ - * TODO: cleanup once syntax has stabilized + /** GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr + * | [GivenSig] ConstrApps [TemplateBody] + * GivenSig ::= [id] [DefTypeParamClause] {WithParamsOrTypes} ‘as’ + * ExtParamClause ::= [DefTypeParamClause] DefParamClause + * ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’ + * WithParamsOrTypes ::= WithParamClause | AnnotTypes */ def givenDef(start: Offset, mods: Modifiers, instanceMod: Mod) = atSpan(start, nameStart) { var mods1 = addMod(mods, instanceMod) @@ -3456,60 +3487,35 @@ object Parsers { templ.body.foreach(checkExtensionMethod(tparams, _)) ModuleDef(name, templ) else - var hasLabel = false - def skipColon() = - if !hasLabel && in.token == COLON then - hasLabel = true - in.nextToken() - if !name.isEmpty then skipColon() + val hasLabel = !name.isEmpty && in.token == COLON || in.isIdent(nme.as) + if hasLabel then in.nextToken() val tparams = typeParamClauseOpt(ParamOwner.Def) - if !tparams.isEmpty then skipColon() val paramsStart = in.offset - var vparamss = - if in.token == LPAREN && followingIsParamOrGivenType() - then paramClauses() // todo: ONLY admit a single paramClause + val vparamss = + if in.token == WITH && in.ch != Chars.LF // TODO: remove LF test + || in.token == LPAREN && followingIsParamOrGivenType() + then paramClauses() else Nil def checkAllGivens(vparamss: List[List[ValDef]], what: String) = vparamss.foreach(_.foreach(vparam => if !vparam.mods.is(Given) then syntaxError(em"$what must be `given`", vparam.span))) - def makeGiven(params: List[ValDef]): List[ValDef] = - params.map(param => param.withMods(param.mods | Given)) - def conditionalParents(): List[Tree] = - accept(ARROW) - if in.token == LPAREN && followingIsParam() then - vparamss = vparamss :+ makeGiven(paramClause(vparamss.flatten.length)) - conditionalParents() - else - val constrs = constrApps(commaOK = true, templateCanFollow = true) - if in.token == ARROW && constrs.forall(_.isType) then - vparamss = vparamss - :+ typesToGivenParams(constrs, ofClass = false, vparamss.flatten.length) - conditionalParents() - else constrs - - val isConditional = - in.token == ARROW - && vparamss.length == 1 - && (hasLabel || name.isEmpty && tparams.isEmpty) - if !isConditional then checkAllGivens(vparamss, "parameter of given instance") + checkAllGivens(vparamss, "parameter of given instance") val parents = if in.token == SUBTYPE && !hasLabel then if !mods.is(Inline) then syntaxError("`<:` is only allowed for given with `inline` modifier") in.nextToken() - TypeBoundsTree(EmptyTree, annotType()) :: Nil - else if isConditional then - vparamss = vparamss.map(makeGiven) - conditionalParents() + TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil else if !hasLabel && !(name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then - accept(COLON) - val constrs = constrApps(commaOK = true, templateCanFollow = true) - if in.token == ARROW && vparamss.isEmpty && constrs.forall(_.isType) then - vparamss = typesToGivenParams(constrs, ofClass = false, 0) :: Nil - conditionalParents() + if in.token == COLON then in.nextToken() + else accept(nme.as) + if in.token == USCORE then + in.nextToken() + accept(SUBTYPE) + TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil else - constrs + constrApps(commaOK = true, templateCanFollow = true) if in.token == EQUALS && parents.length == 1 && parents.head.isType then in.nextToken() @@ -3530,7 +3536,7 @@ object Parsers { finalizeDef(gdef, mods1, start) } - /** ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ExtMethods + /** ExtensionDef ::= [id] ‘on’ ExtParamClause GivenParamClauses ExtMethods */ def extensionDef(start: Offset, mods: Modifiers): ModuleDef = in.nextToken() @@ -3554,7 +3560,8 @@ object Parsers { val constrApp: () => Tree = () => { val t = rejectWildcardType(annotType(), fallbackTree = Ident(nme.ERROR)) // Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code - if in.token == LPAREN then parArgumentExprss(wrapNew(t)) else t + if in.token == LPAREN || in.token == DOTWITH then parArgumentExprss(wrapNew(t)) + else t } /** ConstrApps ::= ConstrApp {(‘,’ | ‘with’) ConstrApp} @@ -3713,7 +3720,7 @@ object Parsers { case Typed(tree @ This(EmptyTypeIdent), tpt) => self = makeSelfDef(nme.WILDCARD, tpt).withSpan(first.span) case _ => - val ValDef(name, tpt, _) = convertToParam(first, "self type clause") + val ValDef(name, tpt, _) = convertToParam(first, EmptyModifiers, "self type clause") if (name != nme.ERROR) self = makeSelfDef(name, tpt).withSpan(first.span) } diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 58deda8268dc..2d7dbc1a0ab6 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -593,7 +593,11 @@ object Scanners { this.copyFrom(prev) } - /** - Join CASE + CLASS => CASECLASS, CASE + OBJECT => CASEOBJECT, SEMI + ELSE => ELSE, COLON + => COLONEOL + /** - Join CASE + CLASS => CASECLASS, + * CASE + OBJECT => CASEOBJECT, + * SEMI + ELSE => ELSE, + * COLON + => COLONEOL + * DOT + WITH => DOTWITH * - Insert missing OUTDENTs at EOF */ def postProcessToken(): Unit = { @@ -619,6 +623,10 @@ object Scanners { } else if (token == EOF) { // e.g. when the REPL is parsing "val List(x, y, _*," /* skip the trailing comma */ } else reset() + case DOT => + lookahead() + if token == WITH then fuse(DOTWITH) + else reset() case COLON => if colonSyntax then observeColonEOL() case EOF | RBRACE => @@ -1301,8 +1309,8 @@ object Scanners { override def toString: String = showTokenDetailed(token) + { - if identifierTokens.contains(token) then name - else if literalTokens.contains(token) then strVal + if identifierTokens.contains(token) then s" $name" + else if literalTokens.contains(token) then s" $strVal" else "" } diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index cccc7702ed01..68144f780e3d 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -189,7 +189,6 @@ object Tokens extends TokensCommon { /** special symbols */ final val NEWLINE = 78; enter(NEWLINE, "end of statement", "new line") final val NEWLINES = 79; enter(NEWLINES, "end of statement", "new lines") - final val COLONEOL = 88; enter(COLONEOL, ":", ": at eol") /** special keywords */ final val USCORE = 73; enter(USCORE, "_") @@ -200,14 +199,18 @@ object Tokens extends TokensCommon { final val HASH = 82; enter(HASH, "#") final val VIEWBOUND = 84; enter(VIEWBOUND, "<%") final val TLARROW = 85; enter(TLARROW, "=>>") + final val CTXARROW = 86; enter(CTXARROW, "?=>") + + final val QUOTE = 87; enter(QUOTE, "'") - final val QUOTE = 86; enter(QUOTE, "'") + final val COLONEOL = 88; enter(COLONEOL, ":", ": at eol") + final val DOTWITH = 89; enter(DOTWITH, ".with") /** XML mode */ final val XMLSTART = 98; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate final val alphaKeywords: TokenSet = tokenRange(IF, MACRO) - final val symbolicKeywords: TokenSet = tokenRange(USCORE, TLARROW) + final val symbolicKeywords: TokenSet = tokenRange(USCORE, CTXARROW) final val keywords: TokenSet = alphaKeywords | symbolicKeywords final val allTokens: TokenSet = tokenRange(minToken, maxToken) diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index e5ed7031b071..512d870005d4 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -131,6 +131,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { else simpleNameString(tsym) } + private def arrow(isGiven: Boolean): String = + if isGiven then "?=>" else "=>" + override def toText(tp: Type): Text = controlled { def toTextTuple(args: List[Type]): Text = "(" ~ argsText(args) ~ ")" @@ -145,19 +148,19 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { atPrec(InfixPrec) { argText(args.head) } else "(" - ~ keywordText("given ").provided(isGiven) ~ keywordText("erased ").provided(isErased) ~ argsText(args.init) ~ ")" - argStr ~ " => " ~ argText(args.last) + argStr ~ " " ~ arrow(isGiven) ~ " " ~ argText(args.last) } def toTextDependentFunction(appType: MethodType): Text = "(" - ~ keywordText("given ").provided(appType.isImplicitMethod) ~ keywordText("erased ").provided(appType.isErasedMethod) ~ paramsText(appType) - ~ ") => " + ~ ") " + ~ arrow(appType.isImplicitMethod) + ~ " " ~ toText(appType.resultType) def isInfixType(tp: Type): Boolean = tp match { @@ -386,8 +389,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { keywordStr("${") ~ toTextGlobal(args, ", ") ~ keywordStr("}") else toTextLocal(fun) + ~ ("." ~ keywordText("with")).provided(app.isGivenApply && !homogenizedView) ~ "(" - ~ keywordText("given ").provided(app.isGivenApply && !homogenizedView) ~ toTextGlobal(args, ", ") ~ ")" case tree: TypeApply => @@ -577,12 +580,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case (arg @ ValDef(_, tpt, _)) :: Nil if tpt.isEmpty => argToText(arg) case _ => "(" - ~ keywordText("given ").provided(isGiven) ~ keywordText("erased ").provided(isErased) ~ Text(args.map(argToText), ", ") ~ ")" } - argsText ~ " => " ~ toText(body) + argsText ~ " " ~ arrow(isGiven) ~ " " ~ toText(body) case PolyFunction(targs, body) => val targsText = "[" ~ Text(targs.map((arg: Tree) => toText(arg)), ", ") ~ "]" changePrec(GlobalPrec) { @@ -770,10 +772,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } private def paramsText[T>: Untyped](params: List[ValDef[T]]) = - "(" - ~ keywordText("given ").provided(params.nonEmpty && params.head.mods.is(Given)) - ~ toText(params, ", ") - ~ ")" + keywordText(" with ").provided(params.nonEmpty && params.head.mods.is(Given)) + ~ "(" ~ toText(params, ", ") ~ ")" protected def defDefToText[T >: Untyped](tree: DefDef[T]): Text = { import untpd.{modsDeco => _} diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 554380596567..57582e56403e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2650,7 +2650,17 @@ class Typer extends Namer else tree else if (wtp.isContextualMethod) - adaptNoArgs(wtp) // insert arguments implicitly + def isContextBoundParams = wtp.stripPoly match + case MethodType(EvidenceParamName(_) :: _) => true + case _ => false + if ctx.scala2CompatMode && isContextBoundParams then + ctx.migrationWarning( + em"""Context bounds will map to context parameters. + |A `with` clause is needed to pass explicit arguments to them""", tree.sourcePos) + patch(Span(tree.span.end), ".with") + tree + else + adaptNoArgs(wtp) // insert arguments implicitly else if (tree.symbol.isPrimaryConstructor && tree.symbol.info.firstParamTypes.isEmpty) readapt(tree.appliedToNone) // insert () to primary constructors else diff --git a/compiler/test-resources/repl/3932 b/compiler/test-resources/repl/3932 index c5dbccb7a00b..33f1592f98c1 100644 --- a/compiler/test-resources/repl/3932 +++ b/compiler/test-resources/repl/3932 @@ -1,2 +1,2 @@ scala> def fun[T](x: T): (given List[T]) => Int = ??? -def fun[T](x: T): (given List[T]) => Int +def fun[T](x: T): (List[T]) ?=> Int \ No newline at end of file diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 3f6470833a08..15efe258dec4 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -83,6 +83,7 @@ comment ::= ‘/*’ “any sequence of characters; nested comments ar nl ::= “new line character” semi ::= ‘;’ | nl {nl} +colonEol ::= ": at end of line that can start a tenmplate body" ``` ## Keywords @@ -97,13 +98,13 @@ private protected override return super sealed then throw trait true try type val var while with yield : = <- => <: :> # @ -=>> +=>> ?=> ``` ### Soft keywords ``` -derives extension inline opaque open +as derives extension inline on opaque open ~ * | & + - ``` @@ -141,15 +142,15 @@ Type ::= FunType | HkTypeParamClause ‘=>>’ Type TypeLambda(ps, t) | MatchType | InfixType -FunType ::= FunArgTypes ‘=>’ Type Function(ts, t) +FunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type Function(ts, t) | HKTypeParamClause '=>' Type PolyFunction(ps, t) FunArgTypes ::= InfixType - | ‘(’ [ ‘[given]’ FunArgType {‘,’ FunArgType } ] ‘)’ - | ‘(’ ‘[given]’ TypedFunParam {‘,’ TypedFunParam } ‘)’ + | ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’ + | ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’ TypedFunParam ::= id ‘:’ Type MatchType ::= InfixType `match` ‘{’ TypeCaseClauses ‘}’ InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) -RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) +RefinedType ::= WithType {[nl | colonEol] Refinement} RefinedTypeTree(t, ds) WithType ::= AnnotType {‘with’ AnnotType} (deprecated) AnnotType ::= SimpleType {Annotation} Annotated(t, annot) SimpleType ::= SimpleType TypeArgs AppliedTypeTree(t, args) @@ -173,13 +174,15 @@ NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds SubtypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeBoundsTree(lo, hi) TypeParamBounds ::= SubtypeBounds {‘:’ Type} ContextBounds(typeBounds, tps) +Types ::= Type {‘,’ Type} +AnnotTypes ::= AnnotType {‘,’ AnnotType} ``` ### Expressions ```ebnf -Expr ::= [‘implicit’] FunParams ‘=>’ Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) +Expr ::= FunParams (‘=>’ | ‘?=>’) Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) | Expr1 -BlockResult ::= [‘implicit’] FunParams ‘=>’ Block +BlockResult ::= FunParams (‘=>’ | ‘?=>’) Block | Expr1 FunParams ::= Bindings | id @@ -205,7 +208,7 @@ PostfixExpr ::= InfixExpr [id] InfixExpr ::= PrefixExpr | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) | InfixExpr MatchClause -MatchClause ::= ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases) +MatchClause ::= ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases) PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op) SimpleExpr ::= Path | Literal @@ -219,6 +222,7 @@ SimpleExpr ::= Path | ‘(’ ExprsInParens ‘)’ Parens(exprs) | SimpleExpr ‘.’ id Select(expr, id) | SimpleExpr ‘.’ MatchClause + | SimpleExpr ‘.’ ContextArguments | SimpleExpr TypeArgs TypeApply(expr, args) | SimpleExpr ArgumentExprs Apply(expr, args) | SimpleExpr ‘_’ PostfixOp(expr, _) @@ -228,10 +232,12 @@ Quoted ::= ‘'’ ‘{’ Block ‘}’ ExprsInParens ::= ExprInParens {‘,’ ExprInParens} ExprInParens ::= PostfixExpr ‘:’ Type -- normal Expr allows only RefinedType here | Expr -ParArgumentExprs ::= ‘(’ [‘given’] ExprsInParens ‘)’ exprs +ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’ exprs | ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar)) +ParArgumentExprss ::= {ParArgumentExprs | ContextArguments} ArgumentExprs ::= ParArgumentExprs | [nl] BlockExpr +ContextArguments ::= ‘.’ ‘with’ ArgumentExprs BlockExpr ::= ‘{’ (CaseClauses | Block) ‘}’ Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) BlockStat ::= Import @@ -293,9 +299,12 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] | SubtypeBounds ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’] - | {ClsParamClause} {GivenClsParamClause} + | ClsParamClause ClsParamClauses + | ClsParamClauses1 +ClsParamClauses1 ::= WithClsParamClause ClsParamClauses + | AnnotTypes ClsParamClauses1 ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’ -GivenClsParamClause::= ‘(’ ‘given’ (ClsParams | GivenTypes) ‘)’ +WithClsParamClause::= ‘with’ ‘(’ (ClsParams | Types) ‘)’ ClsParams ::= ClsParam {‘,’ ClsParam} ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param @@ -303,12 +312,15 @@ Param ::= id ‘:’ ParamType [‘=’ Expr] | INT DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’] - | {DefParamClause} {GivenParamClause} + | DefParamClause DefParamClauses + | DefParamClauses1 +DefParamClauses1 ::= WithParamClause DefParamClauses + | AnnotTypes DefParamClauses1 DefParamClause ::= [nl] ‘(’ DefParams ‘)’ -GivenParamClause ::= ‘(’ ‘given’ (DefParams | GivenTypes) ‘)’ +WithParamClause ::= ‘with’ (‘(’ (DefParams | Types) ‘)’ +WithParamsOrTypes ::= WithParamClause | AnnotTypes DefParams ::= DefParam {‘,’ DefParam} DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id. -GivenTypes ::= Type {‘,’ Type} ClosureMods ::= { ‘implicit’ | ‘given’} ``` @@ -331,18 +343,17 @@ LocalModifier ::= ‘abstract’ AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier] AccessQualifier ::= ‘[’ id ‘]’ -Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args) +Annotation ::= ‘@’ SimpleType ParArgumentExprss Apply(tpe, args) Import ::= ‘import’ ImportExpr {‘,’ ImportExpr} ImportExpr ::= StableId ‘.’ ImportSpec Import(expr, sels) ImportSpec ::= id | ‘_’ - | ‘given’ | ‘{’ ImportSelectors) ‘}’ ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors] | WildCardSelector {‘,’ WildCardSelector} -WildCardSelector ::= ‘given’ [InfixType] - | ‘_' [‘:’ InfixType] +WildCardSelector ::= ‘given’ (‘_' | InfixType) + | ‘_' Export ::= ‘export’ [‘given’] ImportExpr {‘,’ ImportExpr} ``` @@ -384,23 +395,22 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses ConstrMods ::= {Annotation} [AccessModifier] ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template) -GivenDef ::= [GivenSig (‘:’ | <:)] {FunArgTypes ‘=>’} - AnnotType ‘=’ Expr - | [GivenSig ‘:’] {FunArgTypes ‘=>’} - ConstrApps [TemplateBody] -GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause} -ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ExtMethods +GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr + | [GivenSig] ConstrApps [TemplateBody] +GivenSig ::= [id] [DefTypeParamClause] {WithParamsOrTypes} ‘as’ +ExtensionDef ::= [id] ‘on’ ExtParamClause {WithParamsOrTypes} ExtMethods ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’ ExtParamClause ::= [DefTypeParamClause] ‘(’ DefParam ‘)’ Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats) InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}] ConstrApps ::= ConstrApp {(‘,’ | ‘with’) ConstrApp} -ConstrApp ::= AnnotType {ParArgumentExprs} Apply(tp, args) +ConstrApp ::= AnnotType ParArgumentExprss Apply(tp, args) ConstrExpr ::= SelfInvocation | ‘{’ SelfInvocation {semi BlockStat} ‘}’ SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs} -TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ (self, stats) +TemplateBody ::= [nl | colonEol] + ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ (self, stats) TemplateStat ::= Import | Export | {Annotation [nl]} {Modifier} Def @@ -410,7 +420,8 @@ TemplateStat ::= Import SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _) | ‘this’ ‘:’ InfixType ‘=>’ -EnumBody ::= [nl] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’ +EnumBody ::= [nl | colonEol] + ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’ EnumStat ::= TemplateStat | {Annotation [nl]} {Modifier} EnumCase EnumCase ::= ‘case’ (id ClassConstr [‘extends’ ConstrApps]] | ids) @@ -422,7 +433,7 @@ TopStat ::= Import | Packaging | PackageObject | -Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ Package(qid, stats) +Packaging ::= ‘package’ QualId [nl | colonEol] ‘{’ TopStatSeq ‘}’ Package(qid, stats) PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods. CompilationUnit ::= {‘package’ QualId semi} TopStatSeq Package(qid, stats) diff --git a/docs/docs/reference/contextual/by-name-context-parameters.md b/docs/docs/reference/contextual/by-name-context-parameters.md new file mode 100644 index 000000000000..c2c96f10351e --- /dev/null +++ b/docs/docs/reference/contextual/by-name-context-parameters.md @@ -0,0 +1,67 @@ +--- +layout: doc-page +title: "By-Name Context Parameters" +--- + +Context parameters can be declared by-name to avoid a divergent inferred expansion. Example: + +```scala +trait Codec[T] { + def write(x: T): Unit +} + +given intCodec as Codec[Int] = ??? + +given optionCodec[T] with (ev: => Codec[T]) as Codec[Option[T]] { + def write(xo: Option[T]) = xo match { + case Some(x) => ev.write(x) + case None => + } +} + +val s = summon[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` +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 +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. + + 1. Create a new given of type `T`: + + ```scala + given lv as T = ??? + ``` + where `lv` is an arbitrary fresh name. + + 1. This given 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 a by-name context parameter. + + 1. If this search succeeds with expression `E`, and `E` contains references to `lv`, replace `E` by + + + ```scala + { given lv as T = E; lv } + ``` + + Otherwise, return `E` unchanged. + +In the example above, the definition of `s` would be expanded as follows. + +```scala +val s = summon[Test.Codec[Option[Int]]]( + optionCodec[Int].with(intCodec) +) +``` + +No local given instance was generated because the synthesized argument is not recursive. + +### Reference + +For more info, see [Issue #1998](https://github.com/lampepfl/dotty/issues/1998) +and the associated [Scala SIP](https://docs.scala-lang.org/sips/byname-implicits.html). diff --git a/docs/docs/reference/contextual/context-bounds-new.md b/docs/docs/reference/contextual/context-bounds-new.md new file mode 100644 index 000000000000..2ff0cee27021 --- /dev/null +++ b/docs/docs/reference/contextual/context-bounds-new.md @@ -0,0 +1,30 @@ +--- +layout: doc-page +title: "Context Bounds" +--- + +## Context Bounds + +A context bound is a shorthand for expressing the 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: +```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 `with Ord[T]`. The context 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) with (y: U, z: V) : R +``` +would expand to +```scala +def f[T, U](x: T) with (y: U, z: V) with C1[T], C2[T], C3[U]) : R +``` +Context bounds can be combined with subtype bounds. If both are present, subtype bounds come first, e.g. +```scala +def g[T <: B : C](x: T): R = ... +``` + +## Syntax + +``` +TypeParamBounds ::= [SubtypeBounds] {ContextBound} +ContextBound ::= ‘:’ Type +``` diff --git a/docs/docs/reference/contextual/context-bounds.md b/docs/docs/reference/contextual/context-bounds.md index b80285827a50..7f95647c19e7 100644 --- a/docs/docs/reference/contextual/context-bounds.md +++ b/docs/docs/reference/contextual/context-bounds.md @@ -3,6 +3,9 @@ layout: doc-page title: "Context Bounds" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./context-bounds-new.html). + ## Context Bounds 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: diff --git a/docs/docs/reference/contextual/context-functions-spec.md b/docs/docs/reference/contextual/context-functions-spec.md new file mode 100644 index 000000000000..265548f06783 --- /dev/null +++ b/docs/docs/reference/contextual/context-functions-spec.md @@ -0,0 +1,74 @@ +--- +layout: doc-page +title: "Context Functions - More Details" +--- + +## Syntax + + Type ::= ... + | FunArgTypes ‘?=>’ Type + Expr ::= ... + | FunParams ‘?=>’ Expr + +Context function types associate to the right, e.g. +`S ?=> T ?=> U` is the same as `S ?=> (T ?=> U)`. + +## Implementation + +Context function types are shorthands for class types that define `apply` +methods with context parameters. Specifically, the `N`-ary function type +`T1, ..., TN => R` is a shorthand for the class type +`ContextFunctionN[T1 , ... , TN, R]`. Such class types are assumed to have the following definitions, for any value of `N >= 1`: +```scala +package scala +trait ContextFunctionN[-T1 , ... , -TN, +R] { + def apply with (x1: T1 , ... , xN: TN) : R +} +``` +Context function types erase to normal function types, so these classes are +generated on the fly for typechecking, but not realized in actual code. + +Context function literals `(x1: T1, ..., xn: Tn) ?=> e` map +context parameters `xi` of types `Ti` to the result of evaluating the expression `e`. +The scope of each context parameter `xi` is `e`. The parameters must have pairwise distinct names. + +If the expected type of the context function literal is of the form +`scala.ContextFunctionN[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 context function literal is +some other type, all context parameter types must be explicitly given, and the expected type of `e` is undefined. +The type of the context function literal is `scala.ContextFunctionN[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 context function literal is evaluated as the instance creation +expression +```scala +new scala.ContextFunctionN[T1, ..., Tn, T] { + def apply with (x1: T1, ..., xn: Tn) : T = e +} +``` +A context 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 context function types and should be removed. + +Context function literals `(x1: T1, ..., xn: Tn) ?=> e` are +automatically created for any expression `e` whose expected type is +`scala.ContextFunctionN[T1, ..., Tn, R]`, unless `e` is +itself a context function literal. This is analogous to the automatic +insertion of `scala.Function0` around expressions in by-name argument position. + +Context function types generalize to `N > 22` in the same way that function types do, see [the corresponding +documentation](../dropped-features/limit22.md). + +## Examples + +See the section on Expressiveness from [Simplicitly: foundations and +applications of implicit function +types](https://dl.acm.org/citation.cfm?id=3158130). + +### Type Checking + +After desugaring no additional typing rules are required for context function types. diff --git a/docs/docs/reference/contextual/context-functions.md b/docs/docs/reference/contextual/context-functions.md new file mode 100644 index 000000000000..bf25d88e989b --- /dev/null +++ b/docs/docs/reference/contextual/context-functions.md @@ -0,0 +1,153 @@ +--- +layout: doc-page +title: "Context Functions" +--- + +_Context functions_ are functions with (only) context parameters. +Their types are _context function types_. Here is an example of a context function type: + +```scala +type Executable[T] = ExecutionContext ?=> T +``` +Context function are written using `?=>` as the "arrow" sign. +They are applied to synthesized arguments, in +the same way methods with context parameters is applied. For instance: +```scala + given ec as ExecutionContext = ... + + def f(x: Int): Executable[Int] = ... + + f(2).with(ec) // explicit argument + f(2) // argument is inferred +``` +Conversely, if the expected type of an expression `E` is a context function type +`(T_1, ..., T_n) ?=> U` and `E` is not already an +context function literal, `E` is converted to an context function literal by rewriting to +```scala + (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 givens in `E`. + +Like their types, context function literals are written using `?=>` as the arrow between parameters and results. They differ from normal function literals in that their types are context function types. + +For example, continuing with the previous definitions, +```scala + def g(arg: Executable[Int]) = ... + + g(22) // is expanded to g((ev: ExecutionContext) ?=> 22) + + g(f(2)) // is expanded to g((ev: ExecutionContext) ?=> f(2).with(ev)) + + g((ctx: ExecutionContext) ?=> f(22).with(ctx)) // is left as it is +``` +### Example: Builder Pattern + +Context 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 + table { + row { + cell("top left") + cell("top right") + } + row { + cell("bottom left") + cell("bottom right") + } + } +``` +The idea is to define classes for `Table` and `Row` that allow +addition of elements via `add`: +```scala + class Table { + val rows = new ArrayBuffer[Row] + def add(r: Row): Unit = rows += r + override def toString = rows.mkString("Table(", ", ", ")") + } + + class Row { + val cells = new ArrayBuffer[Cell] + def add(c: Cell): Unit = cells += c + override def toString = cells.mkString("Row(", ", ", ")") + } + + case class Cell(elem: String) +``` +Then, the `table`, `row` and `cell` constructor methods can be defined +with context function types as parameters to avoid the plumbing boilerplate +that would otherwise be necessary. +```scala + def table(init: Table ?=> Unit) = { + given t as Table + init + t + } + + def row(init: Row ?=> Unit) with (t: Table) = { + given r as Row + init + t.add(r) + } + + def cell(str: String) with (r: Row) = + r.add(new Cell(str)) +``` +With that setup, the table construction code above compiles and expands to: +```scala + table { ($t: Table) ?=> + + row { ($r: Row) ?=> + cell("top left").with($r) + cell("top right").with($r) + }.with($t) + + row { ($r: Row) ?=> + cell("bottom left").with($r) + cell("bottom right").with($r) + }.with($t) + } +``` +### 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, context function types, and extension methods to provide a zero-overhead abstraction. + +```scala +object PostConditions { + opaque type WrappedResult[T] = T + + def result[T] with (r: WrappedResult[T]) : T = r + + def (x: T) ensuring[T](condition: WrappedResult[T] ?=> Boolean): T = { + assert(condition.with(x)) + x + } +} +import PostConditions.{ensuring, result} + +val s = List(1, 2, 3).sum.ensuring(result == 6) +``` +**Explanations**: We use a context function type `WrappedResult[T] ?=> Boolean` +as the type of the condition of `ensuring`. An argument to `ensuring` such as +`(result == 6)` will therefore have a given of 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 givens in scope (this is good practice in all cases +where context 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: + +```scala +{ val result = List(1, 2, 3).sum + assert(result == 6) + result +} +``` +### Reference + +For more info, see the [blog article](https://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html), +(which uses a different syntax that has been superseded). + +[More details](./context-functions-spec.md) diff --git a/docs/docs/reference/contextual/context-parameters.md b/docs/docs/reference/contextual/context-parameters.md new file mode 100644 index 000000000000..b6184ea9645a --- /dev/null +++ b/docs/docs/reference/contextual/context-parameters.md @@ -0,0 +1,138 @@ +--- +layout: doc-page +title: "Context Parameters" +--- + +Functional programming tends to express most dependencies as simple function parameterization. +This is clean and powerful, but it sometimes leads to functions that take many parameters where the same value is passed over and over again in long call chains to many +functions. Context parameters can help here since they enable the compiler to synthesize +repetitive arguments instead of the programmer having to write them explicitly. + +For example, with the [given instances](./givens.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) with (ord: Ord[T]) : T = + if ord.compare(x, y) < 0 then y else x +``` +Here, `ord` is a _context parameter_ introduced with a `with` clause. +The `max` method can be applied as follows: +```scala +max(2, 3).with(intOrd) +``` +The `.with(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 +applications are equally valid: +```scala +max(2, 3) +max(List(1, 2, 3), Nil) +``` +Formatting hint: For legibility it is recommended to always leave one space after a `with` clause before following it with another lexeme. + +## Anonymous Context Parameters + +In many situations, the name of a context 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 +and just provide its type. Example: +```scala +def maximum[T](xs: List[T]) with Ord[T] : T = + xs.reduceLeft(max) +``` +`maximum` takes a context 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 full parameter list `(p_1: T_1, ..., p_n: T_n)` or just as a sequence of types `T_1, ..., T_n`. Vararg parameters are not supported in with clauses. + +**Note:** According to the rules above, a `with` clause like `(A, B)` consisting of types in parentheses defines a context parameter of tuple type. But by analogy with `(a: A, b: B)` one might assume that it defines two context parameters +of type `A` and `B` instead. To avoid confusion, the compiler could issue a warning in this case that clarifies the meaning. If a context parameter of tuple type is in fact intended, the warning can be avoided by switching to a named context parameter, +e.g. `(ab: (A, B))` or enclosing the tuple in an extra set of parentheses, e.g. `((A, B))`. + +## Inferring Complex Arguments + +Here are two other methods that have a context parameter of type `Ord[T]`: +```scala +def descending[T] with (asc: Ord[T]) : Ord[T] = new Ord[T] { + def compare(x: T, y: T) = asc.compare(y, x) +} + +def minimum[T](xs: List[T]) with Ord[T] = + maximum(xs).with(descending) +``` +The `minimum` method's right hand side passes `descending` as an explicit argument to `maximum(xs)`. +With this setup, the following calls are all well-formed, and they all normalize to the last one: +```scala +minimum(xs) +maximum(xs).with(descending) +maximum(xs).with(descending.with(listOrd)) +maximum(xs).with(descending.with(listOrd.with(intOrd))) +``` + +## Multiple With Clauses + +There can be several `with` clauses in a definition. Example: +```scala +def f(u: Universe) with (ctx: u.Context) with (s: ctx.Symbol, k: ctx.Kind) = ... +``` +Multiple with clauses are matched left-to-right in applications. Example: +```scala +object global extends Universe { type Context = ... } +given ctx as global.Context { type Symbol = ...; type Kind = ... } +given sym as ctx.Symbol +given kind as ctx.Kind +``` +Then the following calls are all valid (and normalize to the last one) +```scala +f(global) +f(global).with(ctx) +f(global).with(ctx).with(sym, kind) +``` +But `f(global).with(sym, kind)` would give a type error. + +`with` clauses can be freely interspersed with normal parameters, but a normal parameter clause cannot +directly follow a `with` clause consisting only of types outside parentheses. So the following is illegal: +```scala +def f with A, B (x: C) = ... +``` +But the following variants are valid: +```scala +def g with A, B with (x: C) = ... +def h with (A, B) (x: C) = ... +``` + +## Summoning Instances + +The method `summon` in `Predef` returns the given of a specific type. For example, +the given instance for `Ord[List[Int]]` is produced by +```scala +summon[Ord[List[Int]]] // reduces to listOrd.with(intOrd) +``` +The `summon` method is simply defined as the (non-widening) identity function over a context parameter. +```scala +def summon[T] with (x: T): x.type = x +``` + +## Syntax + +Here is the new syntax of parameters and arguments seen as a delta from the [standard context free syntax of Scala 3](../../internals/syntax.md). +``` +ClsParamClauses ::= ... + | ClsParamClause ClsParamClauses + | ClsParamClauses1 +ClsParamClauses1 ::= WithClsParamClause ClsParamClauses + | AnnotTypes ClsParamClauses1 +DefParamClauses ::= ... + | DefParamClause DefParamClauses + | DefParamClauses1 +DefParamClauses1 ::= WithParamClause DefParamClauses + | AnnotTypes DefParamClauses1 +WithClsParamClause ::= ‘with’ (‘(’ (ClsParams | Types) ‘)’ | AnnotTypes) +WithParamClause ::= ‘with’ (‘(’ (DefParams | Types) ‘)’ | AnnotTypes) +Types ::= Type {‘,’ Type} +AnnotTypes ::= AnnotType {‘,’ AnnotType} + +SimpleExpr ::= ... + | SimpleExpr ContextArguments +ParArgumentExprss ::= {ParArgumentExprs | ContextArguments} +ContextArguments ::= ‘.’ ‘with’ ArgumentExprs + +``` diff --git a/docs/docs/reference/contextual/conversions-new.md b/docs/docs/reference/contextual/conversions-new.md new file mode 100644 index 000000000000..7faeb3aac0d5 --- /dev/null +++ b/docs/docs/reference/contextual/conversions-new.md @@ -0,0 +1,75 @@ +--- +layout: doc-page +title: "Implicit Conversions" +--- + +Implicit conversions are defined by given instances of 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 +given Conversion[String, Token] { + def apply(str: String): Token = new KeyWord(str) +} +``` +Using an alias this can be expressed more concisely as: +```scala +given Conversion[String, Token] = new KeyWord(_) +``` +An implicit conversion is applied automatically by the compiler in three situations: + +1. If an expression `e` has type `T`, and `T` does not conform to the expression's expected type `S`. +2. In a selection `e.m` with `e` of type `T`, but `T` defines no member `m`. +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 a given `scala.Conversion` instance that maps +an argument of type `T` to type `S`. In the second and third +case, it looks for a given `scala.Conversion` instance 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)`. + +## Examples + +1. The `Predef` package contains "auto-boxing" conversions that map +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 +given int2Integer as Conversion[Int, java.lang.Integer] = + java.lang.Integer.valueOf(_) +``` + +2. The "magnet" pattern is sometimes used to express many variants of a method. Instead of defining overloaded versions of the method, one can also let the method take one or more arguments of specially defined "magnet" types, into which various argument types can be converted. E.g. +```scala +object Completions { + + // The argument "magnet" type + enum CompletionArg { + case Error(s: String) + case Response(f: Future[HttpResponse]) + case Status(code: Future[StatusCode]) + } + object CompletionArg { + + // conversions defining the possible arguments to pass to `complete` + // these always come with CompletionArg + // They can be invoked explicitly, e.g. + // + // CompletionArg.fromStatusCode(statusCode) + + given fromString as Conversion[String, CompletionArg] = Error(_) + given fromFuture as Conversion[Future[HttpResponse], CompletionArg] = Response(_) + given fromStatusCode as Conversion[Future[StatusCode], CompletionArg] = Status(_) + } + import CompletionArg._ + + def complete[T](arg: CompletionArg) = arg match { + case Error(s) => ... + case Response(f) => ... + case Status(code) => ... + } +} +``` +This setup is more complicated than simple overloading of `complete`, but it can still be useful if normal overloading is not available (as in the case above, since we cannot have two overloaded methods that take `Future[...]` arguments), or if normal overloading would lead to a combinatorial explosion of variants. diff --git a/docs/docs/reference/contextual/conversions.md b/docs/docs/reference/contextual/conversions.md index 6b1ccc8fbbb3..d29eb631e820 100644 --- a/docs/docs/reference/contextual/conversions.md +++ b/docs/docs/reference/contextual/conversions.md @@ -3,6 +3,9 @@ layout: doc-page title: "Implicit Conversions" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./conversions-new.html). + Implicit conversions are defined by given instances of the `scala.Conversion` class. This class is defined in package `scala` as follows: ```scala diff --git a/docs/docs/reference/contextual/delegates.md b/docs/docs/reference/contextual/delegates.md index 954f2e5d932c..b5c37fc0e910 100644 --- a/docs/docs/reference/contextual/delegates.md +++ b/docs/docs/reference/contextual/delegates.md @@ -3,6 +3,9 @@ layout: doc-page title: "Given Instances" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./givens.html). + Given instances (or, simply, "givens") define "canonical" values of certain types that serve for synthesizing arguments to [given clauses](./given-clauses.md). Example: @@ -18,7 +21,7 @@ given intOrd: Ord[Int] { if (x < y) -1 else if (x > y) +1 else 0 } -given listOrd[T]: (ord: Ord[T]) => Ord[List[T]] { +given listOrd[T](given ord: Ord[T]): Ord[List[T]] { def compare(xs: List[T], ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 @@ -33,10 +36,8 @@ given listOrd[T]: (ord: Ord[T]) => Ord[List[T]] { This code defines a trait `Ord` with two given instances. `intOrd` defines a given for the type `Ord[Int]` whereas `listOrd[T]` defines givens for `Ord[List[T]]` for all types `T` that come with a given instance for `Ord[T]` themselves. -The `(ord: Ord[T]) =>` clause in `listOrd` defines a condition: There must be a -given instance of type `Ord[T]` so that a given instance of type `List[Ord[T]]` can -be synthesized. Such conditions are expanded by the compiler to implicit -parameters, which are explained in the [next section](./given-clauses.md). +The `(given ord: Ord[T])` clause in `listOrd` defines an implicit parameter. +Given clauses are further explained in the [next section](./given-clauses.md). ## Anonymous Given Instances @@ -44,7 +45,7 @@ The name of a given instance can be left out. So the definitions of the last section can also be expressed like this: ```scala given Ord[Int] { ... } -given [T]: Ord[T] => Ord[List[T]] { ... } +given [T](given Ord[T]): Ord[List[T]] { ... } ``` If the name of a given is missing, the compiler will synthesize a name from the implemented type(s). @@ -63,7 +64,7 @@ returned for this and all subsequent accesses to `global`. Alias givens can be anonymous, e.g. ```scala given Position = enclosingTree.position -given (outer: Context) => Context = outer.withOwner(currentOwner) +given (given outer: Context): Context = outer.withOwner(currentOwner) ``` An alias given can have type parameters and given clauses just like any other given instance, but it can only implement a single type. diff --git a/docs/docs/reference/contextual/derivation-new.md b/docs/docs/reference/contextual/derivation-new.md new file mode 100644 index 000000000000..467c9cbecdf9 --- /dev/null +++ b/docs/docs/reference/contextual/derivation-new.md @@ -0,0 +1,399 @@ +--- +layout: doc-page +title: Type Class Derivation +--- + +Type class derivation is a way to automatically generate given instances for type classes which satisfy some simple +conditions. A type class in this sense is any trait or class with a type parameter determining the type being operated +on. Common examples are `Eq`, `Ordering`, or `Show`. For example, given the following `Tree` algebraic data type +(ADT), + +```scala +enum Tree[T] derives Eq, Ordering, Show { + case Branch[T](left: Tree[T], right: Tree[T]) + case Leaf[T](elem: T) +} +``` + +The `derives` clause generates the following given instances for the `Eq`, `Ordering` and `Show` type classes in the +companion object of `Tree`, + +```scala +given [T: Eq] as Eq[Tree[T]] = Eq.derived +given [T: Ordering] as Ordering[Tree] = Ordering.derived +given [T: Show] as Show[Tree] = Show.derived +``` + +We say that `Tree` is the _deriving type_ and that the `Eq`, `Ordering` and `Show` instances are _derived instances_. + +### Types supporting `derives` clauses + +All data types can have a `derives` clause. This document focuses primarily on data types which also have a given instance +of the `Mirror` type class available. Given instances of the `Mirror` type class are generated automatically by the compiler +for, + ++ enums and enum cases ++ case classes and case objects ++ sealed classes or traits that have only case classes and case objects as children + +`Mirror` type class instances provide information at the type level about the components and labelling of the type. +They also provide minimal term level infrastructure to allow higher level libraries to provide comprehensive +derivation support. + +```scala +sealed trait Mirror { + + /** the type being mirrored */ + type MirroredType + + /** the type of the elements of the mirrored type */ + type MirroredElemTypes + + /** The mirrored *-type */ + type MirroredMonoType + + /** The name of the type */ + type MirroredLabel <: String + + /** The names of the elements of the type */ + type MirroredElemLabels <: Tuple +} + +object Mirror { + /** The Mirror for a product type */ + trait Product extends Mirror { + + /** Create a new instance of type `T` with elements taken from product `p`. */ + def fromProduct(p: scala.Product): MirroredMonoType + } + + trait Sum extends Mirror { self => + /** The ordinal number of the case class of `x`. For enums, `ordinal(x) == x.ordinal` */ + def ordinal(x: MirroredMonoType): Int + } +} +``` + +Product types (i.e. case classes and objects, and enum cases) have mirrors which are subtypes of `Mirror.Product`. Sum +types (i.e. sealed class or traits with product children, and enums) have mirrors which are subtypes of `Mirror.Sum`. + +For the `Tree` ADT from above the following `Mirror` instances will be automatically provided by the compiler, + +```scala +// Mirror for Tree +Mirror.Sum { + type MirroredType = Tree + type MirroredElemTypes[T] = (Branch[T], Leaf[T]) + type MirroredMonoType = Tree[_] + type MirroredLabels = "Tree" + type MirroredElemLabels = ("Branch", "Leaf") + + def ordinal(x: MirroredMonoType): Int = x match { + case _: Branch[_] => 0 + case _: Leaf[_] => 1 + } +} + +// Mirror for Branch +Mirror.Product { + type MirroredType = Branch + type MirroredElemTypes[T] = (Tree[T], Tree[T]) + type MirroredMonoType = Branch[_] + type MirroredLabels = "Branch" + type MirroredElemLabels = ("left", "right") + + def fromProduct(p: Product): MirroredMonoType = + new Branch(...) +} + +// Mirror for Leaf +Mirror.Product { + type MirroredType = Leaf + type MirroredElemTypes[T] = Tuple1[T] + type MirroredMonoType = Leaf[_] + type MirroredLabels = "Leaf" + type MirroredElemLabels = Tuple1["elem"] + + def fromProduct(p: Product): MirroredMonoType = + new Leaf(...) +} +``` + +Note the following properties of `Mirror` types, + ++ Properties are encoded using types rather than terms. This means that they have no runtime footprint unless used and + also that they are a compile time feature for use with Dotty's metaprogramming facilities. ++ The kinds of `MirroredType` and `MirroredElemTypes` match the kind of the data type the mirror is an instance for. + This allows `Mirrors` to support ADTs of all kinds. ++ There is no distinct representation type for sums or products (ie. there is no `HList` or `Coproduct` type as in + Scala 2 versions of shapeless). Instead the collection of child types of a data type is represented by an ordinary, + possibly parameterized, tuple type. Dotty's metaprogramming facilities can be used to work with these tuple types + as-is, and higher level libraries can be built on top of them. ++ The methods `ordinal` and `fromProduct` are defined in terms of `MirroredMonoType` which is the type of kind-`*` + which is obtained from `MirroredType` by wildcarding its type parameters. + +### Type classes supporting automatic deriving + +A trait or class can appear in a `derives` clause if its companion object defines a method named `derived`. The +signature and implementation of a `derived` method for a type class `TC[_]` are arbitrary but it is typically of the +following form, + +```scala +def derived[T] with Mirror.Of[T] : TC[T] = ... +``` + +That is, the `derived` method takes a context parameter of (some subtype of) type `Mirror` which defines the shape of +the deriving type `T`, and computes the type class implementation according to that shape. This is all that the +provider of an ADT with a `derives` clause has to know about the derivation of a type class instance. + +Note that `derived` methods may have given `Mirror` arguments indirectly (e.g. by having a context argument which in turn +has a context `Mirror`, or not at all (e.g. they might use some completely different user-provided mechanism, for +instance using Dotty macros or runtime reflection). We expect that (direct or indirect) `Mirror` based implementations +will be the most common and that is what this document emphasises. + +Type class authors will most likely use higher level derivation or generic programming libraries to implement +`derived` methods. An example of how a `derived` method might be implemented using _only_ the low level facilities +described above and Dotty's general metaprogramming features is provided below. It is not anticipated that type class +authors would normally implement a `derived` method in this way, however this walkthrough can be taken as a guide for +authors of the higher level derivation libraries that we expect typical type class authors will use (for a fully +worked out example of such a library, see [shapeless 3](https://github.com/milessabin/shapeless/tree/shapeless-3)). + +#### How to write a type class `derived` method using low level mechanisms + +The low-level method we will use to implement a type class `derived` method in this example exploits three new +type-level constructs in Dotty: inline methods, inline matches, and implicit searches via `summonFrom`. Given this definition of the +`Eq` type class, + + +```scala +trait Eq[T] { + def eqv(x: T, y: T): Boolean +} +``` + +we need to implement a method `Eq.derived` on the companion object of `Eq` that produces a given instance for `Eq[T]` given +a `Mirror[T]`. Here is a possible implementation, + +```scala +inline given derived[T] with (m: Mirror.Of[T]) as Eq[T] = { + val elemInstances = summonAll[m.MirroredElemTypes] // (1) + inline m match { // (2) + case s: Mirror.SumOf[T] => eqSum(s, elemInstances) + case p: Mirror.ProductOf[T] => eqProduct(p, elemInstances) + } +} +``` + +Note that `derived` is defined as an `inline` given. This means that the method will be expanded at +call sites (for instance the compiler generated instance definitions in the companion objects of ADTs which have a +`derived Eq` clause), and also that it can be used recursively if necessary, to compute instances for children. + +The body of this method (1) first materializes the `Eq` instances for all the child types of type the instance is +being derived for. This is either all the branches of a sum type or all the fields of a product type. The +implementation of `summonAll` is `inline` and uses Dotty's `summonFrom` construct to collect the instances as a +`List`, + +```scala +inline def summonAll[T]: T = summonFrom { + case t: T => t +} + +inline def summonAll[T <: Tuple]: List[Eq[_]] = inline erasedValue[T] match { + case _: Unit => Nil + case _: (t *: ts) => summon[Eq[t]] :: summonAll[ts] +} +``` + +with the instances for children in hand the `derived` method uses an `inline match` to dispatch to methods which can +construct instances for either sums or products (2). Note that because `derived` is `inline` the match will be +resolved at compile-time and only the left-hand side of the matching case will be inlined into the generated code with +types refined as revealed by the match. + +In the sum case, `eqSum`, we use the runtime `ordinal` values of the arguments to `eqv` to first check if the two +values are of the same subtype of the ADT (3) and then, if they are, to further test for equality based on the `Eq` +instance for the appropriate ADT subtype using the auxiliary method `check` (4). + +```scala +def eqSum[T](s: Mirror.SumOf[T], elems: List[Eq[_]]): Eq[T] = + new Eq[T] { + def eqv(x: T, y: T): Boolean = { + val ordx = s.ordinal(x) // (3) + (s.ordinal(y) == ordx) && check(elems(ordx))(x, y) // (4) + } + } +``` + +In the product case, `eqProduct` we test the runtime values of the arguments to `eqv` for equality as products based +on the `Eq` instances for the fields of the data type (5), + +```scala +def eqProduct[T](p: Mirror.ProductOf[T], elems: List[Eq[_]]): Eq[T] = + new Eq[T] { + def eqv(x: T, y: T): Boolean = + iterator(x).zip(iterator(y)).zip(elems.iterator).forall { // (5) + case ((x, y), elem) => check(elem)(x, y) + } + } +``` + +Pulling this all together we have the following complete implementation, + +```scala +import scala.deriving._ +import scala.compiletime.{erasedValue, summonFrom} + +inline def summon[T]: T = summonFrom { + case t: T => t +} + +inline def summonAll[T <: Tuple]: List[Eq[_]] = inline erasedValue[T] match { + case _: Unit => Nil + case _: (t *: ts) => summon[Eq[t]] :: summonAll[ts] +} + +trait Eq[T] { + def eqv(x: T, y: T): Boolean +} + +object Eq { + given Eq[Int] as { + def eqv(x: Int, y: Int) = x == y + } + + def check(elem: Eq[_])(x: Any, y: Any): Boolean = + elem.asInstanceOf[Eq[Any]].eqv(x, y) + + def iterator[T](p: T) = p.asInstanceOf[Product].productIterator + + def eqSum[T](s: Mirror.SumOf[T], elems: List[Eq[_]]): Eq[T] = + new Eq[T] { + def eqv(x: T, y: T): Boolean = { + val ordx = s.ordinal(x) + (s.ordinal(y) == ordx) && check(elems(ordx))(x, y) + } + } + + def eqProduct[T](p: Mirror.ProductOf[T], elems: List[Eq[_]]): Eq[T] = + new Eq[T] { + def eqv(x: T, y: T): Boolean = + iterator(x).zip(iterator(y)).zip(elems.iterator).forall { + case ((x, y), elem) => check(elem)(x, y) + } + } + + inline given derived[T] with (m: Mirror.Of[T]) as Eq[T] = { + val elemInstances = summonAll[m.MirroredElemTypes] + inline m match { + case s: Mirror.SumOf[T] => eqSum(s, elemInstances) + case p: Mirror.ProductOf[T] => eqProduct(p, elemInstances) + } + } +} +``` + +we can test this relative to a simple ADT like so, + +```scala +enum Opt[+T] derives Eq { + case Sm(t: T) + case Nn +} + +object Test extends App { + import Opt._ + val eqoi = summon[Eq[Opt[Int]]] + assert(eqoi.eqv(Sm(23), Sm(23))) + assert(!eqoi.eqv(Sm(23), Sm(13))) + assert(!eqoi.eqv(Sm(23), Nn)) +} +``` + +In this case the code that is generated by the inline expansion for the derived `Eq` instance for `Opt` looks like the +following, after a little polishing, + +```scala +given derived$Eq[T] with (eqT: Eq[T]) as Eq[Opt[T]] = + eqSum(summon[Mirror[Opt[T]]], + List( + eqProduct(summon[Mirror[Sm[T]]], List(summon[Eq[T]])) + eqProduct(summon[Mirror[Nn.type]], Nil) + ) + ) +``` + +Alternative approaches can be taken to the way that `derived` methods can be defined. For example, more aggressively +inlined variants using Dotty macros, whilst being more involved for type class authors to write than the example +above, can produce code for type classes like `Eq` which eliminate all the abstraction artefacts (eg. the `Lists` of +child instances in the above) and generate code which is indistinguishable from what a programmer might write by hand. +As a third example, using a higher level library such as shapeless the type class author could define an equivalent +`derived` method as, + +```scala +given eqSum[A] with (inst: => K0.CoproductInstances[Eq, A]) as Eq[A] { + def eqv(x: A, y: A): Boolean = inst.fold2(x, y)(false)( + [t] => (eqt: Eq[t], t0: t, t1: t) => eqt.eqv(t0, t1) + ) +} + +given eqProduct[A] with (inst: K0.ProductInstances[Eq, A]) as Eq[A] { + def eqv(x: A, y: A): Boolean = inst.foldLeft2(x, y)(true: Boolean)( + [t] => (acc: Boolean, eqt: Eq[t], t0: t, t1: t) => Complete(!eqt.eqv(t0, t1))(false)(true) + ) +} + + +inline def derived[A] with (gen: K0.Generic[A]) as Eq[A] = gen.derive(eqSum, eqProduct) +``` + +The framework described here enables all three of these approaches without mandating any of them. + +### Deriving instances elsewhere + +Sometimes one would like to derive a type class instance for an ADT after the ADT is defined, without being able to +change the code of the ADT itself. To do this, simply define an instance using the `derived` method of the type class +as right-hand side. E.g, to implement `Ordering` for `Option` define, + +```scala +given [T: Ordering] as Ordering[Option[T]] = Ordering.derived +``` + +Assuming the `Ordering.derived` method has a context parameter of type `Mirror[T]` it will be satisfied by the +compiler generated `Mirror` instance for `Option` and the derivation of the instance will be expanded on the right +hand side of this definition in the same way as an instance defined in ADT companion objects. + +### Syntax + +``` +Template ::= InheritClauses [TemplateBody] +EnumDef ::= id ClassConstr InheritClauses EnumBody +InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}] +ConstrApps ::= ConstrApp {‘with’ ConstrApp} + | ConstrApp {‘,’ ConstrApp} +``` + +### Discussion + +This type class derivation framework is intentionally very small and low-level. There are essentially two pieces of +infrastructure in compiler-generated `Mirror` instances, + ++ type members encoding properties of the mirrored types. ++ a minimal value level mechanism for working generically with terms of the mirrored types. + +The `Mirror` infrastructure can be seen as an extension of the existing `Product` infrastructure for case classes: +typically `Mirror` types will be implemented by the ADTs companion object, hence the type members and the `ordinal` or +`fromProduct` methods will be members of that object. The primary motivation for this design decision, and the +decision to encode properties via types rather than terms was to keep the bytecode and runtime footprint of the +feature small enough to make it possible to provide `Mirror` instances _unconditionally_. + +Whilst `Mirrors` encode properties precisely via type members, the value level `ordinal` and `fromProduct` are +somewhat weakly typed (because they are defined in terms of `MirroredMonoType`) just like the members of `Product`. +This means that code for generic type classes has to ensure that type exploration and value selection proceed in +lockstep and it has to assert this conformance in some places using casts. If generic type classes are correctly +written these casts will never fail. + +As mentioned, however, the compiler-provided mechansim is intentionally very low level and it is anticipated that +higher level type class derivation and generic programming libraries will build on this and Dotty's other +metaprogramming facilities to hide these low-level details from type class authors and general users. Type class +derivation in the style of both shapeless and Magnolia are possible (a prototype of shapeless 3, which combines +aspects of both shapeless 2 and Magnolia has been developed alongside this language feature) as is a more aggressively +inlined style, supported by Dotty's new quote/splice macro and inlining facilities. diff --git a/docs/docs/reference/contextual/derivation.md b/docs/docs/reference/contextual/derivation.md index 96883ce983e6..b6e4d8c005e7 100644 --- a/docs/docs/reference/contextual/derivation.md +++ b/docs/docs/reference/contextual/derivation.md @@ -3,6 +3,9 @@ layout: doc-page title: Type Class Derivation --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./derivation-new.html). + Type class derivation is a way to automatically generate given instances for type classes which satisfy some simple conditions. A type class in this sense is any trait or class with a type parameter determining the type being operated on. Common examples are `Eq`, `Ordering`, or `Show`. For example, given the following `Tree` algebraic data type @@ -175,7 +178,7 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that a `Mirror[T]`. Here is a possible implementation, ```scala -inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { +inline given derived[T](given m: Mirror.Of[T]): Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] // (1) inline m match { // (2) case s: Mirror.SumOf[T] => eqSum(s, elemInstances) @@ -281,7 +284,7 @@ object Eq { } } - inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { + inline given derived[T](given m: Mirror.Of[T]): Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] inline m match { case s: Mirror.SumOf[T] => eqSum(s, elemInstances) @@ -312,7 +315,7 @@ In this case the code that is generated by the inline expansion for the derived following, after a little polishing, ```scala -given derived$Eq[T]: (eqT: Eq[T]) => Eq[Opt[T]] = +given derived$Eq[T](given eqT: Eq[T]): Eq[Opt[T]] = eqSum(summon[Mirror[Opt[T]]], List( eqProduct(summon[Mirror[Sm[T]]], List(summon[Eq[T]])) @@ -329,13 +332,13 @@ As a third example, using a higher level library such as shapeless the type clas `derived` method as, ```scala -given eqSum[A] (inst: => K0.CoproductInstances[Eq, A]) => Eq[A] { +given eqSum[A](given inst: => K0.CoproductInstances[Eq, A]): Eq[A] { def eqv(x: A, y: A): Boolean = inst.fold2(x, y)(false)( [t] => (eqt: Eq[t], t0: t, t1: t) => eqt.eqv(t0, t1) ) } -given eqProduct[A] (inst: K0.ProductInstances[Eq, A]) => Eq[A] { +given eqProduct[A](given inst: K0.ProductInstances[Eq, A]): Eq[A] { def eqv(x: A, y: A): Boolean = inst.foldLeft2(x, y)(true: Boolean)( [t] => (acc: Boolean, eqt: Eq[t], t0: t, t1: t) => Complete(!eqt.eqv(t0, t1))(false)(true) ) diff --git a/docs/docs/reference/contextual/extension-methods.md b/docs/docs/reference/contextual/extension-methods.md index 7ad12fe80bdb..d8307ac6cb2e 100644 --- a/docs/docs/reference/contextual/extension-methods.md +++ b/docs/docs/reference/contextual/extension-methods.md @@ -11,7 +11,7 @@ Extension methods allow one to add methods to a type after the type is defined. ```scala case class Circle(x: Double, y: Double, radius: Double) -def (c: Circle) circumference: Double = c.radius * math.Pi * 2 +def (c: Circle).circumference: Double = c.radius * math.Pi * 2 ``` Like regular methods, extension methods can be invoked with infix `.`: @@ -45,7 +45,7 @@ As an example, consider an extension method `longestStrings` on `Seq[String]` de ```scala trait StringSeqOps { - def (xs: Seq[String]) longestStrings = { + def (xs: Seq[String]).longestStrings = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) } @@ -53,7 +53,7 @@ trait StringSeqOps { ``` We can make the extension method available by defining a given `StringSeqOps` instance, like this: ```scala -given ops1: StringSeqOps +given ops1 as StringSeqOps ``` Then ```scala @@ -72,33 +72,37 @@ 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 a given instance `i` - in either the current scope or in the implicit 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 given `g` + in either the current scope or in the context scope of `T` such that `g` defines an extension + method named `m`, then selection is expanded to `g.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 given (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 given (i.e. it is visible at the point of call or it is defined in the companion object of `Circle`). ### Operators The extension method syntax also applies to the definition of operators. -In each case the definition syntax mirrors the way the operator is applied. +In this case it is allowed and preferable to omit the period between the leading parameter list +and the operator. In each case the definition syntax mirrors the way the operator is applied. Examples: ```scala def (x: String) < (y: String) = ... def (x: Elem) +: (xs: Seq[Elem]) = ... +def (x: Number) min (y: Number) = ... "ab" < "c" 1 +: List(2, 3) +x min 3 ``` -The two definitions above translate to +The three definitions above translate to ```scala def < (x: String)(y: String) = ... def +: (xs: Seq[Elem])(x: Elem) = ... +def min(x: Number)(y: Number) = ... ``` -Note that swap of the two parameters `x` and `xs` when translating +Note the swap of the two parameters `x` and `xs` when translating the right-binding operator `+:` to an extension method. This is analogous to the implementation of right binding operators as normal methods. @@ -121,56 +125,60 @@ If an extension method has type parameters, they come immediately after the `def ```scala List(1, 2, 3).second[Int] ``` -### Given Instances for Extension Methods +### Collective Extensions -`given` extensions are given instances that define extension methods and nothing else. Examples: +A collective extension defines one or more concrete methods that have the same type parameters +and prefix parameter. Examples: ```scala -given stringOps: (xs: Seq[String]) extended with { +extension stringOps on (xs: Seq[String]) { def longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) } } -given listOps: [T](xs: List[T]) extended with { +extension listOps on [T](xs: List[T]) { def second = xs.tail.head def third: T = xs.tail.tail.head } -given [T](xs: List[T])(given Ordering[T]) extended with { +extension on [T](xs: List[T]) with Ordering[T]) { def largest(n: Int) = xs.sorted.takeRight(n) } ``` -If a given extension is anonymous (as in the last clause), its name is synthesized from the name of the first defined extension method. +If an extension is anonymous (as in the last clause), its name is synthesized from the name of the first defined extension method. -The extensions above are equivalent to the following regular given instances where the implemented parent is `AnyRef` and the parameters in the `extension` clause are repeated in each extension method definition: +The extensions above are equivalent to the following regular given instances where the implemented parent is `AnyRef` and the leading parameters are repeated in each extension method definition: ```scala -given stringOps: AnyRef { - def (xs: Seq[String]) longestStrings: Seq[String] = { +given stringOps as AnyRef { + def (xs: Seq[String]).longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) } } -given listOps: AnyRef { +given listOps as AnyRef { def [T](xs: List[T]) second = xs.tail.head def [T](xs: List[T]) third: T = xs.tail.tail.head } -given given_largest_of_List_T: AnyRef { - def [T](xs: List[T]) largest (given Ordering[T])(n: Int) = +given extension_largest_List_T as AnyRef { + def [T](xs: List[T]) largest with (Ordering[T]) (n: Int) = xs.sorted.takeRight(n) } ``` ### Syntax -Here are the syntax changes for extension methods and given extensions relative -to the [current syntax](../../internals/syntax.md). `extension` is a soft keyword, recognized only after a `given`. It can be used as an identifier everywhere else. +Here are the syntax changes for extension methods and collective extensions relative +to the [current syntax](../../internals/syntax.md). `extension` is a soft keyword, recognized only +in tandem with `of`. It can be used as an identifier everywhere else. ``` DefSig ::= ... - | ExtParamClause [nl] id DefParamClauses -GivenDef ::= ... - [id ‘:’] ‘extension’ ExtParamClause {GivenParamClause} ExtMethods + | ExtParamClause [nl] [‘.’] id DefParamClauses ExtParamClause ::= [DefTypeParamClause] ‘(’ DefParam ‘)’ -ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’ +TmplDef ::= ... + | ‘extension’ ExtensionDef +ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ‘with’ ExtMethods +ExtMethods ::= ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’ ``` + diff --git a/docs/docs/reference/contextual/given-clauses.md b/docs/docs/reference/contextual/given-clauses.md index 1cf02e3b66f4..6fbd30aa4c3e 100644 --- a/docs/docs/reference/contextual/given-clauses.md +++ b/docs/docs/reference/contextual/given-clauses.md @@ -3,6 +3,9 @@ layout: doc-page title: "Given Parameters" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./context-parameters.html). + Functional programming tends to express most dependencies as simple function parameterization. This is clean and powerful, but it sometimes leads to functions that take many parameters and call trees where the same value is passed over and over again in long call chains to many diff --git a/docs/docs/reference/contextual/given-imports.md b/docs/docs/reference/contextual/given-imports.md new file mode 100644 index 000000000000..8471ade65a93 --- /dev/null +++ b/docs/docs/reference/contextual/given-imports.md @@ -0,0 +1,118 @@ +--- +layout: doc-page +title: "Importing Givens" +--- + +A special form of import wildcard selector is used to import givens. Example: +```scala +object A { + class TC + given tc as TC + def f with TC = ??? +} +object B { + import A._ + import A.{given _} +} +``` +In the code above, the `import A._` clause of object `B` will import all members +of `A` _except_ the given instance `tc`. Conversely, the second import `import A.{given _}` will import _only_ that given instance. +The two import clauses can also be merged into one: +```scala +object B + import A.{given _, _} +``` + +Generally, a normal wildcard selector `_` brings all definitions other than givens or extensions into scope +whereas a `given _` selector brings all givens (including those resulting from extensions) into scope. + +There are two main benefits arising from these rules: + + - It is made clearer where givens in scope are coming from. + In particular, it is not possible to hide imported givens in a long list of regular wildcard imports. + - It enables importing all givens + without importing anything else. This is particularly important since givens + can be anonymous, so the usual recourse of using named imports is not + practical. + +### Importing By Type + +Since givens 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 A.{given TC} +``` +This imports any given in `A` that has a type which conforms to `TC`. Importing givens of several types `T1,...,Tn` +is expressed by multiple `given` selectors. +``` +import A.{given T1, ..., given Tn} +``` +Importing all givens of a parameterized type is expressed by wildcard arguments. +For instance, assuming the object +```scala +object Instances { + given intOrd as Ordering[Int] + given [T: Ordering] listOrd as Ordering[List[T]] + given ec as ExecutionContext = ... + given im as Monoid[Int] +} +``` +the import +```scala +import Instances.{given Ordering[?], given ExecutionContext} +``` +would import the `intOrd`, `listOrd`, and `ec` instances but leave out the `im` instance, 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 +```scala +import Instances.{im, given Ordering[?]} +``` +would import `im`, `intOrd`, and `listOrd` but leave out `ec`. + + + +### Migration + +The rules for imports stated 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 givens and given imports. + +The following modifications avoid this hurdle to migration. + + 1. A `given` import selector 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 `_` or a `given _` wildcard selector. + + 2. In Scala 3.1, old-style implicits accessed through a `_` wildcard import will give a deprecation warning. + + 3. In some version after 3.1, old-style implicits accessed through a `_` wildcard import will give a compiler error. + +These rules mean that library users can use `given _` selectors 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 +representation clauses once their user base has migrated. + +### Syntax + +``` +Import ::= ‘import’ ImportExpr {‘,’ ImportExpr} +ImportExpr ::= StableId ‘.’ ImportSpec +ImportSpec ::= id + | ‘_’ + | ‘{’ ImportSelectors) ‘}’ +ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors] + | WildCardSelector {‘,’ WildCardSelector} +WildCardSelector ::= ‘_' + | ‘given’ (‘_' | InfixType) +Export ::= ‘export’ ImportExpr {‘,’ ImportExpr} +``` \ No newline at end of file diff --git a/docs/docs/reference/contextual/givens.md b/docs/docs/reference/contextual/givens.md new file mode 100644 index 000000000000..fc84de72ef57 --- /dev/null +++ b/docs/docs/reference/contextual/givens.md @@ -0,0 +1,99 @@ +--- +layout: doc-page +title: "Given Instances" +--- + +Given instances (or, simply, "givens") define "canonical" values of certain types +that serve for synthesizing arguments to [context parameters](./context-parameters.md). Example: + +```scala +trait Ord[T] { + def compare(x: T, y: T): Int + def (x: T) < (y: T) = compare(x, y) < 0 + def (x: T) > (y: T) = compare(x, y) > 0 +} + +given intOrd as Ord[Int] { + def compare(x: Int, y: Int) = + if (x < y) -1 else if (x > y) +1 else 0 +} + +given listOrd[T] with (ord: Ord[T]) as Ord[List[T]] { + + def compare(xs: List[T], ys: List[T]): Int = (xs, ys) match + case (Nil, Nil) => 0 + case (Nil, _) => -1 + case (_, Nil) => +1 + case (x :: xs1, y :: ys1) => + val fst = ord.compare(x, y) + if (fst != 0) fst else compare(xs1, ys1) +} +``` +This code defines a trait `Ord` with two given declarations. `intOrd` defines +a given for the type `Ord[Int]` whereas `listOrd[T]` defines givens +for `Ord[List[T]]` for all types `T` that come with a given for `Ord[T]` +themselves. The `with` clause in `listOrd` defines a condition: There must be a +given of type `Ord[T]` for a given of type `List[Ord[T]]` to exist. +Such conditions are expanded by the compiler to context +parameters, which are explained in the [next section](./context-parameters.md). + +## Anonymous Givens + +The name of a given can be left out. So the definitions +of the last section can also be expressed like this: +```scala +given Ord[Int] { ... } +given [T] with Ord[T] as Ord[List[T]] { ... } +``` +If the name of a given is missing, the compiler will synthesize a name from +the implemented type(s). + +## Alias Givens + +An alias can be used to define a given that is equal to some expression. E.g.: +```scala +given global as ExecutionContext = new ForkJoinPool() +``` +This creates a given `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 givens can be anonymous, e.g. +```scala +given as Position = enclosingTree.position +given with (outer: Context) as Context = outer.withOwner(currentOwner) +``` +An alias given can have type parameters and implicit parameters just like any other given, +but it can only implement a single type. + +## Given Whitebox Macro Instances + +An `inline` alias given can be marked as a whitebox macro by writing +`_ <:` in front of the implemented type. Example: +```scala +inline given mkAnnotations[A, T] as _ <: Annotations[A, T] = ${ + // code producing a value of a subtype of Annotations +} +``` +The type of an application of `mkAnnotations` is the type of its right hand side, +which can be a proper subtype of the declared result type `Annotations[A, T]`. + +## Given Instance Initialization + +A given without type or context parameters is initialized on-demand, the first +time it is accessed. If a given has type or context parameters, a fresh instance +is created for each reference. + +## Syntax + +Here is the new syntax for givens, seen as a delta from the [standard context free syntax of Scala 3](../../internals/syntax.md). + +``` +TmplDef ::= ... + | ‘given’ GivenDef +GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr + | [GivenSig] ConstrApp {‘,’ ConstrApp } [TemplateBody] +GivenSig ::= [id] [DefTypeParamClause] {WithParamsOrTypes} ‘as’ +WithParamsOrTypes ::= WithParamClause | AnnotTypes +``` diff --git a/docs/docs/reference/contextual/implicit-by-name-parameters.md b/docs/docs/reference/contextual/implicit-by-name-parameters.md index 8cb846b53946..4c723f647434 100644 --- a/docs/docs/reference/contextual/implicit-by-name-parameters.md +++ b/docs/docs/reference/contextual/implicit-by-name-parameters.md @@ -3,6 +3,9 @@ layout: doc-page title: "Implicit By-Name Parameters" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./by-name-context-parameters.html). + Implicit parameters can be declared by-name to avoid a divergent inferred expansion. Example: ```scala @@ -12,7 +15,7 @@ trait Codec[T] { given intCodec: Codec[Int] = ??? -given optionCodec[T]: (ev: => Codec[T]) => Codec[Option[T]] { +given optionCodec[T](given ev: => Codec[T]): Codec[Option[T]] { def write(xo: Option[T]) = xo match { case Some(x) => ev.write(x) case None => diff --git a/docs/docs/reference/contextual/implicit-function-types-spec.md b/docs/docs/reference/contextual/implicit-function-types-spec.md index cda87bd33e54..c87a37499199 100644 --- a/docs/docs/reference/contextual/implicit-function-types-spec.md +++ b/docs/docs/reference/contextual/implicit-function-types-spec.md @@ -3,6 +3,10 @@ layout: doc-page title: "Implicit Function Types - More Details" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./context-functions-spec.html). + + ## Syntax Type ::= ... diff --git a/docs/docs/reference/contextual/implicit-function-types.md b/docs/docs/reference/contextual/implicit-function-types.md index 6ceaa6114a35..80391b4fcd7e 100644 --- a/docs/docs/reference/contextual/implicit-function-types.md +++ b/docs/docs/reference/contextual/implicit-function-types.md @@ -3,6 +3,9 @@ layout: doc-page title: "Implicit Function Types" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./context-functions.html). + _Implicit functions_ are functions with (only) implicit parameters. Their types are _implicit function types_. Here is an example of an implicit function type: diff --git a/docs/docs/reference/contextual/implicit-match.md b/docs/docs/reference/contextual/implicit-match.md deleted file mode 100644 index 09b8bae92cd1..000000000000 --- a/docs/docs/reference/contextual/implicit-match.md +++ /dev/null @@ -1 +0,0 @@ -The contents of this page have [moved](./delegate-match.md). \ No newline at end of file diff --git a/docs/docs/reference/contextual/import-delegate.md b/docs/docs/reference/contextual/import-delegate.md index ddf1bdaead61..8f07167238a0 100644 --- a/docs/docs/reference/contextual/import-delegate.md +++ b/docs/docs/reference/contextual/import-delegate.md @@ -3,6 +3,9 @@ layout: doc-page title: "Import Given" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./given-imports.html). + A special form of import wildcard selector is used to import given instances. Example: ```scala object A { diff --git a/docs/docs/reference/contextual/inferable-by-name-parameters.md b/docs/docs/reference/contextual/inferable-by-name-parameters.md index ea618a2a87c0..fd5984334404 100644 --- a/docs/docs/reference/contextual/inferable-by-name-parameters.md +++ b/docs/docs/reference/contextual/inferable-by-name-parameters.md @@ -1 +1 @@ -The contents of this page have [moved](./implicit-by-name-parameters.md). \ No newline at end of file +The contents of this page have [moved](./by-name-context-parameters.md). diff --git a/docs/docs/reference/contextual/inferable-params.md b/docs/docs/reference/contextual/inferable-params.md index 169d050ec4e7..4f395ccbdc39 100644 --- a/docs/docs/reference/contextual/inferable-params.md +++ b/docs/docs/reference/contextual/inferable-params.md @@ -1 +1 @@ -The contents of this page have [moved](./given-clauses.md). \ No newline at end of file +The contents of this page have [moved](./context-parameters.md). \ No newline at end of file diff --git a/docs/docs/reference/contextual/instance-defs.md b/docs/docs/reference/contextual/instance-defs.md index 94a595052db3..8dd75ffb98c3 100644 --- a/docs/docs/reference/contextual/instance-defs.md +++ b/docs/docs/reference/contextual/instance-defs.md @@ -1 +1 @@ -The contents of this page have [moved](./delegates.md). \ No newline at end of file +The contents of this page have [moved](./givens.md). \ No newline at end of file diff --git a/docs/docs/reference/contextual/motivation-new.md b/docs/docs/reference/contextual/motivation-new.md new file mode 100644 index 000000000000..ed2402e6cd98 --- /dev/null +++ b/docs/docs/reference/contextual/motivation-new.md @@ -0,0 +1,81 @@ +--- +layout: doc-page +title: "Overview" +--- + +### Critique of the Status Quo + +Scala's implicits are its most distinguished feature. They are _the_ fundamental way to abstract over context. They represent a unified paradigm with a great variety of use cases, among them: implementing type classes, establishing context, dependency injection, expressing capabilities, computing new types and proving relationships between them. + +Following Haskell, Scala was the second popular language to have some form of implicits. Other languages have followed suit. E.g Rust's traits or Swift's protocol extensions. Design proposals are also on the table for Kotlin as [compile time dependency resolution](https://github.com/Kotlin/KEEP/blob/e863b25f8b3f2e9b9aaac361c6ee52be31453ee0/proposals/compile-time-dependency-resolution.md), for C# as [Shapes and Extensions](https://github.com/dotnet/csharplang/issues/164) +or for F# as [Traits](https://github.com/MattWindsor91/visualfsharp/blob/hackathon-vs/examples/fsconcepts.md). Implicits are also a common feature of theorem provers such as Coq or Agda. + +Even though these designs use widely different terminology, they are all variants of the core idea of _term inference_. Given a type, the compiler synthesizes a "canonical" term that has that type. Scala embodies the idea in a purer form than most other languages: An implicit parameter directly leads to an inferred argument term that could also be written down explicitly. By contrast, typeclass based designs are less direct since they hide term inference behind some form of type classification and do not offer the option of writing the inferred quantities (typically, dictionaries) explicitly. + +Given that term inference is where the industry is heading, and given that Scala has it in a very pure form, how come implicits are not more popular? In fact, it's fair to say that implicits are at the same time Scala's most distinguished and most controversial feature. I believe this is due to a number of aspects that together make implicits harder to learn than necessary and also make it harder to prevent abuses. + +Particular criticisms are: + +1. Being very powerful, implicits are easily over-used and mis-used. This observation holds in almost all cases when we talk about _implicit conversions_, which, even though conceptually different, share the same syntax with other implicit definitions. For instance, regarding the two definitions + + ```scala + implicit def i1(implicit x: T): C[T] = ... + implicit def i2(x: T): C[T] = ... + ``` + + the first of these is a conditional implicit _value_, the second an implicit _conversion_. Conditional implicit values are a cornerstone for expressing type classes, whereas most applications of implicit conversions have turned out to be of dubious value. The problem is that many newcomers to the language start with defining implicit conversions since they are easy to understand and seem powerful and convenient. Scala 3 will put under a language flag both definitions and applications of "undisciplined" implicit conversions between types defined elsewhere. This is a useful step to push back against overuse of implicit conversions. But the problem remains that syntactically, conversions and values just look too similar for comfort. + + 2. Another widespread abuse is over-reliance on implicit imports. This often leads to inscrutable type errors that go away with the right import incantation, leaving a feeling of frustration. Conversely, it is hard to see what implicits a program uses since implicits can hide anywhere in a long list of imports. + + 3. The syntax of implicit definitions is too minimal. It consists of a single modifier, `implicit`, that can be attached to a large number of language constructs. A problem with this for newcomers is that it conveys mechanism instead of intent. For instance, a typeclass instance is an implicit object or val if unconditional and an implicit def with implicit parameters referring to some class if conditional. This describes precisely what the implicit definitions translate to -- just drop the `implicit` modifier, and that's it! But the cues that define intent are rather indirect and can be easily misread, as demonstrated by the definitions of `i1` and `i2` above. + + 4. The syntax of implicit parameters also has shortcomings. While implicit _parameters_ are designated specifically, arguments are not. Passing an argument to an implicit parameter looks like a regular application `f(arg)`. This is problematic because it means there can be confusion regarding what parameter gets instantiated in a call. For instance, in + ```scala + def currentMap(implicit ctx: Context): Map[String, Int] + ``` + one cannot write `currentMap("abc")` since the string "abc" is taken as explicit argument to the implicit `ctx` parameter. One has to write `currentMap.apply("abc")` instead, which is awkward and irregular. For the same reason, a method definition can only have one implicit parameter section and it must always come last. This restriction not only reduces orthogonality, but also prevents some useful program constructs, such as a method with a regular parameter whose type depends on an implicit value. Finally, it's also a bit annoying that implicit parameters must have a name, even though in many cases that name is never referenced. + + 5. Implicits pose challenges for tooling. The set of available implicits depends on context, so command completion has to take context into account. This is feasible in an IDE but docs like ScalaDoc that are based static web pages can only provide an approximation. Another problem is that failed implicit searches often give very unspecific error messages, in particular if some deeply recursive implicit search has failed. Note that the Dotty compiler has already made a lot of progress in the error diagnostics area. If a recursive search fails some levels down, it shows what was constructed and what is missing. Also, it suggests imports that can bring missing implicits in scope. + +None of the shortcomings is fatal, after all implicits are very widely used, and many libraries and applications rely on them. But together, they make code using implicits a lot more cumbersome and less clear than it could be. + +Historically, many of these shortcomings come from the way implicits were gradually "discovered" in Scala. Scala originally had only implicit conversions with the intended use case of "extending" a class or trait after it was defined, i.e. what is expressed by implicit classes in later versions of Scala. Implicit parameters and instance definitions came later in 2006 and we picked similar syntax since it seemed convenient. For the same reason, no effort was made to distinguish implicit imports or arguments from normal ones. + +Existing Scala programmers by and large have gotten used to the status quo and see little need for change. But for newcomers this status quo presents a big hurdle. I believe if we want to overcome that hurdle, we should take a step back and allow ourselves to consider a radically new design. + +### The New Design + +The following pages introduce a redesign of contextual abstractions in Scala. They introduce four fundamental changes: + + 1. [Given Instances](./givens.md) 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. [With Clauses](./context-parameters.md) define are a new syntax for implicit _parameters_ and their _arguments_. It unambiguously aligns parameters and arguments, solving a number of language warts. It also allows us to have several with clauses in a definition. + + 3. ["Given" Imports](./given-imports.md) are a new class of import selectors that specifically import + givens and nothing else. + + 4. [Implicit Conversions](./conversions.md) are now expressed as given instances 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.md), which carry over unchanged. + - [Extension Methods](./extension-methods.md) replace implicit classes in a way that integrates better with typeclasses. + - [Implementing Typeclasses](./typeclasses.md) demonstrates how some common typeclasses can be implemented using the new constructs. + - [Typeclass Derivation](./derivation.md) introduces constructs to automatically derive typeclass instances for ADTs. + - [Multiversal Equality](./multiversal-equality.md) introduces a special typeclass to support type safe equality. + - [Context Functions](./context-functions.md) provide a way to abstract over context parameters. + - [By-Name Context Parameters](./by-name-context-parameters.md) are an essential tool to define recursive synthesized values without looping. + - [Relationship with Scala 2 Implicits](./relationship-implicits.md) discusses the relationship between old-style implicits and new-style givens 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 givens 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 givens 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. + +Could we achieve the same goals by tweaking existing implicits? After having tried for a long time, I believe now that this is impossible. + + - First, some of the problems are clearly syntactic and require different syntax to solve them. + - Second, there is the problem how to migrate. We cannot change the rules in mid-flight. At some stage of language evolution we need to accommodate both the new and the old rules. With a syntax change, this is easy: Introduce the new syntax with new rules, support the old syntax for a while to facilitate cross compilation, deprecate and phase out the old syntax at some later time. Keeping the same syntax does not offer this path, and in fact does not seem to offer any viable path for evolution + - 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/motivation.md b/docs/docs/reference/contextual/motivation.md index f0277de5d014..0a219547a931 100644 --- a/docs/docs/reference/contextual/motivation.md +++ b/docs/docs/reference/contextual/motivation.md @@ -3,6 +3,9 @@ layout: doc-page title: "Overview" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./motovation-new.html). + ### Critique of the Status Quo Scala's implicits are its most distinguished feature. They are _the_ fundamental way to abstract over context. They represent a unified paradigm with a great variety of use cases, among them: implementing type classes, establishing context, dependency injection, expressing capabilities, computing new types and proving relationships between them. diff --git a/docs/docs/reference/contextual/multiversal-equality-new.md b/docs/docs/reference/contextual/multiversal-equality-new.md new file mode 100644 index 000000000000..3ea0a7c6a816 --- /dev/null +++ b/docs/docs/reference/contextual/multiversal-equality-new.md @@ -0,0 +1,213 @@ +--- +layout: doc-page +title: "Multiversal Equality" +--- + +Previously, Scala had universal equality: Two values of any types +could be compared with each other with `==` and `!=`. This came from +the fact that `==` and `!=` are implemented in terms of Java's +`equals` method, which can also compare values of any two reference +types. + +Universal equality is convenient. But it is also dangerous since it +undermines type safety. For instance, let's assume one is left after some refactoring +with an erroneous program where a value `y` has type `S` instead of the correct type `T`. + +```scala +val x = ... // of type T +val y = ... // of type S, but should be T +x == y // typechecks, will always yield false +``` + +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 +safer. It uses a binary typeclass `Eql` to indicate that values of +two given types can be compared with each other. +The example above would not typecheck if `S` or `T` was a class +that derives `Eql`, e.g. +```scala +class T derives Eql +``` +Alternatively, one can also provide an `Eql` given instance directly, like this: +```scala +given as 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 +affects type checking but it has no significance for runtime +behavior, since `==` always maps to `equals` and `!=` always maps to +the negation of `equals`. The right hand side `Eql.derived` of the definition +is a value that has any `Eql` instance as its type. Here is the definition of class +`Eql` and its companion object: +```scala +package scala +import annotation.implicitNotFound + +@implicitNotFound("Values of types ${L} and ${R} cannot be compared with == or !=") +sealed trait Eql[-L, -R] + +object Eql { + object derived extends Eql[Any, Any] +} +``` + +One can have several `Eql` given instances 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 +given as Eql[A, A] = Eql.derived +given as Eql[B, B] = Eql.derived +given as Eql[A, B] = Eql.derived +given as Eql[B, A] = Eql.derived +``` +The `scala.Eql` object defines a number of `Eql` given instances 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` given. `eqlAny` is defined as follows: + +```scala +def eqlAny[L, R]: Eql[L, R] = Eql.derived +``` + +Even though `eqlAny` is not declared a given, 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 +defined on them, or the language feature `strictEquality` is enabled + +The primary motivation for having `eqlAny` is backwards compatibility, +if this is of no concern, one can disable `eqlAny` by enabling the language +feature `strictEquality`. As for all language features this can be either +done with an import + +```scala +import scala.language.strictEquality +``` +or with a command line option `-language:strictEquality`. + +## Deriving Eql Instances + +Instead of defining `Eql` instances directly, it is often more convenient to derive them. Example: +```scala +class Box[T](x: T) derives Eql +``` +By the usual rules of [typeclass derivation](./derivation.md), +this generates the following `Eql` given in the companion object of `Box`: +```scala +given [T, U] with Eql[T, U]) as Eql[Box[T], Box[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 there is an instance for `Eql[Int, Long]` +new Box(1) == new Box("a") // error: can't compare +new Box(1) == 1 // error: can't compare +``` + +## Precise Rules for Equality Checking + +The precise rules for equality checking are as follows. + +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 there is a given of type `Eql[T, U]`. + +In the default case where the `strictEquality` feature is not enabled the comparison is +also legal if + + 1. `T` and `U` are the same, or + 2. one of `T`, `U` is a subtype of the _lifted_ version of the other type, or + 3. neither `T` nor `U` have a _reflexive_ `Eql` instance. + +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]` + succeeds. + +## Predefined Eql Instances + +The `Eql` object defines instances 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`. + +Instances are defined so that every one of these types has a _reflexive_ `Eql` instance, 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_). + - `Boolean` can be compared with `java.lang.Boolean` (and _vice versa_). + - `Char` can be compared with `java.lang.Character` (and _vice versa_). + - Two sequences (of arbitrary subtypes of `scala.collection.Seq`) can be compared + with each other if their element types can be compared. The two sequence types + need not be the same. + - Two sets (of arbitrary subtypes of `scala.collection.Set`) can be compared + with each other if their element types can be compared. The two set types + need not be the same. + - Any subtype of `AnyRef` can be compared with `Null` (and _vice versa_). + +## Why Two Type Parameters? + +One particular feature of the `Eql` type is that it takes _two_ type parameters, representing the types of the two items to be compared. By contrast, conventional +implementations of an equality type class take only a single type parameter which represents the common type of _both_ operands. One type parameter is simpler than two, so why go through the additional complication? The reason has to do with the fact that, rather than coming up with a type class where no operation existed before, +we are dealing with a refinement of pre-existing, universal equality. It's best illustrated through an example. + +Say you want to come up with a safe version of the `contains` method on `List[T]`. The original definition of `contains` in the standard library was: +```scala +class List[+T] { + ... + def contains(x: Any): Boolean +} +``` +That uses universal equality in an unsafe way since it permits arguments of any type to be compared with the list's elements. The "obvious" alternative definition +```scala + def contains(x: T): Boolean +``` +does not work, since it refers to the covariant parameter `T` in a nonvariant context. The only variance-correct way to use the type parameter `T` in `contains` is as a lower bound: +```scala + def contains[U >: T](x: U): Boolean +``` +This generic version of `contains` is the one used in the current (Scala 2.13) version of `List`. +It looks different but it admits exactly the same applications as the `contains(x: Any)` definition we started with. +However, we can make it more useful (i.e. restrictive) by adding an `Eql` parameter: +```scala + def contains[U >: T](x: U) with Eql[T, U] : Boolean // (1) +``` +This version of `contains` is equality-safe! More precisely, given +`x: T`, `xs: List[T]` and `y: U`, then `xs.contains(y)` is type-correct if and only if +`x == y` is type-correct. + +Unfortunately, the crucial ability to "lift" equality type checking from simple equality and pattern matching to arbitrary user-defined operations gets lost if we restrict ourselves to an equality class with a single type parameter. Consider the following signature of `contains` with a hypothetical `Eql1[T]` type class: +```scala + def contains[U >: T](x: U) with 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`. + +The situation is different under `-language:strictEquality`. In that case, +the `Eql[Any, Any]` or `Eql1[Any]` instances would never be available, and the +single and two-parameter versions would indeed coincide for most practical purposes. + +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 +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. + +For these reasons, it looks like a two-parameter type class is the only way forward because it can take the existing ecosystem where it is and migrate it towards a future where more and more code uses safe equality. + +In applications where `-language:strictEquality` is the default one could also introduce a one-parameter type alias such as +```scala +type Eq[-T] = Eql[T, T] +``` +Operations needing safe equality could then use this alias instead of the two-parameter `Eql` class. But it would only +work under `-language:strictEquality`, since otherwise the universal `Eq[Any]` instance would be available everywhere. + + +More on multiversal equality is found in a [blog post](http://www.scala-lang.org/blog/2016/05/06/multiversal-equality.html) +and a [Github issue](https://github.com/lampepfl/dotty/issues/1247). diff --git a/docs/docs/reference/contextual/multiversal-equality.md b/docs/docs/reference/contextual/multiversal-equality.md index 82bb34967d2f..c0417f4e24d7 100644 --- a/docs/docs/reference/contextual/multiversal-equality.md +++ b/docs/docs/reference/contextual/multiversal-equality.md @@ -2,6 +2,8 @@ layout: doc-page title: "Multiversal Equality" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./multiversal-equality-new.html). Previously, Scala had universal equality: Two values of any types could be compared with each other with `==` and `!=`. This came from diff --git a/docs/docs/reference/contextual/query-types-spec.md b/docs/docs/reference/contextual/query-types-spec.md index ae227a78306b..2dc89a97b62e 100644 --- a/docs/docs/reference/contextual/query-types-spec.md +++ b/docs/docs/reference/contextual/query-types-spec.md @@ -1 +1 @@ -The contents of this page have [moved](./implicit-function-types-spec.md). \ No newline at end of file +The contents of this page have [moved](./context-functions-spec.md). \ No newline at end of file diff --git a/docs/docs/reference/contextual/query-types.md b/docs/docs/reference/contextual/query-types.md index 8131f6183d43..43b8d6c60754 100644 --- a/docs/docs/reference/contextual/query-types.md +++ b/docs/docs/reference/contextual/query-types.md @@ -1 +1 @@ -The contents of this page have [moved](./implicit-function-types.md). \ No newline at end of file +The contents of this page have [moved](./context-functions.md). \ No newline at end of file diff --git a/docs/docs/reference/contextual/relationship-implicits-new.md b/docs/docs/reference/contextual/relationship-implicits-new.md new file mode 100644 index 000000000000..d0d06d3cfb8c --- /dev/null +++ b/docs/docs/reference/contextual/relationship-implicits-new.md @@ -0,0 +1,189 @@ +--- +layout: doc-page +title: Relationship with Scala 2 Implicits +--- + +Many, but not all, of the new contextual abstraction features in Scala 3 can be mapped to Scala 2's implicits. This page gives a rundown on the relationships between new and old features. + +## Simulating Scala 3 Contextual Abstraction Concepts with Scala 2 Implicits + +### Given Instances + +Given instances can be mapped to combinations of implicit objects, classes and implicit methods. + + 1. Given instances without parameters are mapped to implicit objects. E.g., + ```scala + given intOrd as Ord[Int] { ... } + ``` + maps to + ```scala + implicit object IntOrd extends Ord[Int] { ... } + ``` + 2. Parameterized givens are mapped to combinations of classes and implicit methods. E.g., + ```scala + given listOrd[T] with (ord: Ord[T]) as Ord[List[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. Alias givens map to implicit methods or implicit lazy vals. If an alias has neither type nor implicit parameters, + it is treated as a lazy val, unless the right hand side is a simple reference, in which case we can use a forwarder to + that reference without caching it. + +Examples: +```scala +given global as ExecutionContext = new ForkJoinContext() + +val ctx: Context +given as Context = ctx +``` +would map to +```scala +final implicit lazy val global: ExecutionContext = new ForkJoinContext() +final implicit def given_Context = ctx +``` + +### Anonymous Givens + +Anonymous givens 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` givens above were left out, the following names would be synthesized instead: +```scala +given given_Ord_Int as Ord[Int] { ... } +given given_Ord_List[T] as Ord[List[T]] { ... } +``` +The synthesized type names are formed from + + - the prefix `given_`, + - 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. + +Tuples are treated as transparent, i.e. a type `F[(X, Y)]` would get the synthesized name +`F_X_Y`. Directly implemented function types `A => B` are represented as `A_to_B`. Function types used as arguments to other type constructors are represented as `Function`. + +### Anonymous Collective Extensions + +Anonymous collective extensions also get compiler synthesized names, which are formed from + + - the prefix `extension_` + - the name of the first defined extension method + - the simple name of the first parameter type of this extension method + - the simple name(s) of the toplevel argument type constructors to this type. + +For example, the extension +```scala +extension on [T] (xs: List[T]) { + def second = ... +} +``` +gets the synthesized name `extension_second_List_T`. + +### Given Clauses + +Given clauses correspond largely to Scala-2's implicit parameter clauses. E.g. +```scala +def max[T](x: T, y: T) with (ord: Ord[T]) : T +``` +would be written +```scala +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 parameters of with clauses _must_ be written using `.with(...)`, +mirroring the definition syntax. E.g, `max(2, 3).with(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. + +The `summon` method corresponds to `implicitly` in Scala 2. +It is precisely the same as the `the` method in Shapeless. +The difference between `summon` (or `the`) and `implicitly` is +that `summon` can return a more precise type than the type that was +asked for. + +### Context Bounds + +Context bounds are the same in both language versions. They expand to the respective forms of implicit parameters. + +**Note:** To ease migration, context bounds in Dotty map for a limited time to old-style implicit parameters for which arguments can be passed either followin `.with(...)` or +with a normal application. Once old-style implicits are deprecated, context bounds +will map to with clauses instead. + +### Extension Methods + +Extension methods have no direct counterpart in Scala 2, but they can be simulated with implicit classes. For instance, the extension method +```scala +def (c: Circle).circumference: Double = c.radius * math.Pi * 2 +``` +could be simulated to some degree by +```scala +implicit class CircleDecorator(c: Circle) extends AnyVal { + def circumference: Double = c.radius * math.Pi * 2 +} +``` +Abstract extension methods in traits that are implemented in given 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. + +### 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. + +### Implicit Function Types + +Implicit function types have no analogue in Scala 2. + +### Implicit By-Name Parameters + +Implicit by-name parameters are not supported in Scala 2, but can be emulated to some degree by the `Lazy` type in Shapeless. + +## Simulating Scala 2 Implicits in Scala 3 + +### Implicit Conversions + +Implicit conversion methods in Scala 2 can be expressed as given instances 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 +given stringToToken as Conversion[String, Token] { + def apply(str: String): Token = KeyWord(str) +} +``` +or +```scala +given stringToToken as Conversion[String, Token] = KeyWord(_) +``` + +### 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 given as `Conversion` type. + +### Implicit Values + +Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an alias given. +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 +given as 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 alias given. E.g., Scala 2's +```scala +implicit def symDecorator: SymDecorator +``` +can be expressed in Dotty as +```scala +def symDecorator: SymDecorator +given as SymDecorator = symDecorator +``` + +## Implementation Status and Timeline + +The Dotty implementation implements both Scala-2's implicits and the new abstractions. In fact, support for Scala-2's implicits is an essential part of the common language subset between 2.13/2.14 and Dotty. +Migration to the new abstractions will be supported by making automatic rewritings available. + +Depending on adoption patterns, old style implicits might start to be deprecated in a version following Scala 3.0. diff --git a/docs/docs/reference/contextual/relationship-implicits.md b/docs/docs/reference/contextual/relationship-implicits.md index 0d6f39eefdad..a659a12fba3a 100644 --- a/docs/docs/reference/contextual/relationship-implicits.md +++ b/docs/docs/reference/contextual/relationship-implicits.md @@ -3,6 +3,9 @@ layout: doc-page title: Relationship with Scala 2 Implicits --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./relationship-implicits-new.html). + Many, but not all, of the new contextual abstraction features in Scala 3 can be mapped to Scala 2's implicits. This page gives a rundown on the relationships between new and old features. ## Simulating Contextual Abstraction with Implicits @@ -21,7 +24,7 @@ Given instances can be mapped to combinations of implicit objects, classes and i ``` 2. Parameterized given instances are mapped to combinations of classes and implicit methods. E.g., ```scala - given listOrd[T]: (ord: Ord[T]) => Ord[List[T]] { ... } + given listOrd[T](given ord: Ord[T]): Ord[List[T]] { ... } ``` maps to ```scala diff --git a/docs/docs/reference/contextual/typeclasses-new.md b/docs/docs/reference/contextual/typeclasses-new.md new file mode 100644 index 000000000000..ee2c20226d0b --- /dev/null +++ b/docs/docs/reference/contextual/typeclasses-new.md @@ -0,0 +1,66 @@ +--- +layout: doc-page +title: "Implementing Typeclasses" +--- + +Given instances, extension methods and context bounds +allow a concise and natural expression of _typeclasses_. Typeclasses are just traits +with canonical implementations defined by given instances. Here are some examples of standard typeclasses: + +### Semigroups and monoids: + +```scala +trait SemiGroup[T] { + @infix def (x: T) combine (y: T): T +} + +trait Monoid[T] extends SemiGroup[T] { + def unit: T +} + +object Monoid { + def apply[T] with (m: Monoid[T]) = m +} + +given as Monoid[String] { + def (x: String) combine (y: String): String = x.concat(y) + def unit: String = "" +} + +given as Monoid[Int] { + def (x: Int) combine (y: Int): Int = x + y + def unit: Int = 0 +} + +def sum[T: Monoid](xs: List[T]): T = + xs.foldLeft(Monoid[T].unit)(_ combine _) +``` + +### Functors and monads: + +```scala +trait Functor[F[_]] { + def [A, B](x: F[A]).map(f: A => B): F[B] +} + +trait Monad[F[_]] extends Functor[F] { + def [A, B](x: F[A]).flatMap(f: A => F[B]): F[B] + def [A, B](x: F[A]).map(f: A => B) = x.flatMap(f `andThen` pure) + + def pure[A](x: A): F[A] +} + +given listMonad as Monad[List] { + def [A, B](xs: List[A]).flatMap(f: A => List[B]): List[B] = + xs.flatMap(f) + def pure[A](x: A): List[A] = + List(x) +} + +given readerMonad[Ctx] as Monad[[X] =>> Ctx => X] { + def [A, B](r: Ctx => A).flatMap(f: A => Ctx => B): Ctx => B = + ctx => f(r(ctx))(ctx) + def pure[A](x: A): Ctx => A = + ctx => x +} +``` diff --git a/docs/docs/reference/contextual/typeclasses.md b/docs/docs/reference/contextual/typeclasses.md index 3f82ee269231..9afa47a04b45 100644 --- a/docs/docs/reference/contextual/typeclasses.md +++ b/docs/docs/reference/contextual/typeclasses.md @@ -3,6 +3,10 @@ layout: doc-page title: "Implementing Typeclasses" --- +**Note** The syntax described in this section is currently under revision. +[Here is the new version which will be implemented in Dotty 0.22](./typeclasses-new.html). + + Given instances, extension methods and context bounds allow a concise and natural expression of _typeclasses_. Typeclasses are just traits with canonical implementations defined by given instances. Here are some examples of standard typeclasses: diff --git a/docs/docs/reference/other-new-features/indentation-new.md b/docs/docs/reference/other-new-features/indentation-new.md index 700bb973609a..bbb903a730fd 100644 --- a/docs/docs/reference/other-new-features/indentation-new.md +++ b/docs/docs/reference/other-new-features/indentation-new.md @@ -58,10 +58,10 @@ There are two rules: An indentation region can start - after the condition of an `if-else`, or - - after the leading parameter(s) of a given extension method clause, or + - after a ": at end of line" token (see below) - after one of the following tokens: ``` - = => <- if then else while do try catch finally for yield match return with + = => <- if then else while do try catch finally for yield match return ``` If an `` is inserted, the indentation width of the token on the next line is pushed onto `IW`, which makes it the new current indentation width. @@ -90,65 +90,60 @@ if x < 0 Indentation tokens are only inserted in regions where newline statement separators are also inferred: at the toplevel, inside braces `{...}`, but not inside parentheses `(...)`, patterns or types. -### New Role of With +### Optional Braces Around Template Bodies -To make bracews optional for constructs like class bodies, the syntax of the language is changed so that a class body or similar construct may optionally be prefixed with `with`. Since `with` can start an indentation region, this means that all of the following syntaxes are allowed and are equivalent: -```scala -trait A { - def f: Any -} -class C(x: Int) extends A { - def f = x -} -type T = A { - def f: Int -} -``` ---- -```scala -trait A with { - def f: Int -} -class C(x: Int) extends A with { - def f = x -} -type T = A with { - def f: Int -} -``` ---- +The Scala grammar uses the term _template body_ for the definitions of a class, trait, object, given instance or extension that are normally enclosed in braces. The braces around a template body can also be omitted by means of the following rule: + +If at the point where a template body can start there is a `:` that occurs at the end +of a line, and that is followed by at least one indented statement, the recognized +token is changed from ":" to ": at end of line". The latter token is one of the tokens +that can start an indentation region. The Scala grammar is changed so an optional ": at end of line" is allowed in front of a template body. + +Analogous rules apply for enum bodies, type refinements, definitions in an instance creation expressions, and local packages containing nested definitions. + +With these new rules, the following constructs are all valid: ```scala -trait A with +trait A: def f: Int -class C(x: Int) extends A with +class C(x: Int) extends A: def f = x -type T = A with +object O: + def f = 3 + +enum Color: + case Red, Green, Blue + +type T = A: def f: Int -``` -The syntax changes allowing this are as follows: -``` -TemplateBody ::= [‘with’] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ -EnumBody ::= [‘with’] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’ -Packaging ::= ‘package’ QualId [‘with’] ‘{’ TopStatSeq ‘}’ -RefinedType ::= AnnotType {[‘with’] Refinement} -``` -It is assumed here that braces following a `with` can be transparently replaced by an -indentation region. +given [T] with Ord[T] as Ord[List[T]]: + def compare(x: List[T], y: List[T]) = ??? -With the new indentation rules, the previously allowed syntax -``` -class A extends B with - C +extension on (xs: List[Int]): + def second: Int = xs.tail.head + +new A: + def f = 3 + +package p: + def a = 1 +package q: + def b = 2 ``` -becomes illegal since `C` above would be terated as a nested statement inside `A`. More generally, a `with` that separates parent constructors cannot be at the end of a line. One has to write + +The syntax changes allowing this are as follows: ``` -class A extends B - with C +TemplateBody ::= [colonEol] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ +EnumBody ::= [colonEol] ‘{’ [SelfType] EnumStat {semi EnumStat} ‘}’ +Packaging ::= ‘package’ QualId [colonEol] ‘{’ TopStatSeq ‘}’ +RefinedType ::= AnnotType {[colonEol] Refinement} ``` -instead (or replace the "`with`" by a "`,`"). When compiling in Scala-2 mode, a migration warning is issued for the illegal syntax and a (manual) rewrite is suggested. +Here, `colonEol` stands for ": at end of line", as described above. +The lexical analyzer is modified so that a `:` at the end of a line +is reported as `colonEol` if the parser is at a point where a `colonEol` is +valid as next token. ### Spaces vs Tabs diff --git a/docs/docs/reference/other-new-features/indentation.md b/docs/docs/reference/other-new-features/indentation.md index 463e3b040b49..b7c4fdfeb086 100644 --- a/docs/docs/reference/other-new-features/indentation.md +++ b/docs/docs/reference/other-new-features/indentation.md @@ -4,7 +4,7 @@ title: Optional Braces --- **Note** The syntax described in this section is currently under revision. -[Here is the new version which will be implemented in Dotty 0.20](./indentation-new.html). +[Here is the new version which will be implemented in Dotty 0.22](./indentation-new.html). As an experimental feature, Scala 3 treats indentation as significant and allows some occurrences of braces `{...}` to be optional. diff --git a/library/src/scala/IArray.scala b/library/src/scala/IArray.scala index 73c58dad7531..46867b530127 100644 --- a/library/src/scala/IArray.scala +++ b/library/src/scala/IArray.scala @@ -8,7 +8,7 @@ object opaques opaque type IArray[+T] = Array[_ <: T] /** Defines extension methods for immutable arrays */ - given arrayOps: Object with + given arrayOps: Object { /** The selection operation on an immutable array. * @@ -255,6 +255,7 @@ object opaques * If one of the two collections is longer than the other, its remaining elements are ignored. */ def [T, U: ClassTag](arr: IArray[T]) zip(that: IArray[U]): IArray[(T, U)] = genericArrayOps(arr).zip(that).asInstanceOf[IArray[(T, U)]] + } end opaques type IArray[+T] = opaques.IArray[T] diff --git a/library/src/scala/internal/quoted/Matcher.scala b/library/src/scala/internal/quoted/Matcher.scala index 5b41e3fd8ca6..cb0b3b595282 100644 --- a/library/src/scala/internal/quoted/Matcher.scala +++ b/library/src/scala/internal/quoted/Matcher.scala @@ -94,15 +94,13 @@ private[quoted] object Matcher { case _ => notMatched } - private given treeListOps: extension (scrutinees: List[Tree]) with - + private given treeListOps: extension (scrutinees: List[Tree]) { /** Check that all trees match with =?= and concatenate the results with && */ def =?= (patterns: List[Tree])(given Context, Env): Matching = matchLists(scrutinees, patterns)(_ =?= _) + } - end treeListOps - - private given treeOps: extension (scrutinee0: Tree) with + private given treeOps: extension (scrutinee0: Tree) { /** Check that the trees match and return the contents from the pattern holes. * Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes. @@ -307,7 +305,7 @@ private[quoted] object Matcher { notMatched } } - end treeOps + } private object ClosedPatternTerm { /** Matches a term that does not contain free variables defined in the pattern (i.e. not defined in `Env`) */ diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index c3045fd021c5..8bafc89a27a5 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -220,13 +220,14 @@ object Expr { content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2], v3: Expr[T3]) => bodyFn[t](e.unseal, params, List(v1.unseal, v2.unseal, v3.unseal)).seal.asInstanceOf[Expr[t]]) } - private def paramsAndBody[R](given qctx: QuoteContext)(f: Expr[Any]) = { + private def paramsAndBody[R](f: Expr[Any])(given qctx: QuoteContext) = { import qctx.tasty.{given, _} val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = f.unseal.etaExpand (params, body.seal.asInstanceOf[Expr[R]]) } - private def bodyFn[t](given qctx: QuoteContext)(e: qctx.tasty.Term, params: List[qctx.tasty.ValDef], args: List[qctx.tasty.Term]): qctx.tasty.Term = { + private def bodyFn[t](given qctx: QuoteContext) = { + (e: qctx.tasty.Term, params: List[qctx.tasty.ValDef], args: List[qctx.tasty.Term]) => import qctx.tasty.{given, _} val map = params.map(_.symbol).zip(args).toMap new TreeMap { @@ -236,5 +237,4 @@ object Expr { case tree => tree }.transformTerm(e) } - } diff --git a/library/src/scala/quoted/Liftable.scala b/library/src/scala/quoted/Liftable.scala index 7cd903206870..0cb32a593c0b 100644 --- a/library/src/scala/quoted/Liftable.scala +++ b/library/src/scala/quoted/Liftable.scala @@ -103,7 +103,7 @@ object Liftable { else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } } - given iArrayIsLiftable[T: Type]: (ltArray: Liftable[Array[T]]) => Liftable[IArray[T]] { + given iArrayIsLiftable[T: Type](given ltArray: Liftable[Array[T]]): Liftable[IArray[T]] { def toExpr(iarray: IArray[T]): (given QuoteContext) => Expr[IArray[T]] = '{ ${ltArray.toExpr(iarray.asInstanceOf[Array[T]])}.asInstanceOf[IArray[T]] } } diff --git a/staging/src/scala/quoted/staging/staging.scala b/staging/src/scala/quoted/staging/staging.scala index 37b2138dc5c8..c73aee205029 100644 --- a/staging/src/scala/quoted/staging/staging.scala +++ b/staging/src/scala/quoted/staging/staging.scala @@ -23,7 +23,7 @@ package object staging { * * Usage: * ``` - * val e: T = withQuoteContext { // (given qctx: QuoteContext) => + * val e: T = withQuoteContext { // (qctx: QuoteContext) ?=> * thunk * } * ``` @@ -32,7 +32,7 @@ package object staging { * This method should not be called in a context where there is already has a `QuoteContext` * such as within a `run` or a `withQuoteContext`. */ - def withQuoteContext[T](thunk: (given QuoteContext) => T)(given toolbox: Toolbox): T = { + def withQuoteContext[T](thunk: QuoteContext ?=> T)(given toolbox: Toolbox): T = { val noResult = new Object var result: T = noResult.asInstanceOf[T] def dummyRun(given QuoteContext): Expr[Unit] = { diff --git a/staging/test-resources/repl-staging/i6263 b/staging/test-resources/repl-staging/i6263 index 2dd3e41cc695..6e75ce7047d3 100644 --- a/staging/test-resources/repl-staging/i6263 +++ b/staging/test-resources/repl-staging/i6263 @@ -3,7 +3,7 @@ scala> import quoted.staging._ scala> implicit def toolbox: Toolbox = Toolbox.make(getClass.getClassLoader) def toolbox: quoted.staging.Toolbox scala> def fn[T : Type](v : T) = println("ok") -def fn[T](v: T)(implicit evidence$1: quoted.Type[T]): Unit +def fn[T](v: T)(given evidence$1: quoted.Type[T]): Unit scala> withQuoteContext { fn("foo") } ok scala> withQuoteContext { fn((1,2)) } diff --git a/tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala b/tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala index ddcbb5039a84..fe5efaebc587 100644 --- a/tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala +++ b/tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala @@ -1,10 +1,10 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def foo(i: => Int): Int = ${ fooImpl('i) } - def fooImpl(i: Expr[Int])(given QuoteContext): Expr[Int] = { + def fooImpl(i: Expr[Int]) with QuoteContext : Expr[Int] = { given Toolbox = Toolbox.make(getClass.getClassLoader) val y: Int = run(i) y diff --git a/tests/disabled/reflect/run/t3425b/Base_1.scala b/tests/disabled/reflect/run/t3425b/Base_1.scala index bdbc124d2913..e09a30eed2b1 100644 --- a/tests/disabled/reflect/run/t3425b/Base_1.scala +++ b/tests/disabled/reflect/run/t3425b/Base_1.scala @@ -26,7 +26,7 @@ object Gen { } case class Pair(tp1: Tp, tp2: Tp) { def expr = s"((new ABC): $tp)" - def tp = s"($tp1) with ($tp2)" + def tp = s"($tp1) with $tp2" } val traits = Vector("Any", "A", "B", "C") map ("%6s" format _) val types = Vector("P", "Q", "R forSome { type R <: P with Q }") @@ -39,7 +39,7 @@ object Gen { import p._ List( s"type R1_$idx = $tp", - s"type R2_$idx = R1_$idx { val y: (${tp1.elem}) with (${tp2.elem}) }" + s"type R2_$idx = R1_$idx { val y: (${tp1.elem}) with ${tp2.elem} }" ) } diff --git a/tests/disabled/run/xml-interpolation-3/XmlQuote_1.scala b/tests/disabled/run/xml-interpolation-3/XmlQuote_1.scala index 05a0a0804f6b..88eebb720290 100644 --- a/tests/disabled/run/xml-interpolation-3/XmlQuote_1.scala +++ b/tests/disabled/run/xml-interpolation-3/XmlQuote_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ import scala.tasty.Tasty -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.language.implicitConversions diff --git a/tests/generic-java-signatures/i3653.scala b/tests/generic-java-signatures/i3653.scala index 565bec601b71..42a3a727543a 100644 --- a/tests/generic-java-signatures/i3653.scala +++ b/tests/generic-java-signatures/i3653.scala @@ -5,7 +5,7 @@ class Foo { c0: T, c1: T, c2: T, c3: T, c4: T, c5: T, c6: T, c7: T, c8: T, c9: T) => 0 // #6946 - def baz = (x: (given String) => Unit) => x(given "") + def baz = (x: String ?=> Unit) => x.with("") } object Test { diff --git a/tests/run/boundedImports.scala b/tests/invalid/run/boundedImports.scala similarity index 100% rename from tests/run/boundedImports.scala rename to tests/invalid/run/boundedImports.scala diff --git a/tests/neg-custom-args/erased/tupled-function-instances.scala b/tests/neg-custom-args/erased/tupled-function-instances.scala index 550e217c6ad5..b64e26b6aba4 100644 --- a/tests/neg-custom-args/erased/tupled-function-instances.scala +++ b/tests/neg-custom-args/erased/tupled-function-instances.scala @@ -29,30 +29,30 @@ object Test { summon[TupledFunction[erased (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R,(erased (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] // error summon[TupledFunction[erased (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R,(erased (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] // error - summon[TupledFunction[(given erased T) => R, (given erased Tuple1[T]) => R]] // error - summon[TupledFunction[(given erased T, T) => R, (given erased T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T) => R, (given erased T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T) => R, (given erased T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T) => R, (given erased T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error - summon[TupledFunction[(given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R]] // error + summon[TupledFunction[(erased T) ?=> R, (erased Tuple1[T]) ?=> R]] // error + summon[TupledFunction[(erased T, T) ?=> R, (erased T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T) ?=> R, (erased T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T) ?=> R, (erased T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T) ?=> R, (erased T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error + summon[TupledFunction[(erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, (erased T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R]] // error } } \ No newline at end of file diff --git a/tests/neg-custom-args/fatal-warnings/i7821.scala b/tests/neg-custom-args/fatal-warnings/i7821.scala index 4376a7f2e6fc..5903b63219cd 100644 --- a/tests/neg-custom-args/fatal-warnings/i7821.scala +++ b/tests/neg-custom-args/fatal-warnings/i7821.scala @@ -3,7 +3,7 @@ object XObject { def anX: X = 5 - given ops: Object { + given ops as Object { def (x: X) + (y: X): X = x + y } } @@ -13,7 +13,7 @@ object MyXObject { def anX: MyX = XObject.anX - given ops: Object { + given ops as Object { def (x: MyX) + (y: MyX): MyX = x + y // error: warring: Infinite recursive call } } diff --git a/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala b/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala index 08c1ef895d50..047c9d6c30f4 100644 --- a/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala +++ b/tests/neg-custom-args/fatal-warnings/quote-simple-hole.scala @@ -1,6 +1,6 @@ import scala.quoted.QuoteContext -def test(given QuoteContext) = { +def test with QuoteContext = { val x = '{0} val y = '{ // error: Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ. $x diff --git a/tests/neg-custom-args/implicit-conversions.scala b/tests/neg-custom-args/implicit-conversions.scala index b2dc7e612696..5eeb971aabf0 100644 --- a/tests/neg-custom-args/implicit-conversions.scala +++ b/tests/neg-custom-args/implicit-conversions.scala @@ -21,7 +21,7 @@ object D { } object Test { - import D.given + import D.{given _} val x1: A = new B val x2: B = new A // error under -Xfatal-warnings -feature diff --git a/tests/neg-macros/GenericNumLits/Even_1.scala b/tests/neg-macros/GenericNumLits/Even_1.scala index 978ae5f86e5a..ecfa97a35262 100644 --- a/tests/neg-macros/GenericNumLits/Even_1.scala +++ b/tests/neg-macros/GenericNumLits/Even_1.scala @@ -11,7 +11,7 @@ object Even { else throw FromDigits.MalformedNumber(s"$digits is odd") } - private def evenFromDigitsImpl(digits: Expr[String])(given ctx: QuoteContext): Expr[Even] = digits match { + private def evenFromDigitsImpl(digits: Expr[String]) with (ctx: QuoteContext) : Expr[Even] = digits match { case Const(ds) => val ev = try evenFromDigits(ds) diff --git a/tests/neg-macros/delegate-match-1/Macro_1.scala b/tests/neg-macros/delegate-match-1/Macro_1.scala index a697bcf715d9..3af85f3ffbc6 100644 --- a/tests/neg-macros/delegate-match-1/Macro_1.scala +++ b/tests/neg-macros/delegate-match-1/Macro_1.scala @@ -3,8 +3,8 @@ import scala.quoted.matching._ inline def f: Any = ${ fImpl } -private def fImpl(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} +private def fImpl with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} searchImplicit(('[A]).unseal.tpe) match { case x: ImplicitSearchSuccess => '{} diff --git a/tests/neg-macros/delegate-match-2/Macro_1.scala b/tests/neg-macros/delegate-match-2/Macro_1.scala index a697bcf715d9..3af85f3ffbc6 100644 --- a/tests/neg-macros/delegate-match-2/Macro_1.scala +++ b/tests/neg-macros/delegate-match-2/Macro_1.scala @@ -3,8 +3,8 @@ import scala.quoted.matching._ inline def f: Any = ${ fImpl } -private def fImpl(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} +private def fImpl with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} searchImplicit(('[A]).unseal.tpe) match { case x: ImplicitSearchSuccess => '{} diff --git a/tests/neg-macros/delegate-match-3/Macro_1.scala b/tests/neg-macros/delegate-match-3/Macro_1.scala index a697bcf715d9..3af85f3ffbc6 100644 --- a/tests/neg-macros/delegate-match-3/Macro_1.scala +++ b/tests/neg-macros/delegate-match-3/Macro_1.scala @@ -3,8 +3,8 @@ import scala.quoted.matching._ inline def f: Any = ${ fImpl } -private def fImpl(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} +private def fImpl with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} searchImplicit(('[A]).unseal.tpe) match { case x: ImplicitSearchSuccess => '{} diff --git a/tests/neg-macros/i6432/Macro_1.scala b/tests/neg-macros/i6432/Macro_1.scala index 2ca399dc7a1b..1daffcc70935 100644 --- a/tests/neg-macros/i6432/Macro_1.scala +++ b/tests/neg-macros/i6432/Macro_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.quoted.matching._ object Macro { inline def (sc: => StringContext).foo(args: String*): Unit = ${ impl('sc) } - def impl(sc: Expr[StringContext])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(sc: Expr[StringContext]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} sc match { case '{ StringContext(${ExprSeq(parts)}: _*) } => for (part @ Const(s) <- parts) diff --git a/tests/neg-macros/i6432b/Macro_1.scala b/tests/neg-macros/i6432b/Macro_1.scala index 2ca399dc7a1b..1daffcc70935 100644 --- a/tests/neg-macros/i6432b/Macro_1.scala +++ b/tests/neg-macros/i6432b/Macro_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.quoted.matching._ object Macro { inline def (sc: => StringContext).foo(args: String*): Unit = ${ impl('sc) } - def impl(sc: Expr[StringContext])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(sc: Expr[StringContext]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} sc match { case '{ StringContext(${ExprSeq(parts)}: _*) } => for (part @ Const(s) <- parts) diff --git a/tests/neg-macros/i6976/Macro_1.scala b/tests/neg-macros/i6976/Macro_1.scala index 7741617ec781..3279852bef76 100644 --- a/tests/neg-macros/i6976/Macro_1.scala +++ b/tests/neg-macros/i6976/Macro_1.scala @@ -1,14 +1,14 @@ package playground import scala.quoted._, scala.quoted.matching._ -import scala.quoted.given +import scala.quoted.{given _} import scala.tasty._ object macros { inline def mcr(x: => Any) = ${mcrImpl('x)} - def mcrImpl(body: Expr[Any])(given ctx: QuoteContext): Expr[Any] = { - import ctx.tasty.{_, given} + def mcrImpl(body: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = { + import ctx.tasty.{_, given _} body.unseal match { case Block(_, _) => '{2} } } } diff --git a/tests/neg-macros/inline-case-objects/Macro_1.scala b/tests/neg-macros/inline-case-objects/Macro_1.scala index 45f591864f1f..c0e771cc24db 100644 --- a/tests/neg-macros/inline-case-objects/Macro_1.scala +++ b/tests/neg-macros/inline-case-objects/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { - def impl(foo: Any)(given QuoteContext): Expr[String] = Expr(foo.getClass.getCanonicalName) + def impl(foo: Any) with QuoteContext : Expr[String] = Expr(foo.getClass.getCanonicalName) } class Bar { diff --git a/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala b/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala index 48f81291316f..745c5f4892e2 100644 --- a/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -1,34 +1,34 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object E { inline def eval[T](inline x: E[T]): T = ${ impl(x) } - def impl[T](x: E[T])(given QuoteContext): Expr[T] = x.lift + def impl[T](x: E[T]) with QuoteContext : Expr[T] = x.lift } trait E[T] { - def lift(given QuoteContext): Expr[T] + def lift with QuoteContext : Expr[T] } case class I(n: Int) extends E[Int] { - def lift(given QuoteContext): Expr[Int] = n + def lift with QuoteContext : Expr[Int] = n } case class Plus[T](x: E[T], y: E[T])(implicit op: Plus2[T]) extends E[T] { - def lift(given QuoteContext): Expr[T] = op(x.lift, y.lift) + def lift with QuoteContext : Expr[T] = op(x.lift, y.lift) } trait Op2[T] { - def apply(x: Expr[T], y: Expr[T])(given QuoteContext): Expr[T] + def apply(x: Expr[T], y: Expr[T]) with QuoteContext : Expr[T] } trait Plus2[T] extends Op2[T] object Plus2 { implicit case object IPlus extends Plus2[Int] { - def apply(x: Expr[Int], y: Expr[Int])(given QuoteContext): Expr[Int] = '{$x + $y} + def apply(x: Expr[Int], y: Expr[Int]) with QuoteContext : Expr[Int] = '{$x + $y} } } diff --git a/tests/neg-macros/inline-option/Macro_1.scala b/tests/neg-macros/inline-option/Macro_1.scala index 0eaa64d92f02..7ca34882a06d 100644 --- a/tests/neg-macros/inline-option/Macro_1.scala +++ b/tests/neg-macros/inline-option/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macro { - def impl(opt: Option[Int])(given QuoteContext): Expr[Int] = opt match { + def impl(opt: Option[Int]) with QuoteContext : Expr[Int] = opt match { case Some(i) => Expr(i) case None => '{-1} } diff --git a/tests/neg-macros/inline-tuples-1/Macro_1.scala b/tests/neg-macros/inline-tuples-1/Macro_1.scala index 374be1966fe8..7317640726bd 100644 --- a/tests/neg-macros/inline-tuples-1/Macro_1.scala +++ b/tests/neg-macros/inline-tuples-1/Macro_1.scala @@ -1,28 +1,28 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { - def tup1(tup: Tuple1[Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup2(tup: Tuple2[Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup3(tup: Tuple3[Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup4(tup: Tuple4[Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup5(tup: Tuple5[Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup6(tup: Tuple6[Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup7(tup: Tuple7[Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup8(tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup9(tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup10(tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup11(tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup12(tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup13(tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup14(tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup15(tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup16(tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup17(tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup18(tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup19(tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup20(tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup21(tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup22(tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup1(tup: Tuple1[Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup2(tup: Tuple2[Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup3(tup: Tuple3[Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup4(tup: Tuple4[Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup5(tup: Tuple5[Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup6(tup: Tuple6[Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup7(tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup8(tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup9(tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup10(tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup11(tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup12(tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup13(tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup14(tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup15(tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup16(tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup17(tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup18(tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup19(tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup20(tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup21(tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup22(tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum } diff --git a/tests/neg-macros/macro-class-not-found-1/Foo.scala b/tests/neg-macros/macro-class-not-found-1/Foo.scala index f722502c5ecf..a4ba3ad2c583 100644 --- a/tests/neg-macros/macro-class-not-found-1/Foo.scala +++ b/tests/neg-macros/macro-class-not-found-1/Foo.scala @@ -4,7 +4,7 @@ object Foo { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = + def aMacroImplementation with QuoteContext : Expr[Unit] = throw new NoClassDefFoundError() } diff --git a/tests/neg-macros/macro-class-not-found-2/Foo.scala b/tests/neg-macros/macro-class-not-found-2/Foo.scala index f6b68a2770cd..08c16f5d4b3a 100644 --- a/tests/neg-macros/macro-class-not-found-2/Foo.scala +++ b/tests/neg-macros/macro-class-not-found-2/Foo.scala @@ -4,7 +4,7 @@ object Foo { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = + def aMacroImplementation with QuoteContext : Expr[Unit] = throw new NoClassDefFoundError("this.is.not.a.Class") } diff --git a/tests/neg-macros/macros-in-same-project-1.scala b/tests/neg-macros/macros-in-same-project-1.scala index 2ccbd6d1ce2c..b500e9c8a25b 100644 --- a/tests/neg-macros/macros-in-same-project-1.scala +++ b/tests/neg-macros/macros-in-same-project-1.scala @@ -7,6 +7,6 @@ object Bar { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = '{} + def aMacroImplementation with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/neg-macros/macros-in-same-project-2.scala b/tests/neg-macros/macros-in-same-project-2.scala index ca60fe4666ac..b176777c5e35 100644 --- a/tests/neg-macros/macros-in-same-project-2.scala +++ b/tests/neg-macros/macros-in-same-project-2.scala @@ -8,6 +8,6 @@ object Bar { inline def myMacro(): Unit = myMacro2() inline def myMacro2(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = '{} + def aMacroImplementation with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/neg-macros/macros-in-same-project-4/Bar.scala b/tests/neg-macros/macros-in-same-project-4/Bar.scala index da86189bb201..b90bc0b6d492 100644 --- a/tests/neg-macros/macros-in-same-project-4/Bar.scala +++ b/tests/neg-macros/macros-in-same-project-4/Bar.scala @@ -5,5 +5,5 @@ object Bar { Foo.myMacro() - def hello()(given QuoteContext): Expr[Unit] = '{ println("Hello") } + def hello() with QuoteContext : Expr[Unit] = '{ println("Hello") } } diff --git a/tests/neg-macros/macros-in-same-project-4/Foo.scala b/tests/neg-macros/macros-in-same-project-4/Foo.scala index ecae745a51ed..c3c72d51ee6e 100644 --- a/tests/neg-macros/macros-in-same-project-4/Foo.scala +++ b/tests/neg-macros/macros-in-same-project-4/Foo.scala @@ -4,6 +4,6 @@ object Foo { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = Bar.hello() + def aMacroImplementation with QuoteContext : Expr[Unit] = Bar.hello() } diff --git a/tests/neg-macros/macros-in-same-project-5/Bar.scala b/tests/neg-macros/macros-in-same-project-5/Bar.scala index b3b6e792a984..57cde71ef537 100644 --- a/tests/neg-macros/macros-in-same-project-5/Bar.scala +++ b/tests/neg-macros/macros-in-same-project-5/Bar.scala @@ -4,7 +4,7 @@ object Bar { Foo.myMacro() // error - def aMacroImplementation(given QuoteContext): Expr[Unit] = Bar.hello() + def aMacroImplementation with QuoteContext : Expr[Unit] = Bar.hello() - def hello()(given QuoteContext): Expr[Unit] = '{ println("Hello") } + def hello() with QuoteContext : Expr[Unit] = '{ println("Hello") } } diff --git a/tests/neg-macros/macros-in-same-project-6/Foo.scala b/tests/neg-macros/macros-in-same-project-6/Foo.scala index 7822c7fd234e..116cae3a15b7 100644 --- a/tests/neg-macros/macros-in-same-project-6/Foo.scala +++ b/tests/neg-macros/macros-in-same-project-6/Foo.scala @@ -4,7 +4,7 @@ object Foo { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given qctx: QuoteContext): Expr[Unit] = { + def aMacroImplementation with (qctx: QuoteContext) : Expr[Unit] = { import qctx.tasty._ error("some error", rootPosition) throw new NoClassDefFoundError("Bar$") diff --git a/tests/neg-macros/quote-complex-top-splice.scala b/tests/neg-macros/quote-complex-top-splice.scala index c44d7fc15043..d82fab0a9940 100644 --- a/tests/neg-macros/quote-complex-top-splice.scala +++ b/tests/neg-macros/quote-complex-top-splice.scala @@ -28,6 +28,6 @@ object Test { impl(1) } - def impl(i: Int)(given QuoteContext): Expr[Unit] = '{} + def impl(i: Int) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/neg-macros/quote-error-2/Macro_1.scala b/tests/neg-macros/quote-error-2/Macro_1.scala index ee0c8f4644e3..0081023602cb 100644 --- a/tests/neg-macros/quote-error-2/Macro_1.scala +++ b/tests/neg-macros/quote-error-2/Macro_1.scala @@ -2,10 +2,10 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${ fooImpl(b) } - def fooImpl(b: Boolean)(given QuoteContext): Expr[Unit] = + def fooImpl(b: Boolean) with QuoteContext : Expr[Unit] = '{println(${msg(b)})} - def msg(b: Boolean)(given qctx: QuoteContext): Expr[String] = + def msg(b: Boolean) with (qctx: QuoteContext) : Expr[String] = if (b) '{"foo(true)"} else { qctx.error("foo cannot be called with false"); '{ ??? } } diff --git a/tests/neg-macros/quote-error/Macro_1.scala b/tests/neg-macros/quote-error/Macro_1.scala index e948617ebc85..cef6b8e58389 100644 --- a/tests/neg-macros/quote-error/Macro_1.scala +++ b/tests/neg-macros/quote-error/Macro_1.scala @@ -2,7 +2,7 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} - def fooImpl(b: Boolean)(given qctx: QuoteContext): Expr[Unit] = + def fooImpl(b: Boolean) with (qctx: QuoteContext) : Expr[Unit] = if (b) '{println("foo(true)")} else { qctx.error("foo cannot be called with false"); '{ ??? } } } diff --git a/tests/neg-macros/quote-exception/Macro_1.scala b/tests/neg-macros/quote-exception/Macro_1.scala index b094bce7ee82..c16adce20bd9 100644 --- a/tests/neg-macros/quote-exception/Macro_1.scala +++ b/tests/neg-macros/quote-exception/Macro_1.scala @@ -2,7 +2,7 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${fooImpl(b)} - def fooImpl(b: Boolean)(given QuoteContext): Expr[Unit] = + def fooImpl(b: Boolean) with QuoteContext : Expr[Unit] = if (b) '{println("foo(true)")} else ??? } diff --git a/tests/neg-macros/quote-interpolator-core-old.scala b/tests/neg-macros/quote-interpolator-core-old.scala index a9274130cdcd..e4dc9ca1a49e 100644 --- a/tests/neg-macros/quote-interpolator-core-old.scala +++ b/tests/neg-macros/quote-interpolator-core-old.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} // This test checks the correct interpretation of the inlined value class @@ -12,12 +12,12 @@ object FInterpolation { // ... } - private def liftSeq(args: Seq[Expr[Any]])(given QuoteContext): Expr[Seq[Any]] = args match { + private def liftSeq(args: Seq[Expr[Any]]) with QuoteContext : Expr[Seq[Any]] = args match { case x :: xs => '{ ($x) +: ${liftSeq(xs)} } case Nil => '{Seq(): Seq[Any]} } - def fInterpolation(sc: StringContext, args: Seq[Expr[Any]])(given QuoteContext): Expr[String] = { + def fInterpolation(sc: StringContext, args: Seq[Expr[Any]]) with QuoteContext : Expr[String] = { val str: Expr[String] = sc.parts.mkString("") val args1: Expr[Seq[Any]] = liftSeq(args) '{ $str.format($args1: _*) } diff --git a/tests/neg-macros/quote-macro-complex-arg-0.scala b/tests/neg-macros/quote-macro-complex-arg-0.scala index 244e58119b13..c0aa0e9ff498 100644 --- a/tests/neg-macros/quote-macro-complex-arg-0.scala +++ b/tests/neg-macros/quote-macro-complex-arg-0.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Macros { inline def foo(inline i: Int, dummy: Int, j: Int): Int = ${ bar(i + 1, 'j) } // error: i + 1 is not a parameter or field reference - def bar(x: Int, y: Expr[Int])(given QuoteContext): Expr[Int] = '{ ${Expr(x)} + $y } + def bar(x: Int, y: Expr[Int]) with QuoteContext : Expr[Int] = '{ ${Expr(x)} + $y } } diff --git a/tests/neg-macros/quote-macro-splice.scala b/tests/neg-macros/quote-macro-splice.scala index d854ac834c9c..35002b0e1d35 100644 --- a/tests/neg-macros/quote-macro-splice.scala +++ b/tests/neg-macros/quote-macro-splice.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Test { diff --git a/tests/neg-macros/quote-this-b.scala b/tests/neg-macros/quote-this-b.scala index 6d7dee86a5ad..9908ce966d18 100644 --- a/tests/neg-macros/quote-this-b.scala +++ b/tests/neg-macros/quote-this-b.scala @@ -6,5 +6,5 @@ class Foo { } object Foo { - def impl[T](x: Any)(given QuoteContext): Expr[Unit] = '{} + def impl[T](x: Any) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/neg-macros/quote-this.scala b/tests/neg-macros/quote-this.scala index 7b51712f36fb..de860b9047e1 100644 --- a/tests/neg-macros/quote-this.scala +++ b/tests/neg-macros/quote-this.scala @@ -2,7 +2,7 @@ import scala.quoted._ class Foo { - def f(given QuoteContext): Unit = '{ + def f with QuoteContext : Unit = '{ def bar[T](x: T): T = x bar[ this.type // error @@ -24,5 +24,5 @@ class Foo { } object Foo { - def impl[T](x: Any)(given QuoteContext): Expr[Unit] = '{} + def impl[T](x: Any) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/neg-macros/quote-whitebox/Macro_1.scala b/tests/neg-macros/quote-whitebox/Macro_1.scala index fe307b1b8d4e..8bec03ffb00d 100644 --- a/tests/neg-macros/quote-whitebox/Macro_1.scala +++ b/tests/neg-macros/quote-whitebox/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl(str) } - def defaultOfImpl(str: String)(given QuoteContext): Expr[Any] = str match { + def defaultOfImpl(str: String) with QuoteContext : Expr[Any] = str match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/neg-macros/reflect-inline/assert_1.scala b/tests/neg-macros/reflect-inline/assert_1.scala index cdae0f37b43b..87cf382bed33 100644 --- a/tests/neg-macros/reflect-inline/assert_1.scala +++ b/tests/neg-macros/reflect-inline/assert_1.scala @@ -4,7 +4,7 @@ object api { inline def (inline x: String).stripMargin2: String = ${ stripImpl(x) } - private def stripImpl(x: String)(given qctx: QuoteContext): Expr[String] = + private def stripImpl(x: String) with (qctx: QuoteContext) : Expr[String] = Expr(x.stripMargin) } diff --git a/tests/neg-macros/splice-in-top-level-splice-1.scala b/tests/neg-macros/splice-in-top-level-splice-1.scala index 83b01f6b7f84..4114fe5134e1 100644 --- a/tests/neg-macros/splice-in-top-level-splice-1.scala +++ b/tests/neg-macros/splice-in-top-level-splice-1.scala @@ -1,8 +1,8 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Foo { inline def foo(): Int = ${bar(${x})} // error - def x(given QuoteContext): Expr[Int] = '{1} - def bar(i: Int)(given QuoteContext): Expr[Int] = i + def x with QuoteContext : Expr[Int] = '{1} + def bar(i: Int) with QuoteContext : Expr[Int] = i } diff --git a/tests/neg-macros/splice-in-top-level-splice-2.scala b/tests/neg-macros/splice-in-top-level-splice-2.scala index d1a07ebf503c..c836b126bbe2 100644 --- a/tests/neg-macros/splice-in-top-level-splice-2.scala +++ b/tests/neg-macros/splice-in-top-level-splice-2.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Foo { inline def foo(): Int = ${$x} // error - def x(given QuoteContext): Expr[Expr[Int]] = '{ '{1} } + def x with QuoteContext : Expr[Expr[Int]] = '{ '{1} } } diff --git a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala index c0d830772f19..4d7c7bec2926 100644 --- a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala @@ -12,8 +12,8 @@ object Asserts { inline def macroAssert(cond: => Boolean): Unit = ${impl('cond)} - def impl(cond: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = cond.unseal diff --git a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala index 7e3a7159dab5..76c8e04bfbfe 100644 --- a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala @@ -12,8 +12,8 @@ object Asserts { inline def macroAssert(cond: => Boolean): Unit = ${ impl('cond) } - def impl(cond: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = cond.unseal diff --git a/tests/neg-macros/tasty-macro-error/quoted_1.scala b/tests/neg-macros/tasty-macro-error/quoted_1.scala index 69189cd220d1..68950e1a0cf3 100644 --- a/tests/neg-macros/tasty-macro-error/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-error/quoted_1.scala @@ -4,8 +4,8 @@ object Macros { inline def fun(x: Any): Unit = ${ impl('x) } - def impl(x: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(x: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} error("here is the the argument is " + x.unseal.underlyingArgument.show, x.unseal.underlyingArgument.pos) '{} } diff --git a/tests/neg-macros/tasty-macro-positions/quoted_1.scala b/tests/neg-macros/tasty-macro-positions/quoted_1.scala index 729ffe652955..01e0f64d1d20 100644 --- a/tests/neg-macros/tasty-macro-positions/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-positions/quoted_1.scala @@ -4,8 +4,8 @@ object Macros { inline def fun(x: Any): Unit = ${ impl('x) } - def impl(x: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(x: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val pos = x.unseal.underlyingArgument.pos error("here is the the argument is " + x.unseal.underlyingArgument.show, pos) error("here (+5) is the the argument is " + x.unseal.underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5) diff --git a/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala b/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala index d0865fd34833..fe212e1745f5 100644 --- a/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala +++ b/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala @@ -9,8 +9,8 @@ object Macro { object FIntepolator { - def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} error("there are no parts", strCtxExpr.unseal.underlyingArgument.pos) '{ ($strCtxExpr).s($argsExpr: _*) } } diff --git a/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala b/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala index 4cb7ad8570ac..73b6ea28a4a4 100644 --- a/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala +++ b/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala @@ -8,8 +8,8 @@ object Macro { } object FIntepolator { - def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} error("there are no args", argsExpr.unseal.underlyingArgument.pos) '{ ($strCtxExpr).s($argsExpr: _*) } } diff --git a/tests/neg-staging/i5941/macro_1.scala b/tests/neg-staging/i5941/macro_1.scala index 5ec3d910df6a..58188dde86f3 100644 --- a/tests/neg-staging/i5941/macro_1.scala +++ b/tests/neg-staging/i5941/macro_1.scala @@ -11,9 +11,9 @@ object Lens { def set(t: T, s: S): S = _set(t)(s) } - def impl[S: Type, T: Type](getter: Expr[S => T])(given qctx: QuoteContext): Expr[Lens[S, T]] = { + def impl[S: Type, T: Type](getter: Expr[S => T]) with (qctx: QuoteContext) : Expr[Lens[S, T]] = { implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(this.getClass.getClassLoader) - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} import util._ // obj.copy(field = value) def setterBody(obj: Expr[S], value: Expr[T], field: String): Expr[S] = diff --git a/tests/neg-staging/quote-run-in-macro-1/quoted_1.scala b/tests/neg-staging/quote-run-in-macro-1/quoted_1.scala index 072a3c523b20..15c9d1b675a9 100644 --- a/tests/neg-staging/quote-run-in-macro-1/quoted_1.scala +++ b/tests/neg-staging/quote-run-in-macro-1/quoted_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { given Toolbox = Toolbox.make(getClass.getClassLoader) inline def foo(i: => Int): Int = ${ fooImpl('i) } - def fooImpl(i: Expr[Int])(given QuoteContext): Expr[Int] = { + def fooImpl(i: Expr[Int]) with QuoteContext : Expr[Int] = { val y: Int = run(i) y } diff --git a/tests/neg-with-compiler/GenericNumLits/Even_1.scala b/tests/neg-with-compiler/GenericNumLits/Even_1.scala index 978ae5f86e5a..ecfa97a35262 100644 --- a/tests/neg-with-compiler/GenericNumLits/Even_1.scala +++ b/tests/neg-with-compiler/GenericNumLits/Even_1.scala @@ -11,7 +11,7 @@ object Even { else throw FromDigits.MalformedNumber(s"$digits is odd") } - private def evenFromDigitsImpl(digits: Expr[String])(given ctx: QuoteContext): Expr[Even] = digits match { + private def evenFromDigitsImpl(digits: Expr[String]) with (ctx: QuoteContext) : Expr[Even] = digits match { case Const(ds) => val ev = try evenFromDigits(ds) diff --git a/tests/neg/BigFloat/BigFloat_1.scala b/tests/neg/BigFloat/BigFloat_1.scala index 0ef14e84c20d..b4c790579038 100644 --- a/tests/neg/BigFloat/BigFloat_1.scala +++ b/tests/neg/BigFloat/BigFloat_1.scala @@ -30,7 +30,7 @@ object BigFloat extends App { BigFloat(BigInt(intPart), exponent) } - private def fromDigitsImpl(digits: Expr[String])(given ctx: QuoteContext): Expr[BigFloat] = + private def fromDigitsImpl(digits: Expr[String]) with (ctx: QuoteContext) : Expr[BigFloat] = digits match { case Const(ds) => try { diff --git a/tests/neg/exports.scala b/tests/neg/exports.scala index 9d2d4ae66d65..23d2412196cb 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] = ??? - given bitmap : BitMap + given bitmap as BitMap } class Scanner { diff --git a/tests/neg/given-eta.scala b/tests/neg/given-eta.scala index 29427a8c58f3..a6012ce61061 100644 --- a/tests/neg/given-eta.scala +++ b/tests/neg/given-eta.scala @@ -3,7 +3,9 @@ trait D type T def trans(other: T): T -def h(d: D)(given x: d.T)(y: d.T) = (d.trans(x), d.trans(y)) +def h(d: D) with (x: d.T) (y: d.T) = (d.trans(x), d.trans(y)) val z = h // error: no implicit argument of type d.T was found for parameter x of method h +def f with (D) (x: Int) = x // OK +def g with D (x: Int) = x // error // error \ No newline at end of file diff --git a/tests/neg/i2006.scala b/tests/neg/i2006.scala index b297c9996dea..850c2588ba12 100644 --- a/tests/neg/i2006.scala +++ b/tests/neg/i2006.scala @@ -1,10 +1,10 @@ object Test { - inline def foo(f: (given Int) => Int): AnyRef = f // error - inline def bar(f: (given Int) => Int) = f // error + inline def foo(f: Int ?=> Int): AnyRef = f // error + inline def bar(f: Int ?=> Int) = f // error def main(args: Array[String]) = { - foo((given thisTransaction) => 43) - bar((given thisTransaction) => 44) + foo(thisTransaction ?=> 43) + bar(thisTransaction ?=> 44) } } diff --git a/tests/neg/i2146.scala b/tests/neg/i2146.scala index d57b21c1b972..015805dfd4e7 100644 --- a/tests/neg/i2146.scala +++ b/tests/neg/i2146.scala @@ -1,5 +1,5 @@ class Test { - def foo[A, B]: (given A) => (given B) => Int = { (given b: B) => // error: found Int, required: (given A) => (given B) => Int + def foo[A, B]: A ?=> B ?=> Int = { (b: B) ?=> // error: found Int, required: A ?=> B ?=> Int 42 } } diff --git a/tests/neg/i2514.scala b/tests/neg/i2514.scala index d969b0e7c939..a5f69f1bade9 100644 --- a/tests/neg/i2514.scala +++ b/tests/neg/i2514.scala @@ -4,7 +4,7 @@ object Foo { // ^^^^^^^^ // an identifier expected, but 'implicit' found - f(given 2) + f.with(2) } val f = (implicit x: Int) => x // error // error diff --git a/tests/neg/i2514a.scala b/tests/neg/i2514a.scala index 53b0bab6ecfc..f412711e10ad 100644 --- a/tests/neg/i2514a.scala +++ b/tests/neg/i2514a.scala @@ -1,10 +1,10 @@ object Foo { def foo(): Int = { - val f: (given Int) => Int = (given x: Int) =>2 * x - f(given 2) + val f: Int ?=> Int = (x: Int) ?=> 2 * x + f.with(2) } val f = implicit (x: Int) => x - ((given x: Int) => x): ((given Int) => Int) // error: no implicit argument found + ((x: Int) ?=> x): (Int ?=> Int) // error: no implicit argument found } diff --git a/tests/neg/i2960.scala b/tests/neg/i2960.scala index 50ef19a23786..018af938b302 100644 --- a/tests/neg/i2960.scala +++ b/tests/neg/i2960.scala @@ -22,9 +22,9 @@ class Tag(val name: String, this } - def apply[U](f: (given Tag) => U)(implicit t: Tag = null): this.type = { + def apply[U](f: Tag ?=> U)(implicit t: Tag = null): this.type = { if(t != null) t.children += this - f(given this) + f.with(this) this } } diff --git a/tests/neg/i4044a.scala b/tests/neg/i4044a.scala index 1c88be92c4e4..4c04a174a35d 100644 --- a/tests/neg/i4044a.scala +++ b/tests/neg/i4044a.scala @@ -1,6 +1,6 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { val a = '{1} '{ diff --git a/tests/neg/i4044b.scala b/tests/neg/i4044b.scala index 791c7f72e3c0..9b57cf99eca6 100644 --- a/tests/neg/i4044b.scala +++ b/tests/neg/i4044b.scala @@ -1,6 +1,6 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { '{ given QuoteContext = ??? diff --git a/tests/neg/i4196.scala b/tests/neg/i4196.scala index c50b2f689d74..904c0051e73b 100644 --- a/tests/neg/i4196.scala +++ b/tests/neg/i4196.scala @@ -1,6 +1,6 @@ object Test { @annotation.tailrec - def foo(i: (given Unit) => Int): (given Unit) => Int = + def foo(i: Unit ?=> Int): Unit ?=> Int = if (i == 0) 0 else diff --git a/tests/neg/i4611a.scala b/tests/neg/i4611a.scala index b426f91cb078..866d99d7eb4c 100644 --- a/tests/neg/i4611a.scala +++ b/tests/neg/i4611a.scala @@ -1,6 +1,6 @@ // Don't qualify as SAM type because result type is an implicit function type trait Foo { - def foo(x: Int): (given Int) => Int + def foo(x: Int): Int ?=> Int } trait Bar[T] { @@ -12,10 +12,10 @@ class Test { def foo(x: Int) = 1 } - val good2 = new Bar[(given Int) => Int] { + val good2 = new Bar[Int ?=> Int] { def bar(x: Int) = 1 } val bad1: Foo = (x: Int) => 1 // error - val bad2: Bar[(given Int) => Int] = (x: Int) => 1 // error + val bad2: Bar[Int ?=> Int] = (x: Int) => 1 // error } diff --git a/tests/neg/i4611b.scala b/tests/neg/i4611b.scala index 4944ab79964f..916ef80251e4 100644 --- a/tests/neg/i4611b.scala +++ b/tests/neg/i4611b.scala @@ -3,7 +3,7 @@ import scala.concurrent.Future class Response class Request object Request { - type To[T] = (given Request) => T + type To[T] = Request ?=> T } // Don't qualify as SAM type because result type is an implicit function type diff --git a/tests/neg/i5840.scala b/tests/neg/i5840.scala index b038b048857b..05bbee5755c9 100644 --- a/tests/neg/i5840.scala +++ b/tests/neg/i5840.scala @@ -1,11 +1,11 @@ import scala.quoted._ object Test { - type Contextual[T] = (given QuoteContext) => T + type Contextual[T] = QuoteContext ?=> T inline def i5_1[T](n: T)(implicit thisCtx: QuoteContext): T = ${ foo('n) } // OK - inline def i5_2[T](n: T): Contextual[T] = ${ foo('n) } // error: Macros using `(given X) => Y` return types are not yet supported + inline def i5_2[T](n: T): Contextual[T] = ${ foo('n) } // error: Macros using `X ?=> Y` return types are not yet supported def foo[T](x: Expr[T]) = x } diff --git a/tests/neg/i5954b.scala b/tests/neg/i5954b.scala index be5ed83a0f65..4fee54809f5a 100644 --- a/tests/neg/i5954b.scala +++ b/tests/neg/i5954b.scala @@ -5,7 +5,7 @@ abstract class MatcherFactory1[A] { object MatcherFactory1 { import scala.quoted._ - def impl[T](self: Expr[MatcherFactory1[T]#AndNotWord])(given QuoteContext) = + def impl[T](self: Expr[MatcherFactory1[T]#AndNotWord]) with QuoteContext = '{ val a: Any = $self } // error: access to type T from wrong staging level } diff --git a/tests/neg/i5954c.scala b/tests/neg/i5954c.scala index 054e543e460a..75a8bee943fa 100644 --- a/tests/neg/i5954c.scala +++ b/tests/neg/i5954c.scala @@ -5,7 +5,7 @@ abstract class MatcherFactory1 { object MatcherFactory1 { import scala.quoted._ - def impl[T](self: Expr[MatcherFactory1#AndNotWord[T]])(given QuoteContext) = + def impl[T](self: Expr[MatcherFactory1#AndNotWord[T]]) with QuoteContext = '{ val a: Any = $self } // error: access to type T from wrong staging level } diff --git a/tests/neg/i5978.scala b/tests/neg/i5978.scala index 17165de72200..19c523c1e101 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 { - given TP : TokenParser[Char, Position[CharSequence]] {} + given TP as TokenParser[Char, Position[CharSequence]] {} - given FromCharToken(given T: TokenParser[Char, Position[CharSequence]]) + given FromCharToken with (T: TokenParser[Char, Position[CharSequence]]) : Conversion[Char, Position[CharSequence]] = ??? } @@ -22,7 +22,7 @@ object Testcase { val co_x : Position[CharSequence] = 'x' // error { - given XXX : Conversion[Char, Position[CharSequence]] = co_i + given XXX as Conversion[Char, Position[CharSequence]] = co_i val co_y : Position[CharSequence] = 'x' } } diff --git a/tests/neg/i6324.scala b/tests/neg/i6324.scala index fdc345a4a199..3481e1e28a60 100644 --- a/tests/neg/i6324.scala +++ b/tests/neg/i6324.scala @@ -1,5 +1,5 @@ class Test { - def res(x: quoted.Expr[Int])(given tasty.Reflection): quoted.Expr[Int] = x match { + def res(x: quoted.Expr[Int]) with tasty.Reflection : quoted.Expr[Int] = x match { case '{ 1 + $b } => // error: Type must be fully defined. Consider annotating the splice using a type ascription: (${b}: XYZ). b // error: Not found: b } diff --git a/tests/neg/i6325.scala b/tests/neg/i6325.scala index f2a3be496171..639494137d32 100644 --- a/tests/neg/i6325.scala +++ b/tests/neg/i6325.scala @@ -1,6 +1,6 @@ //import scala.quoted.matching.Bind object Test { - def res(x: quoted.Expr[Int])(given tasty.Reflection): quoted.Expr[Int] = x match { + def res(x: quoted.Expr[Int]) with tasty.Reflection : quoted.Expr[Int] = x match { case '{ 1 + (${Bind(b)}: Int) } => ??? // error: Not found: Bind case _ => ??? } diff --git a/tests/neg/i6530b.scala b/tests/neg/i6530b.scala index b60bc7c5c548..f37b7148bb90 100644 --- a/tests/neg/i6530b.scala +++ b/tests/neg/i6530b.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Foo { - def program(given QuoteContext) = '{ + def program with QuoteContext = '{ val tpe: quoted.Type[Int] = ??? val expr: quoted.Expr[Int] = ??? diff --git a/tests/neg/i6739.scala b/tests/neg/i6739.scala index b961e969d7eb..2daae22d5c07 100644 --- a/tests/neg/i6739.scala +++ b/tests/neg/i6739.scala @@ -3,4 +3,4 @@ import scala.quoted._ inline def assert(expr: => Boolean): Unit = ${ assertImpl('expr) } // error: Macro cannot be implemented with an `inline` method -inline def assertImpl(expr: Expr[Boolean])(given QuoteContext): Expr[Unit] = '{ println("Hello World") } +inline def assertImpl(expr: Expr[Boolean]) with QuoteContext : Expr[Unit] = '{ println("Hello World") } diff --git a/tests/neg/i6762.scala b/tests/neg/i6762.scala index dfec28d1f0e4..e6c64820f53f 100644 --- a/tests/neg/i6762.scala +++ b/tests/neg/i6762.scala @@ -1,5 +1,5 @@ -import scala.quoted.{_, given} +import scala.quoted.{_, given _} type G[X] case class Foo[T](x: T) -def f(word: String)(given QuoteContext): Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error // error +def f(word: String) with QuoteContext : Expr[Foo[G[String]]] = '{Foo(${Expr(word)})} // error // error diff --git a/tests/neg/i6762b.scala b/tests/neg/i6762b.scala index 2d7bf0aacef3..3cbb4091f97f 100644 --- a/tests/neg/i6762b.scala +++ b/tests/neg/i6762b.scala @@ -9,5 +9,5 @@ type Liftable given Liftable = ??? implicit object ExprOps { - def (x: T).toExpr[T](given Liftable): Expr[T] = ??? + def (x: T).toExpr[T] with Liftable : Expr[T] = ??? } diff --git a/tests/neg/i6779.check b/tests/neg/i6779.check index 07c3473349d2..91e2313fa5c7 100644 --- a/tests/neg/i6779.check +++ b/tests/neg/i6779.check @@ -1,6 +1,6 @@ -- [E007] Type Mismatch Error: tests/neg/i6779.scala:9:30 -------------------------------------------------------------- -9 |def g1[T](x: T): F[G[T]] = x.f(given summon[Stuff]) // error - | ^^^^^^^^^^^^^^^^^^^^^^^^ +9 |def g1[T](x: T): F[G[T]] = x.f.with(summon[Stuff]) // error + | ^^^^^^^^^^^^^^^^^^^^^^^ | Found: F[T] | Required: F[G[T]] -- [E007] Type Mismatch Error: tests/neg/i6779.scala:11:27 ------------------------------------------------------------- @@ -9,7 +9,7 @@ | Found: F[T] | Required: F[G[T]] -- [E007] Type Mismatch Error: tests/neg/i6779.scala:13:31 ------------------------------------------------------------- -13 |def g3[T](x: T): F[G[T]] = f(x)(given summon[Stuff]) // error - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +13 |def g3[T](x: T): F[G[T]] = f(x).with(summon[Stuff]) // error + | ^^^^^^^^^^^^^^^^^^^^^^^^ | Found: F[T] | Required: F[G[T]] diff --git a/tests/neg/i6779.scala b/tests/neg/i6779.scala index 54998ba378fe..780f889e76a2 100644 --- a/tests/neg/i6779.scala +++ b/tests/neg/i6779.scala @@ -3,11 +3,11 @@ type G[T] type Stuff given Stuff = ??? -def (x: T).f[T](given Stuff): F[T] = ??? +def (x: T).f[T] with Stuff : F[T] = ??? -def g1[T](x: T): F[G[T]] = x.f(given summon[Stuff]) // error +def g1[T](x: T): F[G[T]] = x.f.with(summon[Stuff]) // error def g2[T](x: T): F[G[T]] = x.f // error -def g3[T](x: T): F[G[T]] = f(x)(given summon[Stuff]) // error +def g3[T](x: T): F[G[T]] = f(x).with(summon[Stuff]) // error diff --git a/tests/neg/i6801.scala b/tests/neg/i6801.scala index 0793f0757ad4..ad8845a06cec 100644 --- a/tests/neg/i6801.scala +++ b/tests/neg/i6801.scala @@ -1,5 +1,5 @@ extension myNumericOps on [T](x: T) { - def + (y: T)(given n: Numeric[T]): T = n.plus(x,y) + def + (y: T) with (n: Numeric[T]) : T = n.plus(x,y) } def foo[T: Numeric](x: T) = 1f + x // error: no implicit argument of type Numeric[Any] def bar[T: Numeric](x: T) = x + 1f // error: no implicit argument of type Numeric[Any] \ No newline at end of file diff --git a/tests/neg/i6997b.scala b/tests/neg/i6997b.scala index 83bca5e8e23d..a67885f3a159 100644 --- a/tests/neg/i6997b.scala +++ b/tests/neg/i6997b.scala @@ -1,10 +1,10 @@ package playground -import scala.quoted.{_, given}, scala.quoted.matching._ +import scala.quoted.{_, given _}, scala.quoted.matching._ inline def mcr(x: => Any): Any = ${mcrImpl('x)} -def mcrImpl(body: Expr[Any])(given ctx: QuoteContext): Expr[Any] = { +def mcrImpl(body: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = { val '{$x: $t} = body // error '{ val tmp: $t = $x.asInstanceOf[$t] // error // error diff --git a/tests/neg/i7013.scala b/tests/neg/i7013.scala index 8bfdb3259786..eb5c261feeb5 100644 --- a/tests/neg/i7013.scala +++ b/tests/neg/i7013.scala @@ -1,6 +1,6 @@ import quoted._ -def foo()(given QuoteContext) = { +def foo() with QuoteContext = { class C '[C] // error } diff --git a/tests/neg/i7013b.scala b/tests/neg/i7013b.scala index 056fb2f33f73..0d696246e47f 100644 --- a/tests/neg/i7013b.scala +++ b/tests/neg/i7013b.scala @@ -2,7 +2,7 @@ import quoted._ class Foo { class Bar - def foo()(given QuoteContext) = { + def foo() with QuoteContext = { '[Bar] // error } } diff --git a/tests/neg/i7013c.scala b/tests/neg/i7013c.scala index 609562f9a522..ac1995b4e0ce 100644 --- a/tests/neg/i7013c.scala +++ b/tests/neg/i7013c.scala @@ -1,6 +1,6 @@ import quoted._ -def foo()(given QuoteContext) = { +def foo() with QuoteContext = { type C '[C] // error } diff --git a/tests/neg/i7052.scala b/tests/neg/i7052.scala index a772b44cdd65..2439769f3f29 100644 --- a/tests/neg/i7052.scala +++ b/tests/neg/i7052.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Test { - def foo(str: String)(given QuoteContext) = '{ + def foo(str: String) with QuoteContext = '{ @deprecated(str, "") // error def bar = ??? } diff --git a/tests/neg/i7052b.scala b/tests/neg/i7052b.scala index 941ee57fee37..87898107f61c 100644 --- a/tests/neg/i7052b.scala +++ b/tests/neg/i7052b.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Test { - def foo(str: String)(given QuoteContext) = '{ + def foo(str: String) with QuoteContext = '{ given QuoteContext = ??? '{ @deprecated(str, "") // error diff --git a/tests/neg/i7060.scala b/tests/neg/i7060.scala index 5ab6d0f4905e..6dfde89434e4 100644 --- a/tests/neg/i7060.scala +++ b/tests/neg/i7060.scala @@ -10,10 +10,10 @@ object PostConditions { class Box[T](val t: T) - def res[T](given b: Box[T]): T = b.t + def res[T] with (b: Box[T]) : T = b.t - def [T](e: T) ensure (cond: (given Box[T]) => Boolean): T = { - if (cond(given Box(e))) e + def [T](e: T) ensure (cond: Box[T] ?=> Boolean): T = { + if (cond.with(Box(e))) e else throw new AssertionError("condition not fulfilled") } } \ No newline at end of file diff --git a/tests/neg/i7078.scala b/tests/neg/i7078.scala index d612f7f2104b..2b50e63c88e3 100644 --- a/tests/neg/i7078.scala +++ b/tests/neg/i7078.scala @@ -3,6 +3,6 @@ class B extends A given g1 <: A = B() // error: `<:' is only allowed for given with `inline' modifier // error -inline given g2 <: A // error: <: A is not a class type +inline given g2 as _ <: A // error: <: A is not a class type def foo = 2 // error: `=' expected diff --git a/tests/neg/i7121.scala b/tests/neg/i7121.scala index dc7dfcdb0f2f..905873ab3960 100644 --- a/tests/neg/i7121.scala +++ b/tests/neg/i7121.scala @@ -7,7 +7,7 @@ class Test()(implicit qtx: QuoteContext) { @annot1('{4}) // error def foo(str: String) = () - @annot2(4)(given '[Int]) // error + @annot2(4).with('[Int]) // error def foo2(str: String) = () } diff --git a/tests/neg/i7248.scala b/tests/neg/i7248.scala index 1f117a74d447..04d84992e903 100644 --- a/tests/neg/i7248.scala +++ b/tests/neg/i7248.scala @@ -1,4 +1,4 @@ object Test extends App { - given f[H]: (h: H) => H = h + given f[H] with (h: H) as H = h summon[Int] // error } \ No newline at end of file diff --git a/tests/neg/i7249.scala b/tests/neg/i7249.scala index a53e2886ef7a..7f627b38e76f 100644 --- a/tests/neg/i7249.scala +++ b/tests/neg/i7249.scala @@ -4,6 +4,6 @@ trait F[H, T] object Test extends App { - given f[H, T]: (h: H, t: T) => F[H, T] = ??? + given f[H, T] with (h: H, t: T) as F[H, T] = ??? summon[F[Int, Unit]] // error } \ No newline at end of file diff --git a/tests/neg/i7264d.scala b/tests/neg/i7264d.scala index 67954e92b422..718131746576 100644 --- a/tests/neg/i7264d.scala +++ b/tests/neg/i7264d.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - def f[T2: Type](e: Expr[T2])(given QuoteContext) = e match { + def f[T2: Type](e: Expr[T2]) with QuoteContext = e match { case '{ $x: *:[Int, Any] } => // error: Type argument Any does not conform to upper bound Tuple } diff --git a/tests/neg/i7323.scala b/tests/neg/i7323.scala index 4fdaefc7f14d..3d5d92858909 100644 --- a/tests/neg/i7323.scala +++ b/tests/neg/i7323.scala @@ -1,3 +1,3 @@ trait Foo { type X } -def f[T](given scala.quoted.Type[T]) = ??? +def f[T] with scala.quoted.Type[T] = ??? def g(m: Foo) = f[m.X] // error \ No newline at end of file diff --git a/tests/neg/i7407.scala b/tests/neg/i7407.scala index 03823eb22e68..1a31f290b3f7 100644 --- a/tests/neg/i7407.scala +++ b/tests/neg/i7407.scala @@ -1,2 +1,2 @@ -def qc(given ctx: scala.quoted.QuoteContext) = println(ctx) +def qc with (ctx: scala.quoted.QuoteContext) = println(ctx) inline def g = qc // error: no implicit argument diff --git a/tests/neg/i7425.scala b/tests/neg/i7425.scala index dae559b48f24..06e2a6cfcda4 100644 --- a/tests/neg/i7425.scala +++ b/tests/neg/i7425.scala @@ -2,7 +2,7 @@ class C { def f: Int = 0 } trait D { def f(): Int = 0 } -def foo1(x: C & D) = x.f // error: method f must be called with () argument +def foo1(x: C & D) = x.f // error: method f must be called with argument def foo2(x: C | D) = x.f // error: value f is not a member of C | D def foo3(x: D & C) = x.f // ok def foo4(x: D | C) = x.f // error: value f is not a member of D | C diff --git a/tests/neg/i7459.scala b/tests/neg/i7459.scala index e981f90049b2..8b8d6cef9477 100644 --- a/tests/neg/i7459.scala +++ b/tests/neg/i7459.scala @@ -8,7 +8,7 @@ object Foo { import scala.deriving._ import scala.compiletime.erasedValue -inline def summon[T](given t:T): T = t match { +inline def summon[T] with (t:T) : T = t match { case t: T => t } @@ -47,7 +47,7 @@ object Eq { } } - inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { + inline given derived[T] with (m: Mirror.Of[T]) : Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] inline m match { case s: Mirror.SumOf[T] => eqSum(s, elemInstances) diff --git a/tests/neg/i7526.scala b/tests/neg/i7526.scala index 46266ca8bde6..ed37df14aa73 100644 --- a/tests/neg/i7526.scala +++ b/tests/neg/i7526.scala @@ -9,7 +9,7 @@ trait NetDB extends NetApi: trait NetHelper extends NetApi def compQ(name: => String) - : (given n: NetApi) => Tr[Nothing, n.Comp, n.Comp] = ??? + : (n: NetApi) ?=> Tr[Nothing, n.Comp, n.Comp] = ??? object net extends NetDB with NetHelper import net._ diff --git a/tests/neg/i7603.scala b/tests/neg/i7603.scala index 834ccc83e517..f96755f762b4 100644 --- a/tests/neg/i7603.scala +++ b/tests/neg/i7603.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - def f[T2: Type](e: Expr[T2])(given QuoteContext) = e match { + def f[T2: Type](e: Expr[T2]) with QuoteContext = e match { case '{ $x: ${'[List[$t]]} } => // error case '{ $x: ${y @ '[List[$t]]} } => // error // error } diff --git a/tests/neg/i7618.scala b/tests/neg/i7618.scala index f1566ee0a7fb..56ab3ddec5dd 100644 --- a/tests/neg/i7618.scala +++ b/tests/neg/i7618.scala @@ -1,6 +1,6 @@ package macros -import scala.quoted.{given, _} +import scala.quoted.{given _, _} enum Exp { case Num(n: Int) @@ -12,7 +12,7 @@ enum Exp { object Compiler { import Exp._ - inline def compile(e: Exp, env: Map[String, Expr[Int]])(given ctx: QuoteContext): Expr[Int] = inline e match { + inline def compile(e: Exp, env: Map[String, Expr[Int]]) with (ctx: QuoteContext) : Expr[Int] = inline e match { case Num(n) => Expr(n) case Plus(e1, e2) => @@ -31,6 +31,6 @@ object Example { val exp = Plus(Plus(Num(2), Var("x")), Num(4)) val letExp = Let("x", Num(3), exp) - Compiler.compile(letExp, Map.empty)(given QuoteContext.macroContext) // error // error + Compiler.compile(letExp, Map.empty).with(QuoteContext.macroContext) // error // error } } diff --git a/tests/neg/i7618b.scala b/tests/neg/i7618b.scala index f756ff890179..18d04a1de1d2 100644 --- a/tests/neg/i7618b.scala +++ b/tests/neg/i7618b.scala @@ -1,6 +1,6 @@ package macros -import scala.quoted.{given, _} +import scala.quoted.{given _, _} enum Exp { case Num(n: Int) @@ -12,7 +12,7 @@ enum Exp { object Compiler { import Exp._ - inline def compile(e: Exp, env: Map[String, Expr[Int]])(given ctx: QuoteContext): Expr[Int] = inline e match { + inline def compile(e: Exp, env: Map[String, Expr[Int]]) with (ctx: QuoteContext) : Expr[Int] = inline e match { case Num(n) => Expr(n) case Plus(e1, e2) => @@ -31,6 +31,6 @@ object Example { val exp = Plus(Plus(Num(2), Var("x")), Num(4)) val letExp = Let("x", Num(3), exp) - Compiler.compile(letExp, Map.empty)(given (??? : QuoteContext)) // error + Compiler.compile(letExp, Map.empty).with((??? : QuoteContext)) // error } } diff --git a/tests/neg/i7919.scala b/tests/neg/i7919.scala index c7192a04d296..09a9de6eddc6 100644 --- a/tests/neg/i7919.scala +++ b/tests/neg/i7919.scala @@ -1,9 +1,9 @@ import scala.quoted._ object Test { - def staged[T](given qctx: QuoteContext) = { - import qctx.tasty.{_, given} - given typeT: quoted.Type[T] // error + def staged[T] with (qctx: QuoteContext) = { + import qctx.tasty.{_, given _} + given typeT as quoted.Type[T] // error val tTypeTree = typeT.unseal val tt = typeOf[T] '{ "in staged" } diff --git a/tests/neg/implicit-funs.scala b/tests/neg/implicit-funs.scala index 0c4fedeb6c24..e3718268f1c5 100644 --- a/tests/neg/implicit-funs.scala +++ b/tests/neg/implicit-funs.scala @@ -1,7 +1,7 @@ -trait IF1 extends ((given Int) => Unit) // error -abstract class IF2 extends ((given Int, String) => Unit) // error +trait IF1 extends (Int ?=> Unit) // error +abstract class IF2 extends ((Int, String) ?=> Unit) // error class IF3 extends (ImplicitFunction3[Int, String, Boolean, Unit]) { // error - def apply(given Int, String, Boolean) = () + def apply with (Int, String, Boolean) = () } trait IFXXL extends ((given // error diff --git a/tests/neg/implicit-params.scala b/tests/neg/implicit-params.scala index 9e6198c6f297..e68ef8503ddf 100644 --- a/tests/neg/implicit-params.scala +++ b/tests/neg/implicit-params.scala @@ -3,26 +3,26 @@ object Test { case class C(x: Int) case class D(x: Int) - def f(x: Int)(given c: C) = x + c.x + def f(x: Int) with (c: C) = x + c.x - def g0(x: Int)(given c: C) (y: Int) = x + c.x + y // now OK + def g0(x: Int) with (c: C) (y: Int) = x + c.x + y - def g(x: Int)(given c: C)(given D) = x + c.x + summon[D].x // OK + def g(x: Int) with (c: C) with D = x + c.x + summon[D].x // OK def h(x: Int) given () = x // error: missing return type - given C : C(11) - given D : D(11) + given C as C(11) + given D as D(11) f(1) - f(1)(given C) - f(given 2) // error + f(1).with(C) + f.with(2) // error f(1)(C) // error g(1) // OK - g(1)(given C) // OK - g(1)(given C)(given D(0)) // OK - g(1)(given D) // error + g(1).with(C) // OK + g(1).with(C).with(D(0)) // OK + g(1).with(D) // error g(1)(D) // error g(1)(C)(D) // error } \ No newline at end of file diff --git a/tests/neg/implied-for.scala b/tests/neg/implied-for.scala index 4953561cb0e8..b06b248e90be 100644 --- a/tests/neg/implied-for.scala +++ b/tests/neg/implied-for.scala @@ -3,8 +3,8 @@ class B extends T class C extends T object A { - given b : B - given c : C + given b as B + given c as C } object Test extends App { diff --git a/tests/neg/import-implied.scala b/tests/neg/import-implied.scala index 437e8cb7c089..d5fbaafed39f 100644 --- a/tests/neg/import-implied.scala +++ b/tests/neg/import-implied.scala @@ -1,27 +1,27 @@ class TC object A { - given tc : TC - def foo(given TC) = () + given tc as TC + def foo with TC = () } object B { import A._ foo // error: no implicit argument was found - foo(given tc) // error: not found: tc - foo(given A.tc) // ok + foo.with(tc) // error: not found: tc + foo.with(A.tc) // ok } object C { import A._ import A.tc foo // ok - foo(given tc) // ok + foo.with(tc) // ok } object D { - import A.{foo, given} + import A.{foo, given _} foo // ok - foo(given tc) // ok + foo.with(tc) // ok } object E { - import A.{_, given} + import A.{_, given _} foo // ok - foo(given tc) // ok + foo.with(tc) // ok } diff --git a/tests/neg/inline-quote.scala b/tests/neg/inline-quote.scala index f8e1dac791ed..a5ceac662303 100644 --- a/tests/neg/inline-quote.scala +++ b/tests/neg/inline-quote.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { - inline def foo(x: Expr[Int])(given QuoteContext): Expr[Int] = '{ // error + inline def foo(x: Expr[Int]) with QuoteContext : Expr[Int] = '{ // error println("foo") ${ ${??? : Expr[Int]} diff --git a/tests/neg/machine-state-encoding-with-implicit-match.scala b/tests/neg/machine-state-encoding-with-implicit-match.scala index b217364bf93b..661f26370a74 100644 --- a/tests/neg/machine-state-encoding-with-implicit-match.scala +++ b/tests/neg/machine-state-encoding-with-implicit-match.scala @@ -8,20 +8,20 @@ final class Off extends State @implicitNotFound("State must be Off") class IsOff[S <: State] object IsOff { - given isOff : IsOff[Off] = new IsOff[Off] + given isOff as IsOff[Off] = new IsOff[Off] } @implicitNotFound("State must be On") class IsOn[S <: State] object IsOn { - given isOn : IsOn[On] = new IsOn[On] + given isOn as IsOn[On] = new IsOn[On] } class Machine[S <: State] { - inline def turnOn()(given s: IsOff[S]) <: Machine[On] = summonFrom { + inline def turnOn() with (s: IsOff[S]) <: Machine[On] = summonFrom { case _: IsOff[Off] => new Machine[On] } - inline def turnOff()(given s: IsOn[S]) <: Machine[Off] = summonFrom { + inline def turnOff() with (s: IsOn[S]) <: Machine[Off] = summonFrom { case _: IsOn[On] => new Machine[Off] } } diff --git a/tests/neg/macro-cycle1.scala b/tests/neg/macro-cycle1.scala index 7004812bec46..65e7b16494b2 100644 --- a/tests/neg/macro-cycle1.scala +++ b/tests/neg/macro-cycle1.scala @@ -1,6 +1,6 @@ import scala.quoted.{Expr, QuoteContext} object Test { - def fooImpl(given QuoteContext): Expr[Unit] = '{println("hi")} + def fooImpl with QuoteContext : Expr[Unit] = '{println("hi")} inline def foo: Unit = ${fooImpl} diff --git a/tests/neg/main-functions2.scala b/tests/neg/main-functions2.scala index 40dd9a90752a..30cc89c1d688 100644 --- a/tests/neg/main-functions2.scala +++ b/tests/neg/main-functions2.scala @@ -10,4 +10,4 @@ class Foo { @main def h[T: util.FromString](x: T) = () // error: @main method cannot have type parameters -@main def i(x: Int)(given Foo) = () // error: @main method cannot have implicit parameters +@main def i(x: Int) with Foo = () // error: @main method cannot have implicit parameters diff --git a/tests/neg/missing-implicit1.scala b/tests/neg/missing-implicit1.scala index b985e99532fa..4128b4ce5f6a 100644 --- a/tests/neg/missing-implicit1.scala +++ b/tests/neg/missing-implicit1.scala @@ -5,14 +5,14 @@ object testObjectInstance: } object instances { - given zipOption: Zip[Option] = ??? - given traverseList: Traverse[List] = ??? + given zipOption as Zip[Option] = ??? + given traverseList as Traverse[List] = ??? extension listExtension on [T](xs: List[T]): def second: T = xs.tail.head def [T](xs: List[T]) first: T = xs.head } - def ff(given xs: Zip[Option]) = ??? + def ff with (xs: Zip[Option]) = ??? ff // error @@ -35,11 +35,11 @@ def testLocalInstance = } object instances { - given zipOption: Zip[Option] = ??? - given traverseList: Traverse[List] = ??? + given zipOption as Zip[Option] = ??? + given traverseList as Traverse[List] = ??? } - def ff(given xs: Zip[Option]) = ??? + def ff with (xs: Zip[Option]) = ??? ff // error diff --git a/tests/neg/missing-implicit2.check b/tests/neg/missing-implicit2.check index 59106a0042e4..e4ab5970457b 100644 --- a/tests/neg/missing-implicit2.check +++ b/tests/neg/missing-implicit2.check @@ -1,12 +1,12 @@ --- Error: tests/neg/missing-implicit2.scala:10:18 ---------------------------------------------------------------------- -10 | f(given xFromY) // error - | ^ - | no implicit argument of type Y was found for parameter y of method xFromY +-- Error: tests/neg/missing-implicit2.scala:10:17 ---------------------------------------------------------------------- +10 | f.with(xFromY) // error + | ^ + | no implicit argument of type Y was found for parameter y of method xFromY | - | The following import might fix the problem: + | The following import might fix the problem: | - | import test.instances.y - | + | import test.instances.y + | -- Error: tests/neg/missing-implicit2.scala:16:5 ----------------------------------------------------------------------- 16 | f // error | ^ diff --git a/tests/neg/missing-implicit2.scala b/tests/neg/missing-implicit2.scala index 429fc3b81a61..8c4ccfe36786 100644 --- a/tests/neg/missing-implicit2.scala +++ b/tests/neg/missing-implicit2.scala @@ -1,17 +1,17 @@ trait X trait Y object test: - def f(given x: X) = ??? + def f with (x: X) = ??? object instances { - given y: Y = ??? + given y as Y = ??? } locally { - given xFromY(given y: Y): X = ??? - f(given xFromY) // error + given xFromY with (y: Y) as X = ??? + f.with(xFromY) // error } locally { object instances2 { - given xFromY: Y => X = ??? + given xFromY with Y as X = ??? } f // error } diff --git a/tests/neg/multi-param-derives.scala b/tests/neg/multi-param-derives.scala index 09beddc39734..221b7eb54f2a 100644 --- a/tests/neg/multi-param-derives.scala +++ b/tests/neg/multi-param-derives.scala @@ -5,11 +5,11 @@ object Test extends App { trait Show[T] object Show { given Show[Int] {} - given [T]: (st: Show[T]) => Show[Tuple1[T]] {} - given t2[T, U](given st: Show[T], su: Show[U]) : Show[(T, U)] {} - given t3[T, U, V](given st: Show[T], su: Show[U], sv: Show[V]) : Show[(T, U, V)] {} + given [T] with (st: Show[T]) as Show[Tuple1[T]] {} + given t2[T, U] with (st: Show[T], su: Show[U]) as Show[(T, U)] {} + given t3[T, U, V] with (st: Show[T], su: Show[U], sv: Show[V]) as Show[(T, U, V)] {} - def derived[T](given m: Mirror.Of[T], r: Show[m.MirroredElemTypes]): Show[T] = new Show[T] {} + def derived[T] with (m: Mirror.Of[T], r: Show[m.MirroredElemTypes]) : Show[T] = new Show[T] {} } case class Mono(i: Int) derives Show @@ -22,12 +22,12 @@ object Test extends App { { trait Functor[F[_]] object Functor { - given [C] : Functor[[T] =>> C] {} + given [C] as Functor[[T] =>> C] {} given Functor[[T] =>> Tuple1[T]] {} - given t2 [T] : Functor[[U] =>> (T, U)] {} - given t3 [T, U] : Functor[[V] =>> (T, U, V)] {} + given t2 [T] as Functor[[U] =>> (T, U)] {} + given t3 [T, U] as Functor[[V] =>> (T, U, V)] {} - def derived[F[_]](given m: Mirror { type MirroredType = F ; type MirroredElemTypes[_] }, r: Functor[m.MirroredElemTypes]): Functor[F] = new Functor[F] {} + def derived[F[_]] with (m: Mirror { type MirroredType = F ; type MirroredElemTypes[_] }, r: Functor[m.MirroredElemTypes]) : Functor[F] = new Functor[F] {} } case class Mono(i: Int) derives Functor @@ -40,10 +40,10 @@ object Test extends App { { trait FunctorK[F[_[_]]] object FunctorK { - given [C] : FunctorK[[F[_]] =>> C] {} - given [T] : FunctorK[[F[_]] =>> Tuple1[F[T]]] + given [C] as FunctorK[[F[_]] =>> C] {} + given [T] as FunctorK[[F[_]] =>> Tuple1[F[T]]] - def derived[F[_[_]]](given m: Mirror { type MirroredType = F ; type MirroredElemTypes[_[_]] }, r: FunctorK[m.MirroredElemTypes]): FunctorK[F] = new FunctorK[F] {} + def derived[F[_[_]]] with (m: Mirror { type MirroredType = F ; type MirroredElemTypes[_[_]] }, r: FunctorK[m.MirroredElemTypes]) : FunctorK[F] = new FunctorK[F] {} } case class Mono(i: Int) derives FunctorK @@ -56,12 +56,12 @@ object Test extends App { { trait Bifunctor[F[_, _]] object Bifunctor { - given [C] : Bifunctor[[T, U] =>> C] {} + given [C] as Bifunctor[[T, U] =>> C] {} given Bifunctor[[T, U] =>> Tuple1[U]] {} - given t2 : Bifunctor[[T, U] =>> (T, U)] {} - given t3 [T] : Bifunctor[[U, V] =>> (T, U, V)] {} + given t2 as Bifunctor[[T, U] =>> (T, U)] {} + given t3 [T] as Bifunctor[[U, V] =>> (T, U, V)] {} - def derived[F[_, _]](given m: Mirror { type MirroredType = F ; type MirroredElemTypes[_, _] }, r: Bifunctor[m.MirroredElemTypes]): Bifunctor[F] = ??? + def derived[F[_, _]] with (m: Mirror { type MirroredType = F ; type MirroredElemTypes[_, _] }, r: Bifunctor[m.MirroredElemTypes]) : Bifunctor[F] = ??? } case class Mono(i: Int) derives Bifunctor diff --git a/tests/neg/quote-0.scala b/tests/neg/quote-0.scala index f82e8cb39771..e56ccf55d45c 100644 --- a/tests/neg/quote-0.scala +++ b/tests/neg/quote-0.scala @@ -1,6 +1,6 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { val x: Int = 0 diff --git a/tests/neg/quote-1.scala b/tests/neg/quote-1.scala index 71749010e37e..03738df74854 100644 --- a/tests/neg/quote-1.scala +++ b/tests/neg/quote-1.scala @@ -2,7 +2,7 @@ import scala.quoted._ class Test { - def f[T](t: Type[T], x: Expr[T])(given QuoteContext) = '{ + def f[T](t: Type[T], x: Expr[T]) with QuoteContext = '{ val z2 = $x // error // error: wrong staging level } diff --git a/tests/neg/quote-macro-2-splices.scala b/tests/neg/quote-macro-2-splices.scala index e419ab09438e..e137c3f9fe97 100644 --- a/tests/neg/quote-macro-2-splices.scala +++ b/tests/neg/quote-macro-2-splices.scala @@ -7,5 +7,5 @@ object Macro { else ${ bar(false) } } - def bar(b: Boolean)(given QuoteContext): Expr[Int] = if (b) '{1} else '{0} + def bar(b: Boolean) with QuoteContext : Expr[Int] = if (b) '{1} else '{0} } diff --git a/tests/neg/quote-spliceNonStaged.scala b/tests/neg/quote-spliceNonStaged.scala index ecb0d062187f..f6d0bd6f1049 100644 --- a/tests/neg/quote-spliceNonStaged.scala +++ b/tests/neg/quote-spliceNonStaged.scala @@ -2,6 +2,6 @@ package quotes import scala.quoted._ object Quotes_1 { - def printHello(given QuoteContext): Expr[Unit] = '{ println("Hello") } + def printHello with QuoteContext : Expr[Unit] = '{ println("Hello") } $printHello // error } diff --git a/tests/neg/quotedPatterns-1.scala b/tests/neg/quotedPatterns-1.scala index c3e9a5aca375..ae5a7a690597 100644 --- a/tests/neg/quotedPatterns-1.scala +++ b/tests/neg/quotedPatterns-1.scala @@ -1,5 +1,5 @@ object Test { - def test(x: quoted.Expr[Int])(given scala.quoted.QuoteContext) = x match { + def test(x: quoted.Expr[Int]) with scala.quoted.QuoteContext = x match { case '{ val a = '{ println($y) }; 0 } => ??? // error: Not found: y case _ => } diff --git a/tests/neg/quotedPatterns-2.scala b/tests/neg/quotedPatterns-2.scala index 2c5e2968fade..01ce35cf8925 100644 --- a/tests/neg/quotedPatterns-2.scala +++ b/tests/neg/quotedPatterns-2.scala @@ -1,5 +1,5 @@ object Test { - def test(x: quoted.Expr[Int])(given scala.quoted.QuoteContext) = x match { + def test(x: quoted.Expr[Int]) with scala.quoted.QuoteContext = x match { case '{ val a = 4; '{ a }; $y } => y // error // error: access to value a from wrong staging level case _ => } diff --git a/tests/neg/quotedPatterns-3.scala b/tests/neg/quotedPatterns-3.scala index cb52e56dae48..7968fa576842 100644 --- a/tests/neg/quotedPatterns-3.scala +++ b/tests/neg/quotedPatterns-3.scala @@ -1,5 +1,5 @@ object Test { - def test(x: quoted.Expr[Int])(given scala.quoted.QuoteContext) = x match { + def test(x: quoted.Expr[Int]) with scala.quoted.QuoteContext = x match { case '{ val `$y`: Int = 2; 1 } => y // error: Not found: y case '{ ((`$y`: Int) => 3); 2 } => diff --git a/tests/neg/quotedPatterns-4.scala b/tests/neg/quotedPatterns-4.scala index 72275a3db92d..2bc5f4273560 100644 --- a/tests/neg/quotedPatterns-4.scala +++ b/tests/neg/quotedPatterns-4.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Test { - def impl(receiver: Expr[StringContext])(given qctx: scala.quoted.QuoteContext) = { + def impl(receiver: Expr[StringContext]) with (qctx: scala.quoted.QuoteContext) = { import qctx.tasty.Repeated receiver match { case '{ StringContext(${Repeated(parts)}: _*) } => // error diff --git a/tests/neg/quotedPatterns-5.scala b/tests/neg/quotedPatterns-5.scala index d813edb1639c..9c03ef5040c9 100644 --- a/tests/neg/quotedPatterns-5.scala +++ b/tests/neg/quotedPatterns-5.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Test { - def test(x: quoted.Expr[Int])(given QuoteContext) = x match { + def test(x: quoted.Expr[Int]) with QuoteContext = x match { case '{ type $t; poly[$t]($x); 4 } => ??? // error: duplicate pattern variable: $t case '{ type `$t`; poly[`$t`]($x); 4 } => val tt: quoted.Type[_] = t // error diff --git a/tests/neg/quotedPatterns-6.scala b/tests/neg/quotedPatterns-6.scala index 97029854fd72..87344a707223 100644 --- a/tests/neg/quotedPatterns-6.scala +++ b/tests/neg/quotedPatterns-6.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Test { - def test(x: quoted.Expr[Int])(given QuoteContext) = x match { + def test(x: quoted.Expr[Int]) with QuoteContext = x match { case '{ poly[${Foo(t)}]($x); 4 } => ??? // error case '{ type $t; poly[${Foo(y: quoted.Type[`$t`])}]($x); 4 } => ??? // error case _ => diff --git a/tests/neg/splice-non-expr.scala b/tests/neg/splice-non-expr.scala index de832af998a6..97ac5929418c 100644 --- a/tests/neg/splice-non-expr.scala +++ b/tests/neg/splice-non-expr.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - def test(given QuoteContext) = '{ + def test with QuoteContext = '{ ${3} // error ${new Object} // error ${"abc"} // error diff --git a/tests/neg/toexproftuple.scala b/tests/neg/toexproftuple.scala index bf7910e40cd3..0406fbb85541 100644 --- a/tests/neg/toexproftuple.scala +++ b/tests/neg/toexproftuple.scala @@ -1,8 +1,8 @@ import scala.quoted._, scala.deriving._ -import scala.quoted.given +import scala.quoted.{given _} inline def mcr: Any = ${mcrImpl} -def mcrImpl(given ctx: QuoteContext): Expr[Any] = { +def mcrImpl with (ctx: QuoteContext) : Expr[Any] = { val tpl: (Expr[1], Expr[2], Expr[3]) = ('{1}, '{2}, '{3}) '{val res: (1, 3, 3) = ${Expr.ofTuple(tpl)}; res} // error diff --git a/tests/neg/tupled-function-instances.scala b/tests/neg/tupled-function-instances.scala index 963f24dcacec..da99fd5fb651 100644 --- a/tests/neg/tupled-function-instances.scala +++ b/tests/neg/tupled-function-instances.scala @@ -16,8 +16,8 @@ object Test { summon[TupledFunction[(T, T, T) => R, () => R]] // error summon[TupledFunction[(T, T, T) => R, (T, T) => R]] // error - summon[TupledFunction[(T, T, T) => R, (given (T, T, T)) =>R]] // error - summon[TupledFunction[(given T, T, T) => R, ((T, T, T)) =>R]] // error + summon[TupledFunction[(T, T, T) => R, ((T, T, T)) ?=> R]] // error + summon[TupledFunction[(T, T, T) => R, ((T, T, T)) ?=> R]] // error } } \ No newline at end of file diff --git a/tests/patmat/i6255.scala b/tests/patmat/i6255.scala index df4e31e8276b..dafbb8fb47b6 100644 --- a/tests/patmat/i6255.scala +++ b/tests/patmat/i6255.scala @@ -1,5 +1,5 @@ class Foo { - def foo(x: quoted.Expr[Int])(given scala.quoted.QuoteContext): Unit = x match { + def foo(x: quoted.Expr[Int]) with scala.quoted.QuoteContext : Unit = x match { case '{ 1 } => case '{ 2 } => case _ => diff --git a/tests/patmat/i6255b.scala b/tests/patmat/i6255b.scala index b9982c8024f0..ffdc38629b94 100644 --- a/tests/patmat/i6255b.scala +++ b/tests/patmat/i6255b.scala @@ -1,5 +1,5 @@ class Foo { - def foo(x: quoted.Expr[Int])(given scala.quoted.QuoteContext): Unit = x match { + def foo(x: quoted.Expr[Int]) with scala.quoted.QuoteContext : Unit = x match { case '{ 1 } => case '{ 2 } => } diff --git a/tests/pending/pos/i4987.scala b/tests/pending/pos/i4987.scala index 26eda253d3f4..5744f580856c 100644 --- a/tests/pending/pos/i4987.scala +++ b/tests/pending/pos/i4987.scala @@ -12,6 +12,6 @@ object Foo { implicit def NilIsLiftable: Liftable[Nil.type] = ??? - Expr(Nil)(given NilIsLiftable) + Expr(Nil) with NilIsLiftable Expr(Nil) } \ No newline at end of file diff --git a/tests/pending/pos/i7778.scala b/tests/pending/pos/i7778.scala index 70d58d938d2b..0bbc8278353c 100644 --- a/tests/pending/pos/i7778.scala +++ b/tests/pending/pos/i7778.scala @@ -1,5 +1,5 @@ object Example extends App { - final case class Foo[A](run: (given A) => Int) + final case class Foo[A](run: A ?=> Int) } \ No newline at end of file diff --git a/tests/pending/run/tasty-comments/quoted_1.scala b/tests/pending/run/tasty-comments/quoted_1.scala index f593b7b5ed19..7a2f00971d95 100644 --- a/tests/pending/run/tasty-comments/quoted_1.scala +++ b/tests/pending/run/tasty-comments/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { @@ -7,8 +7,8 @@ object Macros { inline def printComment[T](t: => T): Unit = ${ impl('t) } - def impl[T](x: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = x.unseal tree.symbol.comment.map(_.raw) match { diff --git a/tests/pos-custom-args/erased/i7868.scala b/tests/pos-custom-args/erased/i7868.scala index 5b0835dc4488..19ff8376fc3a 100644 --- a/tests/pos-custom-args/erased/i7868.scala +++ b/tests/pos-custom-args/erased/i7868.scala @@ -15,17 +15,17 @@ object Coproduct { def cast: Head <:< Head +: Tail = summon[Head <:< Head +: Tail] } - given atTail[Head, Tail, Value, NextIndex <: Int](given atNext: At[Tail, Value, NextIndex]): At[Head +: Tail, Value, S[NextIndex]] { + given atTail[Head, Tail, Value, NextIndex <: Int] with (atNext: At[Tail, Value, NextIndex]) : At[Head +: Tail, Value, S[NextIndex]] { val cast: Value <:< Head +: Tail = atNext.cast } - given [A](given A): (() => A)= { () => summon[A]} + given [A] with A as (() => A)= { () => summon[A]} } - def upCast[A, B](a: A)(given erased evidence: (A <:< B)): B = a.asInstanceOf[B] + def upCast[A, B](a: A) with (erased evidence: (A <:< B) ): B = a.asInstanceOf[B] - def from[Set, Value, Index <: Int](value: Value)(given erased at: At[Set, Value, Index]): (given ValueOf[Index]) => Coproduct[Set, Value, Index] = { - Coproduct[Set, Value, Index](upCast(value: Value)(given at.cast.liftCo[[+X] =>> Value & X]), valueOf[Index]) + def from[Set, Value, Index <: Int](value: Value) with (erased at: At[Set, Value, Index]) : ValueOf[Index] ?=> Coproduct[Set, Value, Index] = { + Coproduct[Set, Value, Index](upCast(value: Value).with(at.cast.liftCo[[+X] =>> Value & X]), valueOf[Index]) } } diff --git a/tests/pos-custom-args/erased/i7878.scala b/tests/pos-custom-args/erased/i7878.scala index d47bb32f1a65..bed16fce4036 100644 --- a/tests/pos-custom-args/erased/i7878.scala +++ b/tests/pos-custom-args/erased/i7878.scala @@ -9,7 +9,7 @@ object Boom { } val a: Int = 1 - given ev1: Fail[a.type, 2] = null + given ev1 as Fail[a.type, 2] = null summon[Fail[a.type, 3]] } \ No newline at end of file diff --git a/tests/pos-custom-args/i4125.scala b/tests/pos-custom-args/i4125.scala index 99453713053d..70d03fbf3d77 100644 --- a/tests/pos-custom-args/i4125.scala +++ b/tests/pos-custom-args/i4125.scala @@ -1,4 +1,4 @@ object Test { def foo: ((erased x: Int, y: Int) => Int) = (erased x, y) => 1 - def bar: ((given erased x: Int, y: Int) => Int) = (given erased x, y) => 1 + def bar: ((erased x: Int, y: Int) ?=> Int) = (erased x, y) ?=> 1 } diff --git a/tests/pos-custom-args/i4509.scala b/tests/pos-custom-args/i4509.scala index f71d5b698a9a..afb15a5486bb 100644 --- a/tests/pos-custom-args/i4509.scala +++ b/tests/pos-custom-args/i4509.scala @@ -1,4 +1,4 @@ object Main { - def fun[T](op: (given erased Int) => T) = op(given 0) + def fun[T](op: (erased Int) ?=> T) = op.with(0) fun { } } diff --git a/tests/pos-custom-args/i6009c.scala b/tests/pos-custom-args/i6009c.scala index e591d0f9b0e5..02f2ced70cec 100644 --- a/tests/pos-custom-args/i6009c.scala +++ b/tests/pos-custom-args/i6009c.scala @@ -1,5 +1,5 @@ class Foo { - def foo(f: (given erased Int) => Int): Int = { + def foo(f: (erased Int) ?=> Int): Int = { implicit erased val ctx = 1 f } diff --git a/tests/pos-custom-args/phantom-Eq.scala b/tests/pos-custom-args/phantom-Eq.scala index 2ec38fd73800..9547720d9ca5 100644 --- a/tests/pos-custom-args/phantom-Eq.scala +++ b/tests/pos-custom-args/phantom-Eq.scala @@ -18,7 +18,7 @@ object EqUtil { type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U) (given erased ce: PhantomEq[T, U]) = x.equals(y) + def ===[U] (y: U) with (erased ce: PhantomEq[T, U]) = x.equals(y) } implicit erased def eqString: PhantomEqEq[String] = ??? @@ -28,5 +28,5 @@ object EqUtil { implicit erased def eqByteNum: PhantomEq[Byte, Number] = ??? implicit erased def eqNumByte: PhantomEq[Number, Byte] = ??? - implicit erased def eqSeq[T, U] (given erased eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = ??? + implicit erased def eqSeq[T, U] with (erased eq: PhantomEq[T, U]) : PhantomEq[Seq[T], Seq[U]] = ??? } diff --git a/tests/pos-custom-args/phantom-Eq2/Phantom-Eq_1.scala b/tests/pos-custom-args/phantom-Eq2/Phantom-Eq_1.scala index 49d779a4b459..afabcaeb7d40 100644 --- a/tests/pos-custom-args/phantom-Eq2/Phantom-Eq_1.scala +++ b/tests/pos-custom-args/phantom-Eq2/Phantom-Eq_1.scala @@ -6,7 +6,7 @@ object EqUtil { type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U) (given erased ce: PhantomEq[T, U]) = x.equals(y) + def ===[U] (y: U) with (erased ce: PhantomEq[T, U]) = x.equals(y) } implicit erased def eqString: PhantomEqEq[String] = new PhantomEq[String, String] @@ -16,6 +16,6 @@ object EqUtil { implicit erased def eqByteNum: PhantomEq[Byte, Number] = new PhantomEq[Byte, Number] implicit erased def eqNumByte: PhantomEq[Number, Byte] = new PhantomEq[Number, Byte] - implicit erased def eqSeq[T, U] (given erased eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = + implicit erased def eqSeq[T, U] with (erased eq: PhantomEq[T, U]) : PhantomEq[Seq[T], Seq[U]] = new PhantomEq[Seq[T], Seq[U]] } diff --git a/tests/pos-custom-args/phantom-Evidence.scala b/tests/pos-custom-args/phantom-Evidence.scala index e7b8cd11536e..db0bac9fe295 100644 --- a/tests/pos-custom-args/phantom-Evidence.scala +++ b/tests/pos-custom-args/phantom-Evidence.scala @@ -10,8 +10,8 @@ object WithNormalState { def newInstance(): Instance[Off] = new Instance[Off] } class Instance[S <: State] private { - def getOnInstance (given erased ev: S =::= Off): Instance[On] = new Instance[On] // phantom parameter ev is erased - def getOffInstance (given erased ev: S =::= On): Instance[Off] = new Instance[Off] // phantom parameter ev is erased + def getOnInstance with (erased ev: S =::= Off) : Instance[On] = new Instance[On] // phantom parameter ev is erased + def getOffInstance with (erased ev: S =::= On) : Instance[Off] = new Instance[Off] // phantom parameter ev is erased } def run() = { diff --git a/tests/pos-macros/i3898/quoted_1.scala b/tests/pos-macros/i3898/quoted_1.scala index 5be61fa2be8e..6e68a77b8aeb 100644 --- a/tests/pos-macros/i3898/quoted_1.scala +++ b/tests/pos-macros/i3898/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff(args: Any*): String = ${impl('args)} - def impl(args: Expr[Seq[Any]])(given QuoteContext): Expr[String] = '{""} + def impl(args: Expr[Seq[Any]]) with QuoteContext : Expr[String] = '{""} } diff --git a/tests/pos-macros/i3898b/quoted_1.scala b/tests/pos-macros/i3898b/quoted_1.scala index 65daf3640719..41a41e99782a 100644 --- a/tests/pos-macros/i3898b/quoted_1.scala +++ b/tests/pos-macros/i3898b/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff(x: Int, inline y: Int): String = ${impl('x)} - def impl(x: Expr[Int])(given QuoteContext): Expr[String] = '{""} + def impl(x: Expr[Int]) with QuoteContext : Expr[String] = '{""} } diff --git a/tests/pos-macros/i3898c/quoted_1.scala b/tests/pos-macros/i3898c/quoted_1.scala index 65daf3640719..41a41e99782a 100644 --- a/tests/pos-macros/i3898c/quoted_1.scala +++ b/tests/pos-macros/i3898c/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff(x: Int, inline y: Int): String = ${impl('x)} - def impl(x: Expr[Int])(given QuoteContext): Expr[String] = '{""} + def impl(x: Expr[Int]) with QuoteContext : Expr[String] = '{""} } diff --git a/tests/pos-macros/i3898c/quoted_2.scala b/tests/pos-macros/i3898c/quoted_2.scala index 4bda610c887e..1b1947f65e16 100644 --- a/tests/pos-macros/i3898c/quoted_2.scala +++ b/tests/pos-macros/i3898c/quoted_2.scala @@ -1,5 +1,5 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { val a = '{ def z: Int = 5 Macro.ff(z, 5) diff --git a/tests/pos-macros/i3912-1/i3912_1.scala b/tests/pos-macros/i3912-1/i3912_1.scala index 3a2564666960..7bed91812477 100644 --- a/tests/pos-macros/i3912-1/i3912_1.scala +++ b/tests/pos-macros/i3912-1/i3912_1.scala @@ -3,5 +3,5 @@ import scala.quoted._ object Macros { inline def foo(): Int = { ${ impl() } } - def impl()(given QuoteContext): Expr[Int] = '{1} + def impl() with QuoteContext : Expr[Int] = '{1} } \ No newline at end of file diff --git a/tests/pos-macros/i3912-2/i3912_1.scala b/tests/pos-macros/i3912-2/i3912_1.scala index 2bdab7c6eee8..bc44f30dec6a 100644 --- a/tests/pos-macros/i3912-2/i3912_1.scala +++ b/tests/pos-macros/i3912-2/i3912_1.scala @@ -3,5 +3,5 @@ import scala.quoted._ object Macros { inline def foo2(): Unit = ${ impl() } - def impl()(given QuoteContext): Expr[Int] = '{1} + def impl() with QuoteContext : Expr[Int] = '{1} } \ No newline at end of file diff --git a/tests/pos-macros/i4023b/Macro_1.scala b/tests/pos-macros/i4023b/Macro_1.scala index 195896cc8d8f..9ebbeae837c8 100644 --- a/tests/pos-macros/i4023b/Macro_1.scala +++ b/tests/pos-macros/i4023b/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff[T](implicit t: Type[T]): Int = ${ impl[T] } - def impl[T](given QuoteContext): Expr[Int] = '{4} + def impl[T] with QuoteContext : Expr[Int] = '{4} } diff --git a/tests/pos-macros/i4734/Macro_1.scala b/tests/pos-macros/i4734/Macro_1.scala index e575f0e6b48a..26f2d67322c2 100644 --- a/tests/pos-macros/i4734/Macro_1.scala +++ b/tests/pos-macros/i4734/Macro_1.scala @@ -5,7 +5,7 @@ object Macros { inline def unrolledForeach(f: Int => Int): Int = ${unrolledForeachImpl('f)} - def unrolledForeachImpl(f: Expr[Int => Int])(given QuoteContext): Expr[Int] = '{ + def unrolledForeachImpl(f: Expr[Int => Int]) with QuoteContext : Expr[Int] = '{ val size: Int = 5 ($f)(3) } diff --git a/tests/pos-macros/i6171/Macro_1.scala b/tests/pos-macros/i6171/Macro_1.scala index 01826821a80f..95968d1d619f 100644 --- a/tests/pos-macros/i6171/Macro_1.scala +++ b/tests/pos-macros/i6171/Macro_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(x: => Any): Unit = ${ assertImpl('x) } - def assertImpl(x: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(x: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} x.unseal.underlyingArgument '{ () } } diff --git a/tests/pos-macros/i6210/Macros_1.scala b/tests/pos-macros/i6210/Macros_1.scala index 3ae8e0a11344..571c13bd1a14 100644 --- a/tests/pos-macros/i6210/Macros_1.scala +++ b/tests/pos-macros/i6210/Macros_1.scala @@ -4,7 +4,7 @@ object Macro { inline def test[A, B]: Any = ${ impl[A, B] } - def impl[A : Type, B : Type](given QuoteContext): Expr[Any] = { + def impl[A : Type, B : Type] with QuoteContext : Expr[Any] = { val t = '[Map[A, B]] '{ new Object().asInstanceOf[$t] diff --git a/tests/pos-macros/i6535/Macro_1.scala b/tests/pos-macros/i6535/Macro_1.scala index 619197c61c9b..e12b3040c095 100644 --- a/tests/pos-macros/i6535/Macro_1.scala +++ b/tests/pos-macros/i6535/Macro_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition) } - def assertImpl(cond: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ cond.unseal.underlyingArgument match { diff --git a/tests/pos-macros/i6803b/Macro_1.scala b/tests/pos-macros/i6803b/Macro_1.scala index 99dd47c0513c..e3f207e3f5c6 100644 --- a/tests/pos-macros/i6803b/Macro_1.scala +++ b/tests/pos-macros/i6803b/Macro_1.scala @@ -2,15 +2,15 @@ package blah import scala.language.implicitConversions import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object AsObject { final class LineNo(val lineNo: Int) object LineNo { def unsafe(i: Int): LineNo = new LineNo(i) inline given x : LineNo = ${impl} - private def impl(given qctx: QuoteContext): Expr[LineNo] = { - import qctx.tasty.{_, given} + private def impl with (qctx: QuoteContext) : Expr[LineNo] = { + import qctx.tasty.{_, given _} '{unsafe(${rootPosition.startLine})} } } diff --git a/tests/pos-macros/i6803b/Test_2.scala b/tests/pos-macros/i6803b/Test_2.scala index b97c35c46c42..cb22fb35a077 100644 --- a/tests/pos-macros/i6803b/Test_2.scala +++ b/tests/pos-macros/i6803b/Test_2.scala @@ -5,7 +5,7 @@ object Test { def testO(): Unit = { import AsObject.LineNo - summon[LineNo](given LineNo.x) + summon[LineNo].with(LineNo.x) } } } diff --git a/tests/pos-macros/i7011/Macros_1.scala b/tests/pos-macros/i7011/Macros_1.scala index 2bdd8661da65..a70e8d1ef3ae 100644 --- a/tests/pos-macros/i7011/Macros_1.scala +++ b/tests/pos-macros/i7011/Macros_1.scala @@ -1,10 +1,10 @@ import scala.quoted._, scala.quoted.matching._ -import scala.quoted.given +import scala.quoted.{given _} inline def mcr(body: => Any): Unit = ${mcrImpl('body)} -def mcrImpl[T](body: Expr[Any])(given ctx: QuoteContext): Expr[Any] = { - import ctx.tasty.{_, given} +def mcrImpl[T](body: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = { + import ctx.tasty.{_, given _} val bTree = body.unseal val under = bTree.underlyingArgument diff --git a/tests/pos-macros/i7513/Macro_1.scala b/tests/pos-macros/i7513/Macro_1.scala index 05193fbc7fc6..6ebab19b09df 100644 --- a/tests/pos-macros/i7513/Macro_1.scala +++ b/tests/pos-macros/i7513/Macro_1.scala @@ -5,7 +5,7 @@ trait Quoted { } inline def quote: Quoted = ${ quoteImpl } -def quoteImpl(given qctx: QuoteContext): Expr[Quoted] = '{ +def quoteImpl with (qctx: QuoteContext) : Expr[Quoted] = '{ new Quoted { def foo = ??? } diff --git a/tests/pos-macros/i7513b/Macro_1.scala b/tests/pos-macros/i7513b/Macro_1.scala index ba1f60dfbf93..85faf7748496 100644 --- a/tests/pos-macros/i7513b/Macro_1.scala +++ b/tests/pos-macros/i7513b/Macro_1.scala @@ -5,7 +5,7 @@ trait Quoted { } inline def quote: Quoted = ${ quoteImpl } -def quoteImpl(given qctx: QuoteContext): Expr[Quoted] = '{ +def quoteImpl with (qctx: QuoteContext) : Expr[Quoted] = '{ new Quoted { val foo = ??? } diff --git a/tests/pos-macros/i7513c/Macro_1.scala b/tests/pos-macros/i7513c/Macro_1.scala index 671918f348f5..486a5624ba3c 100644 --- a/tests/pos-macros/i7513c/Macro_1.scala +++ b/tests/pos-macros/i7513c/Macro_1.scala @@ -6,7 +6,7 @@ object Macros { } inline def quote: Quoted = ${ quoteImpl } - def quoteImpl(given qctx: QuoteContext): Expr[Quoted] = '{ + def quoteImpl with (qctx: QuoteContext) : Expr[Quoted] = '{ new Quoted { def foo = ??? } diff --git a/tests/pos-macros/i7853/JsonEncoder_1.scala b/tests/pos-macros/i7853/JsonEncoder_1.scala index 414a6ff72678..48c18a7a938c 100644 --- a/tests/pos-macros/i7853/JsonEncoder_1.scala +++ b/tests/pos-macros/i7853/JsonEncoder_1.scala @@ -36,15 +36,15 @@ object JsonEncoder { } } - given listEncoder[T]: (encoder: JsonEncoder[T]) => JsonEncoder[List[T]] { + given listEncoder[T] with (encoder: JsonEncoder[T]) as JsonEncoder[List[T]] { def encode(list: List[T]) = s"[${ list.map(v => encoder.encode(v)).mkString(", ") }]" } - given intEncoder: JsonEncoder[Int] { + given intEncoder as JsonEncoder[Int] { def encode(value: Int) = value + "" } - given stringEncoder: JsonEncoder[String] { + given stringEncoder as JsonEncoder[String] { def encode(value: String) = value } } \ No newline at end of file diff --git a/tests/pos-macros/i7853/SummonJsonEncoderTest_2.scala b/tests/pos-macros/i7853/SummonJsonEncoderTest_2.scala index 1c4930b3d32f..d991df71e263 100644 --- a/tests/pos-macros/i7853/SummonJsonEncoderTest_2.scala +++ b/tests/pos-macros/i7853/SummonJsonEncoderTest_2.scala @@ -2,13 +2,13 @@ import scala.deriving._ import scala.quoted._ import scala.quoted.matching._ import scala.compiletime.{erasedValue, summonFrom} -import JsonEncoder.{given, _} +import JsonEncoder.{given _, _} object SummonJsonEncoderTest { inline def encodeAndMessAroundType[T](value: =>T): String = ${ encodeAndMessAroundTypeImpl('value) } - def encodeAndMessAroundTypeImpl[T: Type](value: Expr[T])(given qctx: QuoteContext): Expr[String] = { + def encodeAndMessAroundTypeImpl[T: Type](value: Expr[T]) with (qctx: QuoteContext) : Expr[String] = { import qctx.tasty._ val mirrorExpr = summonExpr[Mirror.Of[T]] match { diff --git a/tests/pos-macros/macro-with-type/Macro_1.scala b/tests/pos-macros/macro-with-type/Macro_1.scala index 6d2e3c1380a2..b82ade598d5d 100644 --- a/tests/pos-macros/macro-with-type/Macro_1.scala +++ b/tests/pos-macros/macro-with-type/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff: Unit = ${impl('[Int])} - def impl(t: Type[Int])(given QuoteContext): Expr[Unit] = '{} + def impl(t: Type[Int]) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/pos-macros/macros-in-same-project-1/Foo.scala b/tests/pos-macros/macros-in-same-project-1/Foo.scala index ed7995160718..686d234276da 100644 --- a/tests/pos-macros/macros-in-same-project-1/Foo.scala +++ b/tests/pos-macros/macros-in-same-project-1/Foo.scala @@ -4,6 +4,6 @@ object Foo { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = '{ println("Hello") } + def aMacroImplementation with QuoteContext : Expr[Unit] = '{ println("Hello") } } diff --git a/tests/pos-macros/macros-in-same-project-2/Foo.scala b/tests/pos-macros/macros-in-same-project-2/Foo.scala index 63af6389a5c0..80c4a210c03c 100644 --- a/tests/pos-macros/macros-in-same-project-2/Foo.scala +++ b/tests/pos-macros/macros-in-same-project-2/Foo.scala @@ -2,6 +2,6 @@ import scala.quoted._ object Foo { - def aMacroImplementation(given QuoteContext): Expr[Unit] = '{ println("Hello") } + def aMacroImplementation with QuoteContext : Expr[Unit] = '{ println("Hello") } } diff --git a/tests/pos-macros/macros-in-same-project-3/Bar.scala b/tests/pos-macros/macros-in-same-project-3/Bar.scala index e2f42449fc97..cbbd514eed83 100644 --- a/tests/pos-macros/macros-in-same-project-3/Bar.scala +++ b/tests/pos-macros/macros-in-same-project-3/Bar.scala @@ -4,6 +4,6 @@ object Bar { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = Foo.hello() + def aMacroImplementation with QuoteContext : Expr[Unit] = Foo.hello() } diff --git a/tests/pos-macros/macros-in-same-project-3/Foo.scala b/tests/pos-macros/macros-in-same-project-3/Foo.scala index 55e4cb27983b..3557f5bdb2c1 100644 --- a/tests/pos-macros/macros-in-same-project-3/Foo.scala +++ b/tests/pos-macros/macros-in-same-project-3/Foo.scala @@ -2,6 +2,6 @@ import scala.quoted._ object Foo { - def hello()(given QuoteContext): Expr[Unit] = '{ println("Hello") } + def hello() with QuoteContext : Expr[Unit] = '{ println("Hello") } } diff --git a/tests/pos-macros/macros-in-same-project-4/Bar.scala b/tests/pos-macros/macros-in-same-project-4/Bar.scala index 31bd6c04b392..2dfed7cc1ce8 100644 --- a/tests/pos-macros/macros-in-same-project-4/Bar.scala +++ b/tests/pos-macros/macros-in-same-project-4/Bar.scala @@ -3,9 +3,9 @@ import scala.quoted._ object Bar { inline def eqMacro(x: Foo, y: Foo): Boolean = ${ eqMacroExpr('x, 'y) } - def eqMacroExpr(x: Expr[Foo], y: Expr[Foo])(given QuoteContext): Expr[Boolean] = '{ $x == $y } + def eqMacroExpr(x: Expr[Foo], y: Expr[Foo]) with QuoteContext : Expr[Boolean] = '{ $x == $y } inline def plusMacro(x: Foo, y: Foo): Foo = ${ eqPlusExpr('x, 'y) } - def eqPlusExpr(x: Expr[Foo], y: Expr[Foo])(given QuoteContext): Expr[Foo] = '{ new Foo($x.value + $y.value) } + def eqPlusExpr(x: Expr[Foo], y: Expr[Foo]) with QuoteContext : Expr[Foo] = '{ new Foo($x.value + $y.value) } } diff --git a/tests/pos-macros/power-macro/Macro_1.scala b/tests/pos-macros/power-macro/Macro_1.scala index b05e2dfd4ce7..25c38cdf0656 100644 --- a/tests/pos-macros/power-macro/Macro_1.scala +++ b/tests/pos-macros/power-macro/Macro_1.scala @@ -5,7 +5,7 @@ object PowerMacro { inline def power(inline n: Long, x: Double) = ${powerCode(n, 'x)} - def powerCode(n: Long, x: Expr[Double])(given QuoteContext): Expr[Double] = + def powerCode(n: Long, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } else '{ $x * ${powerCode(n - 1, x)} } diff --git a/tests/pos-macros/quote-nested-object/Macro_1.scala b/tests/pos-macros/quote-nested-object/Macro_1.scala index 44cf14461620..cdd00bc23b0f 100644 --- a/tests/pos-macros/quote-nested-object/Macro_1.scala +++ b/tests/pos-macros/quote-nested-object/Macro_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macro { @@ -9,7 +9,7 @@ object Macro { inline def plus(inline n: Int, m: Int): Int = ${ plus(n, 'm) } - def plus(n: Int, m: Expr[Int])(given QuoteContext): Expr[Int] = + def plus(n: Int, m: Expr[Int]) with QuoteContext : Expr[Int] = if (n == 0) m else '{ ${n} + $m } @@ -17,7 +17,7 @@ object Macro { inline def plus(inline n: Int, m: Int): Int = ${ plus(n, 'm) } - def plus(n: Int, m: Expr[Int])(given QuoteContext): Expr[Int] = + def plus(n: Int, m: Expr[Int]) with QuoteContext : Expr[Int] = if (n == 0) m else '{ ${n} + $m } } diff --git a/tests/pos-macros/quote-whitebox-2/Macro_1.scala b/tests/pos-macros/quote-whitebox-2/Macro_1.scala index a09a3c37707f..e60dadfbddd3 100644 --- a/tests/pos-macros/quote-whitebox-2/Macro_1.scala +++ b/tests/pos-macros/quote-whitebox-2/Macro_1.scala @@ -5,6 +5,6 @@ object Macro { inline def charOrString(inline str: String) <: Any = ${ impl(str) } - def impl(str: String)(given QuoteContext) = if (str.length == 1) Expr(str.charAt(0)) else Expr(str) + def impl(str: String) with QuoteContext = if (str.length == 1) Expr(str.charAt(0)) else Expr(str) } diff --git a/tests/pos-macros/tasty-constant-type/Macro_1.scala b/tests/pos-macros/tasty-constant-type/Macro_1.scala index 8ffb982667c9..252c4e363dcf 100644 --- a/tests/pos-macros/tasty-constant-type/Macro_1.scala +++ b/tests/pos-macros/tasty-constant-type/Macro_1.scala @@ -6,8 +6,8 @@ object Macro { inline def ff[A <: Int, B <: Int]() <: AddInt[A, B] = ${ impl('[A], '[B]) } - def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B])(given qctx: QuoteContext): Expr[AddInt[A, B]] = { - import qctx.tasty.{_, given} + def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B]) with (qctx: QuoteContext) : Expr[AddInt[A, B]] = { + import qctx.tasty.{_, given _} val ConstantType(Constant(v1: Int)) = a.unseal.tpe val ConstantType(Constant(v2: Int)) = b.unseal.tpe diff --git a/tests/pos-macros/treemap-unapply/Macro.scala b/tests/pos-macros/treemap-unapply/Macro.scala index 955a565740f2..661bb548197f 100644 --- a/tests/pos-macros/treemap-unapply/Macro.scala +++ b/tests/pos-macros/treemap-unapply/Macro.scala @@ -1,8 +1,8 @@ -import scala.quoted.{ given, _ } +import scala.quoted.{ given _, _ } inline def mcr(x: => Unit): Unit = ${mcrImpl('x)} -def mcrImpl(x: Expr[Unit])(given ctx: QuoteContext): Expr[Unit] = - import ctx.tasty.{ given, _ } +def mcrImpl(x: Expr[Unit]) with (ctx: QuoteContext) : Expr[Unit] = + import ctx.tasty.{ given _, _ } val tr: Term = x.unseal object m extends TreeMap m.transformTerm(tr).seal.cast[Unit] diff --git a/tests/pos-special/fatal-warnings/i6290.scala b/tests/pos-special/fatal-warnings/i6290.scala index f4f2e6d31fb4..d8b410224269 100644 --- a/tests/pos-special/fatal-warnings/i6290.scala +++ b/tests/pos-special/fatal-warnings/i6290.scala @@ -1,15 +1,15 @@ class TC { type T } -class C(given TC { type T = Int }) - -def f1(given x: TC) = ??? -def f2(given @unchecked x: TC) = ??? -inline def f3(given inline x: TC) = ??? - -class C1(given x: TC) -class C2(given @unchecked x: TC) -class C3(given val x: TC) -class C4(given var x: TC) -class C5(given private val x: TC) -class C6(given private[this] val x: TC) +class C with (TC { type T = Int }) + +def f1 with (x: TC) = ??? +def f2 with (@unchecked x: TC) = ??? +inline def f3 with (inline x: TC) = ??? + +class C1 with (x: TC) +class C2 with (@unchecked x: TC) +class C3 with (val x: TC) +class C4 with (var x: TC) +class C5 with (private val x: TC) +class C6 with (private[this] val x: TC) diff --git a/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala b/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala index 4ca6e836afa2..661612640c66 100644 --- a/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala +++ b/tests/pos-special/fatal-warnings/tasty-parent-unapply.scala @@ -6,7 +6,7 @@ object Macros { def impl(reflect: Reflection): Unit = { - import reflect.{_, given} + import reflect.{_, given _} def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: Tree) = { diff --git a/tests/pos-special/strawman-collections/CollectionStrawMan6.scala b/tests/pos-special/strawman-collections/CollectionStrawMan6.scala index 37fc529bb2be..e6d51f89a830 100644 --- a/tests/pos-special/strawman-collections/CollectionStrawMan6.scala +++ b/tests/pos-special/strawman-collections/CollectionStrawMan6.scala @@ -753,11 +753,11 @@ object CollectionStrawMan6 extends LowPriority { def elemTag: ClassTag[A] = ClassTag(xs.getClass.getComponentType) - protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A](elemTag) + protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A].with(elemTag) def fromIterable[B: ClassTag](coll: Iterable[B]): Array[B] = coll.toArray[B] - protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(elemTag)) + protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray.with(elemTag)) override def knownSize = xs.length diff --git a/tests/pos-staging/quote-0.scala b/tests/pos-staging/quote-0.scala index 462124bf2490..b1bc399b1971 100644 --- a/tests/pos-staging/quote-0.scala +++ b/tests/pos-staging/quote-0.scala @@ -1,6 +1,6 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { @@ -8,15 +8,15 @@ object Macros { inline def assert(expr: => Boolean): Unit = ${ assertImpl('expr) } - def assertImpl(expr: Expr[Boolean])(given QuoteContext) = + def assertImpl(expr: Expr[Boolean]) with QuoteContext = '{ if !($expr) then throw new AssertionError(s"failed assertion: ${${showExpr(expr)}}") } - def showExpr[T](expr: Expr[T])(given QuoteContext): Expr[String] = expr.toString + def showExpr[T](expr: Expr[T]) with QuoteContext : Expr[String] = expr.toString inline def power(inline n: Int, x: Double) = ${ powerCode(n, 'x) } - def powerCode(n: Int, x: Expr[Double])(given QuoteContext): Expr[Double] = + def powerCode(n: Int, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n % 2 == 0) '{ { val y = $x * $x; ${ powerCode(n / 2, 'y) } } } diff --git a/tests/pos-staging/quote-assert/quoted_1.scala b/tests/pos-staging/quote-assert/quoted_1.scala index 8332f9dc7415..2eb5269b15fc 100644 --- a/tests/pos-staging/quote-assert/quoted_1.scala +++ b/tests/pos-staging/quote-assert/quoted_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Macros { - def assertImpl(expr: Expr[Boolean])(given QuoteContext) = + def assertImpl(expr: Expr[Boolean]) with QuoteContext = '{ if !($expr) then throw new AssertionError(s"failed assertion: ${$expr}") } } diff --git a/tests/pos-staging/quote-assert/quoted_2.scala b/tests/pos-staging/quote-assert/quoted_2.scala index 28d3e93433e8..97dcd6976692 100644 --- a/tests/pos-staging/quote-assert/quoted_2.scala +++ b/tests/pos-staging/quote-assert/quoted_2.scala @@ -10,7 +10,7 @@ object Test { ${ assertImpl('expr) } - def program(given QuoteContext) = '{ + def program with QuoteContext = '{ val x = 1 assert(x != 0) diff --git a/tests/pos/Orderings.scala b/tests/pos/Orderings.scala index cab67f3daf67..315ce0167da6 100644 --- a/tests/pos/Orderings.scala +++ b/tests/pos/Orderings.scala @@ -15,6 +15,6 @@ object Orderings { else ev.less(xs.head, ys.head) } - def isLess[T]: T => T => (given Ord[T]) => Boolean = + def isLess[T]: T => T => Ord[T] ?=> Boolean = x => y => implicitly[Ord[T]].less(x, y) } diff --git a/tests/pos/case-getters.scala b/tests/pos/case-getters.scala index 3d4b38f161fa..b49806ce07ee 100644 --- a/tests/pos/case-getters.scala +++ b/tests/pos/case-getters.scala @@ -1,8 +1,8 @@ -case class Foo(x: 1, y: (given Int) => Int) +case class Foo(x: 1, y: Int ?=> Int) object Test { - val f = Foo(1, (given i: Int) =>i) + val f = Foo(1, (i: Int) ?=> i) val fx1: 1 = f.x val fx2: 1 = f._1 - val fy1: Int = f.y(given 1) - val fy2: Int = f._2(given 1) + val fy1: Int = f.y.with(1) + val fy2: Int = f._2.with(1) } diff --git a/tests/pos/combine.scala b/tests/pos/combine.scala index 7728b443c245..5a978b461d4c 100644 --- a/tests/pos/combine.scala +++ b/tests/pos/combine.scala @@ -2,7 +2,7 @@ trait Semigroup[A] { def (x: A).combine(y: A): A } given Semigroup[Int] = ??? -given [A, B]: Semigroup[A], Semigroup[B] => Semigroup[(A, B)] = ??? +given [A, B] with (Semigroup[A], Semigroup[B]) : Semigroup[(A, B)] = ??? object Test extends App { ((1, 1)) combine ((2, 2)) // doesn't compile ((1, 1): (Int, Int)) combine (2, 2) // compiles diff --git a/tests/pos/depfuntype.scala b/tests/pos/depfuntype.scala index 9e44286ca0dc..a8cbd454d08a 100644 --- a/tests/pos/depfuntype.scala +++ b/tests/pos/depfuntype.scala @@ -19,15 +19,15 @@ object Test { // Reproduced here because the one from DottyPredef is lacking a parameter dependency of the return type `ev.type` inline final def implicitly[T](implicit ev: T): ev.type = ev - type IDF = (given x: C) =>x.M + type IDF = (x: C) ?=> x.M implicit val ic: C = ??? val ifun: IDF = implicitly[C].m - val u = ifun(given c) + val u = ifun.with(c) val u1: Int = u - val v = ifun(given d) + val v = ifun.with(d) val v1: d.M = v } diff --git a/tests/pos/eff-compose.scala b/tests/pos/eff-compose.scala index 48fe6c7d159c..300c994e43da 100644 --- a/tests/pos/eff-compose.scala +++ b/tests/pos/eff-compose.scala @@ -5,7 +5,7 @@ object Test { // Type X => Y abstract class Fun[-X, Y] { type Eff <: Effect - def apply(x: X): (given Eff) => Y + def apply(x: X): Eff ?=> Y } // Type X -> Y @@ -13,7 +13,7 @@ object Test { // def map(f: A => B)(xs: List[A]): List[B] def map[A, B, E <: Effect](f: Fun[A, B] { type Eff = E})(xs: List[A]) - : (given E) => List[B] = + : E ?=> List[B] = xs.map(f.apply) // def mapFn[A, B]: (A => B) -> List[A] -> List[B] @@ -31,18 +31,18 @@ object Test { def apply(f: Fun[A, B] { type Eff = E}) = new Fun[List[A], List[B]] { type Eff = E - def apply(xs: List[A]): (given Eff) => List[B] = + def apply(xs: List[A]): Eff ?=> List[B] = map(f)(xs) } } - implicit def combine[E1 <: Effect, E2 <: Effect](given x: E1, y: E2): E1 & E2 = ??? + implicit def combine[E1 <: Effect, E2 <: Effect] with (x: E1, y: E2) : E1 & E2 = ??? // def compose(f: A => B)(g: B => C)(x: A): C def compose[A, B, C, E1 <: Effect, E2 <: Effect] (f: Fun[A, B] { type Eff = E1}) (g: Fun[B, C] { type Eff = E2}) - (x: A): (given E1 & E2) => C = g(f(x)) + (x: A): (E1 & E2) ?=> C = g(f(x)) // def composeFn: (A => B) -> (B => C) -> A -> C def composeFn[A, B, C, E1 <: Effect, E2 <: Effect]: diff --git a/tests/pos/given-constrapps.scala b/tests/pos/given-constrapps.scala index 8a108006257e..feccbc1dd777 100644 --- a/tests/pos/given-constrapps.scala +++ b/tests/pos/given-constrapps.scala @@ -1,29 +1,29 @@ class TC val tc = TC() -class C(given x: TC) { +class C with (x: TC) { assert(x eq tc) } -class C2(n: Int)(given x: TC)(given List[TC]) { +class C2(n: Int) with (x: TC) with List[TC] { assert(x eq tc) summon[List[TC]].foreach(t => assert(t eq tc)) - def this()(given TC)(given List[TC]) = this(1) + def this() with TC with List[TC] = this(1) } -class D extends C(given tc) -class D2 extends C2(1)(given tc)(given Nil) +class D extends C.with(tc) +class D2 extends C2(1).with(tc).with(Nil) -class Foo(given TC) { +class Foo with TC { assert(summon[TC] != null) } object Test extends App { - new C(given tc) - new C()(given tc) - new C(given tc) {} - new C2(1)(given tc)(given List(tc)) - new C2(1)(given tc)(given List(tc)) {} - new C2()(given tc)(given List(tc)) - def foo(given TC) = () - foo(given tc) + new C.with(tc) + new C().with(tc) + new C.with(tc) {} + new C2(1).with(tc).with(List(tc)) + new C2(1).with(tc).with(List(tc)) {} + new C2().with(tc).with(List(tc)) + def foo with TC = () + foo.with(tc) } \ No newline at end of file diff --git a/tests/pos/givenIn.scala b/tests/pos/givenIn.scala index 73e57bf20387..6e22c66f0f7e 100644 --- a/tests/pos/givenIn.scala +++ b/tests/pos/givenIn.scala @@ -2,14 +2,14 @@ object Test { import scala.compiletime.constValue class Context { - inline def givenIn[T](op: => (given Context) => T) = { + inline def givenIn[T](op: => Context ?=> T) = { given Context = this op } } def ctx: Context = new Context - def g(given Context) = () + def g with Context = () ctx.givenIn(g) /* The last three statements should generate the following code: diff --git a/tests/pos/ho-implicits.scala b/tests/pos/ho-implicits.scala index 93bcc04768a0..a48368020e7f 100644 --- a/tests/pos/ho-implicits.scala +++ b/tests/pos/ho-implicits.scala @@ -1,9 +1,9 @@ object Test2 { - implicit def __1: (given Int) => String = s"implicit: ${implicitly[Int]}" + implicit def __1: Int ?=> String = s"implicit: ${implicitly[Int]}" implicit def __2: Int = 42 - def f: (given String) => Int = implicitly[String].length + def f: String ?=> Int = implicitly[String].length f: Int } \ No newline at end of file diff --git a/tests/pos/i2278.scala b/tests/pos/i2278.scala index 82f17fa791db..2e9606f827a2 100644 --- a/tests/pos/i2278.scala +++ b/tests/pos/i2278.scala @@ -4,7 +4,7 @@ object Fluent { } trait CC[T] - type Context[Alg[x[_]] <: Foo[x], E] = (given Alg[CC]) => CC[E] + type Context[Alg[x[_]] <: Foo[x], E] = Alg[CC] ?=> CC[E] def meth1[T]() : Context[Foo, T] = { implicitly[Foo[CC]].meth1() diff --git a/tests/pos/i2671.scala b/tests/pos/i2671.scala index 7bb4eef9aaee..497d40c6f034 100644 --- a/tests/pos/i2671.scala +++ b/tests/pos/i2671.scala @@ -1,10 +1,10 @@ object Foo { - def map[E](f: (given E) => Int): ((given E) => Int) = ??? + def map[E](f: E ?=> Int): (E ?=> Int) = ??? implicit def i: Int = ??? - def f: (given Int) => Int = ??? + def f: Int ?=> Int = ??? val a: Int = map(f) diff --git a/tests/pos/i2723.scala b/tests/pos/i2723.scala index 2e2390235d3d..f1d05581467a 100644 --- a/tests/pos/i2723.scala +++ b/tests/pos/i2723.scala @@ -1,3 +1,3 @@ -trait App(init: (given Array[String]) => Unit) { - inline def main(args: Array[String]): Unit = init(given args) +trait App(init: Array[String] ?=> Unit) { + inline def main(args: Array[String]): Unit = init.with(args) } diff --git a/tests/pos/i2749.scala b/tests/pos/i2749.scala index ad2edc9ff176..54043fbbbb19 100644 --- a/tests/pos/i2749.scala +++ b/tests/pos/i2749.scala @@ -1,23 +1,23 @@ object Test { - val f: (given (given Int) => Char) => Boolean = ??? + val f: (Int ?=> Char) ?=> Boolean = ??? implicit val n: Int = 3 - implicit val g: (given Int) => Char = ??? + implicit val g: Int ?=> Char = ??? f : Boolean } object Test2 { - val f: (given (given Int) => Char) => Boolean = ??? + val f: (Int ?=> Char) ?=> Boolean = ??? implicit val s: String = null - implicit val g: (given Int) => (given String) => Char = ??? + implicit val g: Int ?=> String ?=> Char = ??? f : Boolean } object Test3 { - val f: (given (given Int) => (given String) => Char) => Boolean = ??? + val f: (Int ?=> String ?=> Char) ?=> Boolean = ??? implicit val n: Int = 3 - implicit val g: (given Int) => Char = ??? + implicit val g: Int ?=> Char = ??? f : Boolean } diff --git a/tests/pos/i2774.scala b/tests/pos/i2774.scala index 694e20313eae..30473eea6b4f 100644 --- a/tests/pos/i2774.scala +++ b/tests/pos/i2774.scala @@ -1,13 +1,13 @@ object Test { trait T; trait Q - val a: (given T) => (given Q) => Int = 1 + val a: T ?=> Q ?=> Int = 1 given Q = new Q {} - val i1: Int = a(given new T{}) + val i1: Int = a.with(new T{}) given T = new T {} val i2: Int = a val i3: Int = a2 - def a2(given t: T)(given q: Q): Int = 1 + def a2 with (t: T) with (q: Q) : Int = 1 } diff --git a/tests/pos/i3692.scala b/tests/pos/i3692.scala index 1313b63fc31c..3681bfb7b642 100644 --- a/tests/pos/i3692.scala +++ b/tests/pos/i3692.scala @@ -6,9 +6,9 @@ object Main { //val b: Int => Int = a def main(args: Array[String]): Unit = { - val choose: (given c: C) => Set[Int] = Set.empty - val b0: (C) => Set[Int] = choose(given _) - val b1: (c: C) => Set[Int] = choose(given _) + val choose: (c: C) ?=> Set[Int] = Set.empty + val b0: (C) => Set[Int] = choose.with(_) + val b1: (c: C) => Set[Int] = choose.with(_) def applyF(f: (c: C) => Set[Int]) = f(new C{type T=Int}) //applyF(choose) } diff --git a/tests/pos/i3912-3/i3912_1.scala b/tests/pos/i3912-3/i3912_1.scala index 5d3e5be014ca..4fafe0f87459 100644 --- a/tests/pos/i3912-3/i3912_1.scala +++ b/tests/pos/i3912-3/i3912_1.scala @@ -7,5 +7,5 @@ object Macros { } } - def impl()(given QuoteContext): Expr[Int] = '{1} + def impl() with QuoteContext : Expr[Int] = '{1} } \ No newline at end of file diff --git a/tests/pos/i4196.scala b/tests/pos/i4196.scala index e7cb83d9ee34..684bdc33aebe 100644 --- a/tests/pos/i4196.scala +++ b/tests/pos/i4196.scala @@ -1,6 +1,6 @@ object Test { @annotation.tailrec - def foo(i: (given Unit) => Int): (given Unit) => Int = + def foo(i: Unit ?=> Int): Unit ?=> Int = if (i == 0) 0 else diff --git a/tests/pos/i4203.scala b/tests/pos/i4203.scala index 337ef96e8911..6eda4628f760 100644 --- a/tests/pos/i4203.scala +++ b/tests/pos/i4203.scala @@ -1,7 +1,7 @@ case class Box[Z](unbox: Z) object Test { - def foo(b: Box[(given Int) => Int]): Int = b match { + def foo(b: Box[Int ?=> Int]): Int = b match { case Box(f) => implicit val i: Int = 1 f diff --git a/tests/pos/i4350.scala b/tests/pos/i4350.scala index 8b2127987bba..e114cad275ad 100644 --- a/tests/pos/i4350.scala +++ b/tests/pos/i4350.scala @@ -1,5 +1,5 @@ import scala.quoted._ -class Foo[T: Type](given QuoteContext) { +class Foo[T: Type] with QuoteContext { '{null.asInstanceOf[T]} } diff --git a/tests/pos/i4380a.scala b/tests/pos/i4380a.scala index 3d506a91b336..6c131923dd6b 100644 --- a/tests/pos/i4380a.scala +++ b/tests/pos/i4380a.scala @@ -3,7 +3,7 @@ import scala.quoted._ object Test { trait Producer[A] { self => - def step(k: (A => Expr[Unit]))(given QuoteContext): Expr[Unit] + def step(k: (A => Expr[Unit])) with QuoteContext : Expr[Unit] } trait Foo[A] @@ -13,7 +13,7 @@ object Test { stream match { case Bar(producer, nestedf) => { new Producer[Expr[A]] { - def step(k: Expr[A] => Expr[Unit])(given QuoteContext): Expr[Unit] = '{ + def step(k: Expr[A] => Expr[Unit]) with QuoteContext : Expr[Unit] = '{ val adv: Unit => Unit = { _ => ${producer.step((el) => nestedf(el))} } } } diff --git a/tests/pos/i4396a.scala b/tests/pos/i4396a.scala index 78c6eccde6f4..fb54511a6102 100644 --- a/tests/pos/i4396a.scala +++ b/tests/pos/i4396a.scala @@ -1,4 +1,4 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { '{ Option(4) match { case Some(a) => a; case None => 1 }} } diff --git a/tests/pos/i4396b.scala b/tests/pos/i4396b.scala index ba39a96d8c78..1240b7577781 100644 --- a/tests/pos/i4396b.scala +++ b/tests/pos/i4396b.scala @@ -1,4 +1,4 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { '{ case class Foo() } } \ No newline at end of file diff --git a/tests/pos/i4514.scala b/tests/pos/i4514.scala index 87283f8c263c..7e2b8f07c81b 100644 --- a/tests/pos/i4514.scala +++ b/tests/pos/i4514.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Foo { inline def foo[X](x: X): Unit = ${fooImpl('x)} - def fooImpl[X: Type](x: X)(given QuoteContext): Expr[Unit] = '{} + def fooImpl[X: Type](x: X) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/pos/i4539.scala b/tests/pos/i4539.scala index 74eba0fb0648..f11b0344cb49 100644 --- a/tests/pos/i4539.scala +++ b/tests/pos/i4539.scala @@ -1,5 +1,5 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { val q = '[String] '[String] } diff --git a/tests/pos/i4539b.scala b/tests/pos/i4539b.scala index bf6a16d6ca53..b3bd3f57a598 100644 --- a/tests/pos/i4539b.scala +++ b/tests/pos/i4539b.scala @@ -1,5 +1,5 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { def f = { { '[String] diff --git a/tests/pos/i4725.scala b/tests/pos/i4725.scala index 8659c2de181d..0e214a242cb4 100644 --- a/tests/pos/i4725.scala +++ b/tests/pos/i4725.scala @@ -1,8 +1,8 @@ object Test1 { trait T[A] - def foo[S[_], A](given ev: (given T[A]) => T[S[A]]): Unit = () - implicit def bar[A](given ev: T[A]): T[List[A]] = ??? + def foo[S[_], A] with (ev: (given T[A]) => T[S[A]]): Unit = () + implicit def bar[A] with (ev: T[A]) : T[List[A]] = ??? foo[List, Int] } @@ -11,8 +11,8 @@ object Test2 { trait T trait S - def foo(given ev: (given T) => S): Unit = () - implicit def bar(given ev: T): S = ??? + def foo with (ev: T ?=> S) : Unit = () + implicit def bar with (ev: T) : S = ??? foo } diff --git a/tests/pos/i4753.scala b/tests/pos/i4753.scala index 00ae8fdea753..5fcda241be5b 100644 --- a/tests/pos/i4753.scala +++ b/tests/pos/i4753.scala @@ -1,7 +1,7 @@ class A trait Foo { - def foo: (given A) => Int + def foo: A ?=> Int } class Test { @@ -9,5 +9,5 @@ class Test { } class FooI extends Foo { - def foo: (given A) => Int = 3 + def foo: A ?=> Int = 3 } \ No newline at end of file diff --git a/tests/pos/i4753b.scala b/tests/pos/i4753b.scala index a4faff882e9c..9052664e2ac1 100644 --- a/tests/pos/i4753b.scala +++ b/tests/pos/i4753b.scala @@ -1,7 +1,7 @@ class Foo1 { - def foo: (given String) => Int = 1 + def foo: String ?=> Int = 1 } class Foo2 extends Foo1 { - override def foo: (given String) => Int = 2 + override def foo: String ?=> Int = 2 } diff --git a/tests/pos/i4773.scala b/tests/pos/i4773.scala index fefbc9ee2727..01b4e2058ff7 100644 --- a/tests/pos/i4773.scala +++ b/tests/pos/i4773.scala @@ -2,6 +2,6 @@ import scala.quoted._ object Foo { inline def foo2(): Unit = ${foo2Impl()} - def foo2Impl()(given QuoteContext): Expr[Unit] = '{} + def foo2Impl() with QuoteContext : Expr[Unit] = '{} inline def foo(): Unit = foo2() } diff --git a/tests/pos/i4846.scala b/tests/pos/i4846.scala index d90c69aa0406..e97c3ba23628 100644 --- a/tests/pos/i4846.scala +++ b/tests/pos/i4846.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Test { inline def foo(inline x: Int): Int = ${fooImpl(x, 'x, '{ 'x }, '{ '{ 'x } })} - def fooImpl(a: Int, b: Expr[Int], c: Expr[(given QuoteContext) => Expr[Int]], d: Expr[(given QuoteContext) => Expr[(given QuoteContext) => Expr[Int]]]): Expr[Int] = ??? + def fooImpl(a: Int, b: Expr[Int], c: Expr[QuoteContext ?=> Expr[Int]], d: Expr[QuoteContext ?=> Expr[QuoteContext ?=> Expr[Int]]]): Expr[Int] = ??? } diff --git a/tests/pos/i4891.scala b/tests/pos/i4891.scala index ccc2c934325f..5c2229108775 100644 --- a/tests/pos/i4891.scala +++ b/tests/pos/i4891.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Test { - def foo(given QuoteContext): Expr[Option[String]] = '{None} + def foo with QuoteContext : Expr[Option[String]] = '{None} } diff --git a/tests/pos/i5295.scala b/tests/pos/i5295.scala index 75f463db9edb..0cbe0b2fe1a2 100644 --- a/tests/pos/i5295.scala +++ b/tests/pos/i5295.scala @@ -1,2 +1,2 @@ -inline def foo: String = bar(given 4) -private def bar: (given Int) => String = "baz" +inline def foo: String = bar.with(4) +private def bar: Int ?=> String = "baz" diff --git a/tests/pos/i5547.scala b/tests/pos/i5547.scala index 26f1bad2a25c..95ac2c55ebde 100644 --- a/tests/pos/i5547.scala +++ b/tests/pos/i5547.scala @@ -7,6 +7,6 @@ object scalatest { inline def assert2(condition: => Boolean): Unit = ${ assertImpl('condition, Expr("")) } - def assertImpl(condition: Expr[Boolean], clue: Expr[Any])(given QuoteContext): Expr[Unit] = + def assertImpl(condition: Expr[Boolean], clue: Expr[Any]) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/pos/i5833.scala b/tests/pos/i5833.scala index 78a7842bfd93..bd097d27770d 100644 --- a/tests/pos/i5833.scala +++ b/tests/pos/i5833.scala @@ -1,16 +1,16 @@ object Dependent{ - def x: (given i: Int) => Int = ??? - def y: (given i: Int) => Int = x + def x: (i: Int) ?=> Int = ??? + def y: (i: Int) ?=> Int = x } object Independent{ - def x: (given Int) => Int = ??? - def y: (given Int) => Int = x + def x: Int ?=> Int = ??? + def y: Int ?=> Int = x } object NarrowDependent{ - def x: (given Int) => Int = ??? - def y: (given i: Int) => Int = x + def x: Int ?=> Int = ??? + def y: (i: Int) ?=> Int = x } object WidenDependent{ - def x: (given i: Int) => Int = ??? - def y: (given Int) => Int = x + def x: (i: Int) ?=> Int = ??? + def y: Int ?=> Int = x } \ No newline at end of file diff --git a/tests/pos/i5954.scala b/tests/pos/i5954.scala index d14c1ddf1076..b55bb44413f6 100644 --- a/tests/pos/i5954.scala +++ b/tests/pos/i5954.scala @@ -5,7 +5,7 @@ abstract class MatcherFactory1 { object MatcherFactory1 { import scala.quoted._ - def impl(self: Expr[MatcherFactory1#AndNotWord])(given QuoteContext) = + def impl(self: Expr[MatcherFactory1#AndNotWord]) with QuoteContext = '{ val a: Any = $self } diff --git a/tests/pos/i5954b.scala b/tests/pos/i5954b.scala index b0cb1ed2eb79..26ccea1c6746 100644 --- a/tests/pos/i5954b.scala +++ b/tests/pos/i5954b.scala @@ -5,11 +5,11 @@ abstract class MatcherFactory1 { object MatcherFactory1 { import scala.quoted._ - def impl(self: Expr[MatcherFactory1#AndNotWord[Int]])(given QuoteContext) = + def impl(self: Expr[MatcherFactory1#AndNotWord[Int]]) with QuoteContext = '{ val a: Any = $self } - def impl[T: Type](self: Expr[MatcherFactory1#AndNotWord[T]])(given QuoteContext) = + def impl[T: Type](self: Expr[MatcherFactory1#AndNotWord[T]]) with QuoteContext = '{ val a: Any = $self } } diff --git a/tests/pos/i5954c.scala b/tests/pos/i5954c.scala index 5ae67c521628..83877b66783a 100644 --- a/tests/pos/i5954c.scala +++ b/tests/pos/i5954c.scala @@ -5,11 +5,11 @@ abstract class MatcherFactory1[A] { object MatcherFactory1 { import scala.quoted._ - def impl(self: Expr[MatcherFactory1[Int]#AndNotWord])(given QuoteContext) = + def impl(self: Expr[MatcherFactory1[Int]#AndNotWord]) with QuoteContext = '{ val a: Any = $self } - def impl[T: Type](self: Expr[MatcherFactory1[T]#AndNotWord])(given QuoteContext) = + def impl[T: Type](self: Expr[MatcherFactory1[T]#AndNotWord]) with QuoteContext = '{ val a: Any = $self } } diff --git a/tests/pos/i5954d.scala b/tests/pos/i5954d.scala index ec59abe167a6..9c7e343e7263 100644 --- a/tests/pos/i5954d.scala +++ b/tests/pos/i5954d.scala @@ -5,7 +5,7 @@ abstract class MatcherFactory1 { object MatcherFactory1 { import scala.quoted._ - def impl(self: Expr[MatcherFactory1#AndNotWord])(given QuoteContext) = + def impl(self: Expr[MatcherFactory1#AndNotWord]) with QuoteContext = '{ val a: Any = $self } diff --git a/tests/pos/i5966.scala b/tests/pos/i5966.scala index 42fccc476ee0..9e80f9387f22 100644 --- a/tests/pos/i5966.scala +++ b/tests/pos/i5966.scala @@ -1,8 +1,8 @@ object Test { - def foo = (given v: Int) => (x: Int) => v + x - given myInt : Int = 4 + def foo = (v: Int) ?=> (x: Int) => v + x + given myInt as Int = 4 foo.apply(1) - foo(given 2) + foo.with(2) foo(3) } diff --git a/tests/pos/i5978.scala b/tests/pos/i5978.scala index 9ab194405469..8fef8c97def4 100644 --- a/tests/pos/i5978.scala +++ b/tests/pos/i5978.scala @@ -7,18 +7,18 @@ trait TokenParser[Token, R] package p1 { object TextParser { - given TP : TokenParser[Char, Position[CharSequence]] {} + given TP as TokenParser[Char, Position[CharSequence]] {} def f - (given TokenParser[Char, Position[CharSequence]]) = ??? + with (TokenParser[Char, Position[CharSequence]]) = ??? - given FromCharToken(given T: TokenParser[Char, Position[CharSequence]]) + given FromCharToken with (T: TokenParser[Char, Position[CharSequence]]) : Conversion[Char, Position[CharSequence]] = ??? } object Testcase { def main(args: Array[String]): Unit = { - import TextParser.{given, _} + import TextParser.{given _, _} val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP val tp_i = summon[TokenParser[Char, Position[CharSequence]]] @@ -42,7 +42,7 @@ package p2 { object Testcase { def main(args: Array[String]): Unit = { - import TextParser.{given, _} + import TextParser.{given _, _} val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP val tp_i = summon[TokenParser[Char, Position[CharSequence]]] @@ -60,7 +60,7 @@ package p3 { object Testcase { def main(args: Array[String]): Unit = { - import TextParser.{_, given} + import TextParser.{_, given _} val co_i: Conversion[Char, Position[CharSequence]] = summon[Conversion[Char, Position[CharSequence]]] @@ -71,7 +71,7 @@ package p3 { val co_x : Position[CharSequence] = 'x' { - given XXX : Conversion[Char, Position[CharSequence]] = co_i + given XXX as Conversion[Char, Position[CharSequence]] = co_i val co_y : Position[CharSequence] = 'x' } } @@ -81,9 +81,9 @@ package p3 { package p4 { class TC - given A : TC + given A as TC - given B[X[_], Y] : TC + given B[X[_], Y] as TC - given C(given TC) : TC + given C with TC as TC } \ No newline at end of file diff --git a/tests/pos/i6008.scala b/tests/pos/i6008.scala index f1af11862527..793770fc9093 100644 --- a/tests/pos/i6008.scala +++ b/tests/pos/i6008.scala @@ -2,5 +2,5 @@ import scala.quoted._ class C { type T = Int - def fn(e : Expr[T])(given QuoteContext): Expr[T] = '{ println(); $e } + def fn(e : Expr[T]) with QuoteContext : Expr[T] = '{ println(); $e } } diff --git a/tests/pos/i6142.scala b/tests/pos/i6142.scala index da099ddc13f8..f6e8bd2f0a37 100644 --- a/tests/pos/i6142.scala +++ b/tests/pos/i6142.scala @@ -1,7 +1,7 @@ import scala.quoted._ object O { - def foo(given QuoteContext) = { + def foo with QuoteContext = { type T implicit val _: scala.quoted.Type[T] = ??? '[List[T]] diff --git a/tests/pos/i6214.scala b/tests/pos/i6214.scala index 736eabc8c28b..a98cebee62e8 100644 --- a/tests/pos/i6214.scala +++ b/tests/pos/i6214.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Test { - def res(x: quoted.Expr[Int])(given QuoteContext): quoted.Expr[Int] = x match { + def res(x: quoted.Expr[Int]) with QuoteContext : quoted.Expr[Int] = x match { case '{ val a: Int = $y; 1} => y // owner of `y` is `res` case _ => '{ val b: Int = ${val c = 2; Expr(c)}; 1} // owner of `c` is `b`, but that seems to be OK } diff --git a/tests/pos/i6214b.scala b/tests/pos/i6214b.scala index b6287a0c4b3d..807c98d873d4 100644 --- a/tests/pos/i6214b.scala +++ b/tests/pos/i6214b.scala @@ -1,5 +1,5 @@ object Test { - def res(x: quoted.Expr[Int])(given scala.quoted.QuoteContext): quoted.Expr[Int] = x match { + def res(x: quoted.Expr[Int]) with scala.quoted.QuoteContext : quoted.Expr[Int] = x match { case '{ val a: Int = ${ Foo('{ val b: Int = $y; b }) }; a } => y // owner of y is res } object Foo { diff --git a/tests/pos/i6253.scala b/tests/pos/i6253.scala index ca8e4b664b74..5d3ab6fe1014 100644 --- a/tests/pos/i6253.scala +++ b/tests/pos/i6253.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Macros { - def impl(self: Expr[StringContext])(given QuoteContext): Expr[String] = self match { + def impl(self: Expr[StringContext]) with QuoteContext : Expr[String] = self match { case '{ StringContext() } => '{""} case '{ StringContext($part1) } => part1 case '{ StringContext($part1, $part2) } => '{ $part1 + $part2 } diff --git a/tests/pos/i6373.scala b/tests/pos/i6373.scala index c9197f786fec..3b30388798bf 100644 --- a/tests/pos/i6373.scala +++ b/tests/pos/i6373.scala @@ -2,11 +2,11 @@ object Test { class Test { class Context(val t: Boolean) - type Contextual[T] = (given Context) => T + type Contextual[T] = Context ?=> T inline def f(): Contextual[Boolean] = summon[Context].t - given ctx : Context = new Context(true) + given ctx as Context = new Context(true) f() } diff --git a/tests/pos/i6435.scala b/tests/pos/i6435.scala index cdfb92d287b7..56f0dd2bbb61 100644 --- a/tests/pos/i6435.scala +++ b/tests/pos/i6435.scala @@ -1,7 +1,7 @@ class Foo { import scala.quoted._ import scala.quoted.matching._ - def f(sc: quoted.Expr[StringContext])(given QuoteContext): Unit = { + def f(sc: quoted.Expr[StringContext]) with QuoteContext : Unit = { val '{ StringContext(${parts}: _*) } = sc val ps0: Expr[Seq[String]] = parts diff --git a/tests/pos/i6783.scala b/tests/pos/i6783.scala index 6aa1ff4f04a7..86c6cc7d92e8 100644 --- a/tests/pos/i6783.scala +++ b/tests/pos/i6783.scala @@ -1,6 +1,6 @@ import scala.quoted._ -def testImpl(f: Expr[(Int, Int) => Int])(given QuoteContext): Expr[Int] = Expr.betaReduce(f)('{1}, '{2}) +def testImpl(f: Expr[(Int, Int) => Int]) with QuoteContext : Expr[Int] = Expr.betaReduce(f)('{1}, '{2}) inline def test(f: (Int, Int) => Int) = ${ testImpl('f) diff --git a/tests/pos/i6862/lib_1.scala b/tests/pos/i6862/lib_1.scala index 8cc95e6cc42a..e00546a3163b 100644 --- a/tests/pos/i6862/lib_1.scala +++ b/tests/pos/i6862/lib_1.scala @@ -1,3 +1,3 @@ trait Ctx -inline def foo(): Unit = (given x: Ctx) => () -def bar[T](b: (given Ctx) => Unit): Unit = ??? +inline def foo(): Unit = (x: Ctx) ?=> () +def bar[T](b: Ctx ?=> Unit): Unit = ??? diff --git a/tests/pos/i6862b/lib.scala b/tests/pos/i6862b/lib.scala index 978ff8897e0c..63de744aa592 100644 --- a/tests/pos/i6862b/lib.scala +++ b/tests/pos/i6862b/lib.scala @@ -4,5 +4,5 @@ trait Expr[+T] trait Ctx inline def foo(): Int = splice( bar() ) -def bar()(given Ctx): Expr[Int] = ??? -def splice[T](f: (given Ctx) => Expr[T]): T = ??? +def bar() with Ctx : Expr[Int] = ??? +def splice[T](f: Ctx ?=> Expr[T]): T = ??? diff --git a/tests/pos/i6863/lib_1.scala b/tests/pos/i6863/lib_1.scala index 3ad48ee96909..cde38c97220a 100644 --- a/tests/pos/i6863/lib_1.scala +++ b/tests/pos/i6863/lib_1.scala @@ -1,2 +1,2 @@ trait Ctx -inline def foo(): Unit = (given x: Ctx) => () +inline def foo(): Unit = (x: Ctx) ?=> () diff --git a/tests/pos/i6900.scala b/tests/pos/i6900.scala index 4c13f90e55f5..1975b641fcc2 100644 --- a/tests/pos/i6900.scala +++ b/tests/pos/i6900.scala @@ -8,7 +8,7 @@ object Test1 { // But not with newstyle /* - given [A]: Conversion[A, Foo[A]]: + given [A] as Conversion[A, Foo[A]]: def apply(a: A) = new Foo[A]: def foo[C]: C => A = _ => a */ diff --git a/tests/pos/i6914.scala b/tests/pos/i6914.scala index e611fee12ff5..b1ba069803c5 100644 --- a/tests/pos/i6914.scala +++ b/tests/pos/i6914.scala @@ -2,10 +2,10 @@ trait Expr[T] trait Liftable[T] object test1 { - class ToExpr[T](given Liftable[T]) extends Conversion[T, Expr[T]] { + class ToExpr[T] with Liftable[T] extends Conversion[T, Expr[T]] { def apply(x: T): Expr[T] = ??? } - given toExpr[T]: Liftable[T] => ToExpr[T] + given toExpr[T] with Liftable[T] as ToExpr[T] given Liftable[Int] = ??? given Liftable[String] = ??? @@ -18,7 +18,7 @@ object test1 { object test2 { - given autoToExpr[T](given Liftable[T]) : Conversion[T, Expr[T]] { + given autoToExpr[T] with Liftable[T] as Conversion[T, Expr[T]] { def apply(x: T): Expr[T] = ??? } diff --git a/tests/pos/i6938.scala b/tests/pos/i6938.scala index d592a0498d40..f4955e115ba3 100644 --- a/tests/pos/i6938.scala +++ b/tests/pos/i6938.scala @@ -1,5 +1,5 @@ trait Foo[T] object Foo: - given [T]: Foo[Tuple1[T]] - given [T, U]: Foo[(T, U)] - given [T, U, V]: Foo[(T, U, V)] \ No newline at end of file + given [T] as Foo[Tuple1[T]] + given [T, U] as Foo[(T, U)] + given [T, U, V] as Foo[(T, U, V)] \ No newline at end of file diff --git a/tests/pos/i6997.scala b/tests/pos/i6997.scala index 1c3449d0e6af..0be55ea66c22 100644 --- a/tests/pos/i6997.scala +++ b/tests/pos/i6997.scala @@ -1,7 +1,7 @@ import scala.quoted._ class Foo { - def mcrImpl(body: Expr[Any])(given t: Type[_ <: Any])(given ctx: QuoteContext): Expr[Any] = '{ + def mcrImpl(body: Expr[Any]) with (t: Type[_ <: Any]) with (ctx: QuoteContext) : Expr[Any] = '{ val tmp = ???.asInstanceOf[$t] tmp } diff --git a/tests/pos/i6997c.scala b/tests/pos/i6997c.scala index 9a9b481b335b..c16272d26c74 100644 --- a/tests/pos/i6997c.scala +++ b/tests/pos/i6997c.scala @@ -1,10 +1,10 @@ package playground -import scala.quoted.{_, given}, scala.quoted.matching._ +import scala.quoted.{_, given _}, scala.quoted.matching._ inline def mcr(x: => Any): Any = ${mcrImpl('x)} -def mcrImpl(body: Expr[Any])(given ctx: QuoteContext): Expr[Any] = +def mcrImpl(body: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = body match case '{$x: $t} => '{ diff --git a/tests/pos/i6998.scala b/tests/pos/i6998.scala index 819d6acbd719..19f13f55dc6a 100644 --- a/tests/pos/i6998.scala +++ b/tests/pos/i6998.scala @@ -1,5 +1,5 @@ import scala.quoted._ -def foo(given QuoteContext) : Unit = { +def foo with QuoteContext : Unit = { val '{ $f : (Int => Double) } = ??? } diff --git a/tests/pos/i7046.scala b/tests/pos/i7046.scala index a63778a980a8..e6cc43039b8c 100644 --- a/tests/pos/i7046.scala +++ b/tests/pos/i7046.scala @@ -1,7 +1,7 @@ import scala.quoted._ inline def mcr: Any = ${mcrImpl} -def mcrImpl(given ctx: QuoteContext): Expr[Any] = { +def mcrImpl with (ctx: QuoteContext) : Expr[Any] = { val tpl: Expr[1] = '{1} '{()} } diff --git a/tests/pos/i7048.scala b/tests/pos/i7048.scala index 8e121dc67322..a4a8fae5ccc9 100644 --- a/tests/pos/i7048.scala +++ b/tests/pos/i7048.scala @@ -7,7 +7,7 @@ trait IsExpr[T] { def f(x: Any): String = x.toString -def g[T](given e: IsExpr[T], tu: Type[e.Underlying]): (given QuoteContext) => Expr[String] = { +def g[T] with (e: IsExpr[T], tu: Type[e.Underlying]) : QuoteContext ?=> Expr[String] = { val underlying: Expr[e.Underlying] = e.expr '{f($underlying)} } diff --git a/tests/pos/i7048b.scala b/tests/pos/i7048b.scala index 1a5a88a092c3..92183d266817 100644 --- a/tests/pos/i7048b.scala +++ b/tests/pos/i7048b.scala @@ -6,7 +6,7 @@ trait IsExpr { val foo: IsExpr = ??? -def g()(given QuoteContext): Unit = { +def g() with QuoteContext : Unit = { val a = '[foo.Underlying] () } diff --git a/tests/pos/i7048c.scala b/tests/pos/i7048c.scala index a00228f85cd6..5d765aac7228 100644 --- a/tests/pos/i7048c.scala +++ b/tests/pos/i7048c.scala @@ -6,8 +6,8 @@ trait IsExpr { val foo: IsExpr = ??? -def g(e: IsExpr)(given tu: Type[e.Underlying]): Unit = ??? +def g(e: IsExpr) with (tu: Type[e.Underlying]) : Unit = ??? -def mcrImpl(given QuoteContext): Unit = { +def mcrImpl with QuoteContext : Unit = { g(foo) } diff --git a/tests/pos/i7048d.scala b/tests/pos/i7048d.scala index e9b5c46cc0a7..444e83330c1f 100644 --- a/tests/pos/i7048d.scala +++ b/tests/pos/i7048d.scala @@ -6,8 +6,8 @@ trait IsExpr { val foo: IsExpr = ??? -def g(e: IsExpr)(given tu: Type[e.Underlying]): Unit = ??? +def g(e: IsExpr) with (tu: Type[e.Underlying]) : Unit = ??? -def mcrImpl(given QuoteContext): Unit = { +def mcrImpl with QuoteContext : Unit = { g(foo) } diff --git a/tests/pos/i7052.scala b/tests/pos/i7052.scala index 501b9ec07f22..106c19d2aaf7 100644 --- a/tests/pos/i7052.scala +++ b/tests/pos/i7052.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Test { - def foo(str: Expr[String])(given QuoteContext) = '{ + def foo(str: Expr[String]) with QuoteContext = '{ @deprecated($str, "") def bar = ??? } diff --git a/tests/pos/i7070.scala b/tests/pos/i7070.scala index 0f65b8a3f418..a7d4abe82840 100644 --- a/tests/pos/i7070.scala +++ b/tests/pos/i7070.scala @@ -2,7 +2,7 @@ object Test { class C - def (str: String).foo: (given C) => Int = ??? + def (str: String).foo: C ?=> Int = ??? given C = ??? diff --git a/tests/pos/i7078.scala b/tests/pos/i7078.scala index e1299efa5e0b..70106e2e0356 100644 --- a/tests/pos/i7078.scala +++ b/tests/pos/i7078.scala @@ -1,7 +1,7 @@ trait A class B extends A -inline given tc <: A = B() +inline given tc as _ <: A = B() val x: B = summon[A] diff --git a/tests/pos/i7084.scala b/tests/pos/i7084.scala index bb6ddb96428e..2eb82e124b2c 100644 --- a/tests/pos/i7084.scala +++ b/tests/pos/i7084.scala @@ -3,10 +3,10 @@ object Test { type Foo extension on (y: Any) { - def g(given Foo): Any = ??? + def g with Foo : Any = ??? } - def f(x: Any)(given Foo): Any = { + def f(x: Any) with Foo : Any = { val y = x.g y.g diff --git a/tests/pos/i7087.scala b/tests/pos/i7087.scala index 8550ffd3e1aa..7fc487e8ad92 100644 --- a/tests/pos/i7087.scala +++ b/tests/pos/i7087.scala @@ -7,7 +7,7 @@ type F[T] = T match { } extension on [T](tup: T) { - def g(given Foo: F[T]) = ??? + def g with (Foo: F[T]) = ??? } -def f(x: G[Int])(given Foo: String) = x.g \ No newline at end of file +def f(x: G[Int]) with (Foo: String) = x.g \ No newline at end of file diff --git a/tests/pos/i7119.scala b/tests/pos/i7119.scala index 0124dafb155d..ab087c1a2210 100644 --- a/tests/pos/i7119.scala +++ b/tests/pos/i7119.scala @@ -1,9 +1,9 @@ class Impl -def (impl: Impl).prop(given Int) = ???//summon[Int] +def (impl: Impl).prop with Int = ???//summon[Int] def main(args: Array[String]): Unit = { given Int = 3 - println(new Impl().prop(given 3)) + println(new Impl().prop.with(3)) } \ No newline at end of file diff --git a/tests/pos/i7204.scala b/tests/pos/i7204.scala index 95e76848c800..01cc89f3fcf8 100644 --- a/tests/pos/i7204.scala +++ b/tests/pos/i7204.scala @@ -1,8 +1,8 @@ import scala.quoted._ object Foo { - def impl(given qctx: QuoteContext): Unit = { - import qctx.tasty.{_, given} + def impl with (qctx: QuoteContext) : Unit = { + import qctx.tasty.{_, given _} val Select(_, _) = (??? : Term) } } diff --git a/tests/pos/i7264.scala b/tests/pos/i7264.scala index 1d8181ab50a8..25a75daf533e 100644 --- a/tests/pos/i7264.scala +++ b/tests/pos/i7264.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - def f[T2](t: Type[T2])(given QuoteContext) = t match { + def f[T2](t: Type[T2]) with QuoteContext = t match { case '[ *:[Int, $t] ] => '[ *:[Int, $t] ] } diff --git a/tests/pos/i7264b.scala b/tests/pos/i7264b.scala index f401f3076b84..10603967c8a0 100644 --- a/tests/pos/i7264b.scala +++ b/tests/pos/i7264b.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - def f[T2: Type](e: Expr[T2])(given QuoteContext) = e match { + def f[T2: Type](e: Expr[T2]) with QuoteContext = e match { case '{ $x: *:[Int, $t] } => '[ *:[Int, $t] ] } diff --git a/tests/pos/i7264c.scala b/tests/pos/i7264c.scala index d6abd0113f03..ef60e2afee94 100644 --- a/tests/pos/i7264c.scala +++ b/tests/pos/i7264c.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - def f[T2: Type](e: Expr[T2])(given QuoteContext) = e match { + def f[T2: Type](e: Expr[T2]) with QuoteContext = e match { case '{ $x: $t0 } => t0 match case '[ *:[Int, $t] ] => diff --git a/tests/pos/i7358.scala b/tests/pos/i7358.scala index 3d60dcb621ec..27ad8a27013b 100644 --- a/tests/pos/i7358.scala +++ b/tests/pos/i7358.scala @@ -3,7 +3,7 @@ package test import scala.quoted._ import scala.compiletime._ -inline def summonT[Tp <: Tuple](given QuoteContext) <: Tuple = inline erasedValue[Tp] match { +inline def summonT[Tp <: Tuple] with QuoteContext <: Tuple = inline erasedValue[Tp] match { case _ : Unit => () case _ : (hd *: tl) => { type H = hd @@ -13,4 +13,4 @@ inline def summonT[Tp <: Tuple](given QuoteContext) <: Tuple = inline erasedValu } } -def test[T : Type](given QuoteContext) = summonT[Tuple1[List[T]]] +def test[T : Type] with QuoteContext = summonT[Tuple1[List[T]]] diff --git a/tests/pos/i7413.scala b/tests/pos/i7413.scala index d546b2c8a132..9539bc7d36ad 100644 --- a/tests/pos/i7413.scala +++ b/tests/pos/i7413.scala @@ -3,7 +3,7 @@ import scala.language.implicitConversions trait Fixture[A] extends Conversion[0, A] trait TestFramework[A] { - def (testName: String).in(test: (given Fixture[A]) => Unit): Unit = ??? + def (testName: String).in(test: Fixture[A] ?=> Unit): Unit = ??? } trait Greeter { @@ -13,7 +13,7 @@ trait Greeter { case class MyFixture(name: String, greeter: Greeter) object Test1: - given conv: Conversion[0, Greeter] + given conv as Conversion[0, Greeter] def apply(x: 0): Greeter = ??? val g: Greeter = 0 diff --git a/tests/pos/i7477.scala b/tests/pos/i7477.scala index ae095eeb42de..ccb3d53846ea 100644 --- a/tests/pos/i7477.scala +++ b/tests/pos/i7477.scala @@ -14,9 +14,9 @@ package X { class Test1 { - def spawn[T](f: => T)(given ec:ExecutionContext, naming: Int = 3): Future[T] = ??? + def spawn[T](f: => T) with (ec:ExecutionContext, naming: Int = 3) : Future[T] = ??? - def await[T](f:Future[T], atMost: Duration = Duration.Inf)(given ec: ExecutionContext):T = ??? + def await[T](f:Future[T], atMost: Duration = Duration.Inf) with (ec: ExecutionContext) :T = ??? def test(): Unit = { val promiseToWait = Promise[Int]() diff --git a/tests/pos/i7519.scala b/tests/pos/i7519.scala index d05787834b3a..ca37d884ffb1 100644 --- a/tests/pos/i7519.scala +++ b/tests/pos/i7519.scala @@ -7,7 +7,7 @@ object Test { class Quoted[T] inline def quote[T]: Quoted[T] = ${ quoteImpl[T] } - def quoteImpl[T: Type](given qctx: QuoteContext): Expr[Quoted[T]] = '{ + def quoteImpl[T: Type] with (qctx: QuoteContext) : Expr[Quoted[T]] = '{ new Quoted[T @Annot] } } diff --git a/tests/pos/i7519b.scala b/tests/pos/i7519b.scala index f47c3ba0b8b1..9e2e77e7ad71 100644 --- a/tests/pos/i7519b.scala +++ b/tests/pos/i7519b.scala @@ -7,7 +7,7 @@ class Quoted[T] inline def quote[T]: Quoted[T] = ${ quoteImpl[T] } -def quoteImpl[T: Type](given qctx: QuoteContext): Expr[Quoted[T]] = { +def quoteImpl[T: Type] with (qctx: QuoteContext) : Expr[Quoted[T]] = { val value: Expr[Int] = '{ 42 } '{ new Quoted[T @Annot($value)] } } diff --git a/tests/pos/i7532.scala b/tests/pos/i7532.scala index 173dc7da8d9d..0753a547fe2c 100644 --- a/tests/pos/i7532.scala +++ b/tests/pos/i7532.scala @@ -11,8 +11,8 @@ class Tasty { } object Foo { - def impl(given tasty: Tasty): Unit = { - import tasty.{_, given} + def impl with (tasty: Tasty) : Unit = { + import tasty.{_, given _} val Select() = (??? : Term) } } \ No newline at end of file diff --git a/tests/pos/i7602.scala b/tests/pos/i7602.scala index 0a380efc9d79..0aab3b74ffc3 100644 --- a/tests/pos/i7602.scala +++ b/tests/pos/i7602.scala @@ -2,6 +2,6 @@ object Test { type X[T] = ({ type F[_]; type R = F[T]})#R trait Monad[F[_]] - type of[M[_[_]], T] = ({ type F[_]; type R = (given M[F]) => F[T]})#R + type of[M[_[_]], T] = ({ type F[_]; type R = M[F] ?=> F[T]})#R def foo(a: of[Monad, String]) = ??? } diff --git a/tests/pos/i7700.scala b/tests/pos/i7700.scala index 07e822e1e141..5403fceec9d7 100644 --- a/tests/pos/i7700.scala +++ b/tests/pos/i7700.scala @@ -7,6 +7,6 @@ object Macros: inline def (sc: StringContext).show(args: =>Any*): String = ??? object Show: - def[A] (a: A) show(given S: Show[A]): String = S.show(a) + def[A] (a: A) show with (S: Show[A]) : String = S.show(a) export Macros.show \ No newline at end of file diff --git a/tests/pos/i7851.scala b/tests/pos/i7851.scala index def150672f19..19910acdd83c 100644 --- a/tests/pos/i7851.scala +++ b/tests/pos/i7851.scala @@ -10,7 +10,7 @@ given Wrapper[Unit] { type WrappedT = Unit } given [T: Wrappable]: Wrapper[T] { type WrappedT = Wrapped[T] } -given [H: Wrappable, T <: Tuple, WrappedT0 <: Tuple](given Wrapper.Aux[T, WrappedT0]): Wrapper[H *: T] { +given [H: Wrappable, T <: Tuple, WrappedT0 <: Tuple] with (Wrapper.Aux[T, WrappedT0]) : Wrapper[H *: T] { type WrappedT = Wrapped[H] *: WrappedT0 } diff --git a/tests/pos/ift-assign.scala b/tests/pos/ift-assign.scala index 63751a6b9c7b..7e9243760245 100644 --- a/tests/pos/ift-assign.scala +++ b/tests/pos/ift-assign.scala @@ -1,7 +1,7 @@ class Context object Test { - var f: (given Context) => String = (given _) => "" + var f: Context ?=> String = (_ ?=> "") f = f diff --git a/tests/pos/implicit-dep.scala b/tests/pos/implicit-dep.scala index 057ce4dd512a..6a8eee0772a0 100644 --- a/tests/pos/implicit-dep.scala +++ b/tests/pos/implicit-dep.scala @@ -5,5 +5,5 @@ trait HasT { object Test { - def foo: (given Int) => (given g: HasT) => g.T = ??? + def foo: Int ?=> (g: HasT) ?=> g.T = ??? } diff --git a/tests/pos/implicit-shadowing.scala b/tests/pos/implicit-shadowing.scala index 18d9ad1a49f6..99083e5ad9cf 100644 --- a/tests/pos/implicit-shadowing.scala +++ b/tests/pos/implicit-shadowing.scala @@ -20,8 +20,8 @@ object Test { } } - def h[T]: (given C1[T]) => Unit = { - def g[U]: (given C2[U]) => Unit = { + def h[T]: C1[T] ?=> Unit = { + def g[U]: C2[U] ?=> Unit = { implicitly[C1[T]] // OK: no shadowing for evidence parameters implicitly[C2[U]] } diff --git a/tests/pos/implicitFuns.scala b/tests/pos/implicitFuns.scala index ab7efdb2b992..39d9ca086142 100644 --- a/tests/pos/implicitFuns.scala +++ b/tests/pos/implicitFuns.scala @@ -10,7 +10,7 @@ class ConfManagement(papers: List[Paper], realScore: Map[Paper, Int]) extends Ap private def hasConflict(ps1: Set[Person], ps2: Iterable[Person]) = ps2.exists(ps1 contains _) - type Viewable[T] = (given Viewers) => T + type Viewable[T] = Viewers ?=> T def vs: Viewable[Viewers] = implicitly @@ -52,7 +52,7 @@ object Orderings extends App { x => y => x < y } - implicit def __2[T]: (given Ord[T]) => Ord[List[T]] = new Ord[List[T]] { + implicit def __2[T]: Ord[T] ?=> Ord[List[T]] = new Ord[List[T]] { def less: List[T] => List[T] => Boolean = xs => ys => if ys.isEmpty then false @@ -61,7 +61,7 @@ object Orderings extends App { else isLess(xs.head)(ys.head) } - def isLess[T]: T => T => (given Ord[T]) => Boolean = + def isLess[T]: T => T => Ord[T] ?=> Boolean = x => y => implicitly[Ord[T]].less(x)(y) println(isLess(Nil)(List(1, 2, 3))) diff --git a/tests/pos/inline-apply.scala b/tests/pos/inline-apply.scala index a8bfa7394779..9b8598f10523 100644 --- a/tests/pos/inline-apply.scala +++ b/tests/pos/inline-apply.scala @@ -3,9 +3,9 @@ class Context object Test { def transform()(implicit ctx: Context) = { - inline def withLocalOwner[T](op: (given Context) => T) = op(given ctx) + inline def withLocalOwner[T](op: Context ?=> T) = op.with(ctx) - withLocalOwner { (given ctx) => } + withLocalOwner { ctx ?=> } } } diff --git a/tests/pos/macro-docs.scala b/tests/pos/macro-docs.scala index 66436d2b80b9..f9bb4f9399ab 100644 --- a/tests/pos/macro-docs.scala +++ b/tests/pos/macro-docs.scala @@ -17,14 +17,14 @@ object MacrosMD_Liftable { } } - given [T: Liftable : Type] : Liftable[List[T]] { + given [T: Liftable : Type] as Liftable[List[T]] { def toExpr(xs: List[T]) = xs match { case head :: tail => '{ ${ Expr(head) } :: ${ toExpr(tail) } } case Nil => '{ Nil: List[T] } } } - def showExpr[T](expr: Expr[T])(given QuoteContext): Expr[String] = { + def showExpr[T](expr: Expr[T]) with QuoteContext : Expr[String] = { val code: String = expr.show Expr(code) } diff --git a/tests/pos/multi-given.scala b/tests/pos/multi-given.scala index 97092fc7ae00..ef2cb4ad8680 100644 --- a/tests/pos/multi-given.scala +++ b/tests/pos/multi-given.scala @@ -2,7 +2,7 @@ trait A trait B trait C -def fancy(given a: A, b: B, c: C) = "Fancy!" +def fancy with (a: A, b: B, c: C) = "Fancy!" def foo(implicit a: A, b: B, c: C) = "foo" given A, B {} diff --git a/tests/pos/multiversal.scala b/tests/pos/multiversal.scala index 938a4dddb8cb..a206b99db070 100644 --- a/tests/pos/multiversal.scala +++ b/tests/pos/multiversal.scala @@ -1,7 +1,7 @@ object Test { import scala.Eql - given [X, Y]: Eql[X, Y] => Eql[List[X], List[Y]] = Eql.derived + given [X, Y] with (Eql[X, Y]) as Eql[List[X], List[Y]] = Eql.derived val b: Byte = 1 val c: Char = 2 diff --git a/tests/pos/postconditions.scala b/tests/pos/postconditions.scala index d84f28f4e584..243540b0bcee 100644 --- a/tests/pos/postconditions.scala +++ b/tests/pos/postconditions.scala @@ -1,9 +1,9 @@ object PostConditions: opaque type WrappedResult[T] = T - def result[T](given r: WrappedResult[T]): T = r + def result[T] with (r: WrappedResult[T]) : T = r - def [T](x: T) ensuring (condition: (given WrappedResult[T]) => Boolean): T = + def [T](x: T) ensuring (condition: WrappedResult[T] ?=> Boolean): T = given WrappedResult[T] = x assert(condition) x diff --git a/tests/pos/quote-bind-T.scala b/tests/pos/quote-bind-T.scala index 1b882825b1d0..7a0c787564b8 100644 --- a/tests/pos/quote-bind-T.scala +++ b/tests/pos/quote-bind-T.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { - def matchX[T](x: Expr[T])(given Type[T], QuoteContext): Expr[T] = '{ + def matchX[T](x: Expr[T]) with (Type[T], QuoteContext) : Expr[T] = '{ $x match { case y: T => y } diff --git a/tests/pos/quote-liftable.scala b/tests/pos/quote-liftable.scala index 2f74bb7f86ce..1e55c12bee0b 100644 --- a/tests/pos/quote-liftable.scala +++ b/tests/pos/quote-liftable.scala @@ -1,6 +1,6 @@ import scala.quoted._ -def test(given QuoteContext) = { +def test with QuoteContext = { given QuoteContext = ??? diff --git a/tests/pos/quote-matching-implicit-types.scala b/tests/pos/quote-matching-implicit-types.scala index 4cc211a2e6cc..10ee78d0cf13 100644 --- a/tests/pos/quote-matching-implicit-types.scala +++ b/tests/pos/quote-matching-implicit-types.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Foo { - def f(e: Expr[Any])(given QuoteContext): Unit = e match { + def f(e: Expr[Any]) with QuoteContext : Unit = e match { case '{ foo[$t]($x) } => bar(x) case '{ foo[$t]($x) } if bar(x) => () case '{ foo[$t]($x) } => '{ foo($x) } diff --git a/tests/pos/quote-nested.scala b/tests/pos/quote-nested.scala index b1d0db392baa..aec2ebc4cc4e 100644 --- a/tests/pos/quote-nested.scala +++ b/tests/pos/quote-nested.scala @@ -5,7 +5,7 @@ object Macro { inline def foo: Unit = ${ nested() } - private def nested()(given QuoteContext): Expr[Unit] = '{ + private def nested() with QuoteContext : Expr[Unit] = '{ var i = 0 ${ val x: Expr[Double] = '{ diff --git a/tests/pos/quote-no-splices.scala b/tests/pos/quote-no-splices.scala index 0f5de4f6796d..2a2a0a2aded4 100644 --- a/tests/pos/quote-no-splices.scala +++ b/tests/pos/quote-no-splices.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - def foo(given QuoteContext): Unit = { + def foo with QuoteContext : Unit = { val expr ='{ val a = 3 println("foo") diff --git a/tests/pos/quote-non-static-macro.scala b/tests/pos/quote-non-static-macro.scala index 2cff78dc4423..655016075c26 100644 --- a/tests/pos/quote-non-static-macro.scala +++ b/tests/pos/quote-non-static-macro.scala @@ -14,5 +14,5 @@ object Foo { object Quox { inline def foo: Unit = ${Foo.impl} } - def impl(given QuoteContext): Expr[Unit] = '{} + def impl with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/pos/quote-this.scala b/tests/pos/quote-this.scala index a493d33c1093..fd68a0eda044 100644 --- a/tests/pos/quote-this.scala +++ b/tests/pos/quote-this.scala @@ -1,16 +1,16 @@ import scala.quoted._ class Foo { - def a(given QuoteContext): Expr[Int] = '{1} - def b(given QuoteContext): Expr[Int] = '{ + def a with QuoteContext : Expr[Int] = '{1} + def b with QuoteContext : Expr[Int] = '{ ${ this.a } } - def d(given QuoteContext): Expr[(given QuoteContext) => Expr[Int]] = '{ '{1} } + def d with QuoteContext : Expr[QuoteContext ?=> Expr[Int]] = '{ '{1} } def foo[T](x: T): T = x - def f(given QuoteContext) = '{ + def f with QuoteContext = '{ ${ foo[this.type](this).a } } @@ -21,5 +21,5 @@ class Foo { } object Foo { - def impl[T](x: Any)(given QuoteContext): Expr[Unit] = '{} + def impl[T](x: Any) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/pos/quoted-inline-quote.scala b/tests/pos/quoted-inline-quote.scala index 713de60e0df5..464da08d3c6e 100644 --- a/tests/pos/quoted-inline-quote.scala +++ b/tests/pos/quoted-inline-quote.scala @@ -1,6 +1,6 @@ import scala.quoted._ class Foo { - inline def foo(x: Expr[String])(given QuoteContext) = '{ println(${x}) } + inline def foo(x: Expr[String]) with QuoteContext = '{ println(${x}) } given QuoteContext = ??? foo('{"abc"}) diff --git a/tests/pos/quoted-pattern-type.scala b/tests/pos/quoted-pattern-type.scala index 67a9369d26e9..d2b0372ff01d 100644 --- a/tests/pos/quoted-pattern-type.scala +++ b/tests/pos/quoted-pattern-type.scala @@ -3,7 +3,7 @@ import scala.tasty.Reflection object Lib { - def impl[T: Type](arg: Expr[T])(given QuoteContext): Expr[T] = { + def impl[T: Type](arg: Expr[T]) with QuoteContext : Expr[T] = { arg match { case e @ '{ $x: Boolean } => e: Expr[T & Boolean] diff --git a/tests/pos/quotedPatterns.scala b/tests/pos/quotedPatterns.scala index da52f643eb5b..48e4380f855a 100644 --- a/tests/pos/quotedPatterns.scala +++ b/tests/pos/quotedPatterns.scala @@ -1,12 +1,12 @@ import scala.quoted._ object Test { - def x(given QuoteContext) = '{1 + 2} + def x with QuoteContext = '{1 + 2} def f(x: Int) = x def g(x: Int, y: Int) = x * y - def res(given QuoteContext): quoted.Expr[Int] = x match { + def res with QuoteContext : quoted.Expr[Int] = x match { case '{1 + 2} => '{0} case '{f($y)} => y case '{g($y, $z)} => '{$y * $z} diff --git a/tests/pos/reference/delegates.scala b/tests/pos/reference/delegates.scala index abc125da9021..24bdcf287950 100644 --- a/tests/pos/reference/delegates.scala +++ b/tests/pos/reference/delegates.scala @@ -22,15 +22,16 @@ class Common: def [A, B](x: F[A]) map (f: A => B) = x.flatMap(f `andThen` pure) def pure[A](x: A): F[A] +end Common object Instances extends Common: - given intOrd: Ord[Int]: + given intOrd as Ord[Int]: def (x: Int).compareTo(y: Int) = if (x < y) -1 else if (x > y) +1 else 0 - given listOrd[T]: Ord[T] => Ord[List[T]]: - def (xs: List[T]).compareTo(ys: List[T]): Int = (xs, ys).match + given listOrd[T] with Ord[T] as Ord[List[T]]: + def (xs: List[T]).compareTo(ys: List[T]): Int = (xs, ys) match case (Nil, Nil) => 0 case (Nil, _) => -1 case (_, Nil) => +1 @@ -48,41 +49,41 @@ object Instances extends Common: def second = xs.tail.head def third = xs.tail.tail.head - given listMonad: Monad[List]: + given listMonad as Monad[List]: def [A, B](xs: List[A]) flatMap (f: A => List[B]): List[B] = xs.flatMap(f) def pure[A](x: A): List[A] = List(x) - given readerMonad[Ctx]: Monad[[X] =>> Ctx => X]: + given readerMonad[Ctx] as Monad[[X] =>> Ctx => X]: def [A, B](r: Ctx => A) flatMap (f: A => Ctx => B): Ctx => B = ctx => f(r(ctx))(ctx) def pure[A](x: A): Ctx => A = ctx => x - def maximum[T](xs: List[T])(given Ord[T]): T = + def maximum[T](xs: List[T]) with Ord[T] : T = xs.reduceLeft((x, y) => if (x < y) y else x) - def descending[T](given asc: Ord[T]): Ord[T] = new Ord[T]: + def descending[T] with (asc: Ord[T]) : Ord[T] = new Ord[T]: def (x: T).compareTo(y: T) = asc.compareTo(y)(x) - def minimum[T](xs: List[T])(given Ord[T]) = - maximum(xs)(given descending) + def minimum[T](xs: List[T]) with Ord[T] = + maximum(xs).with(descending) def test(): Unit = val xs = List(1, 2, 3) println(maximum(xs)) - println(maximum(xs)(given descending)) - println(maximum(xs)(given descending(given intOrd))) + println(maximum(xs).with(descending)) + println(maximum(xs).with(descending.with(intOrd))) println(minimum(xs)) case class Context(value: String) - val c0: (given Context) => String = (given ctx) => ctx.value - val c1: ((given Context) => String) = (given ctx: Context) => ctx.value + val c0: Context ?=> String = ctx ?=> ctx.value + val c1: Context ?=> String = (ctx: Context) ?=> ctx.value class A class B - val ab: (given x: A, y: B) => Int = (given a: A, b: B) => 22 + val ab: (x: A, y: B) ?=> Int = (a: A, b: B) ?=> 22 trait TastyAPI: type Symbol @@ -98,7 +99,7 @@ object Instances extends Common: class D[T] - class C(given ctx: Context): + class C with (ctx: Context) : def f() = locally { given Context = this.ctx @@ -110,11 +111,11 @@ object Instances extends Common: println(summon[Context].value) } locally { - given d[T]: D[T] + given d[T] as D[T] println(summon[D[Int]]) } locally { - given Context => D[Int] + given with Context as D[Int] println(summon[D[Int]]) } end C @@ -122,7 +123,7 @@ object Instances extends Common: class Token(str: String) object Token: - given StringToToken : Conversion[String, Token]: + given StringToToken as Conversion[String, Token]: def apply(str: String): Token = new Token(str) val x: Token = "if" @@ -131,11 +132,11 @@ end Instances object PostConditions: opaque type WrappedResult[T] = T - def result[T](given x: WrappedResult[T]): T = x + def result[T] with (x: WrappedResult[T]) : T = x extension on [T](x: T): - def ensuring(condition: (given WrappedResult[T]) => Boolean): T = - assert(condition(given x)) + def ensuring(condition: WrappedResult[T] ?=> Boolean): T = + assert(condition.with(x)) x end PostConditions @@ -144,7 +145,7 @@ object AnonymousInstances extends Common: def (x: Int).compareTo(y: Int) = if (x < y) -1 else if (x > y) +1 else 0 - given [T: Ord] : Ord[List[T]]: + given [T: Ord] as Ord[List[T]]: def (xs: List[T]).compareTo(ys: List[T]): Int = (xs, ys).match case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -161,7 +162,7 @@ object AnonymousInstances extends Common: extension on [T](xs: List[T]): def second = xs.tail.head - given [From, To]: (c: Convertible[From, To]) => Convertible[List[From], List[To]]: + given [From, To] with (c: Convertible[From, To]) as Convertible[List[From], List[To]]: def (x: List[From]).convert: List[To] = x.map(c.convert) given Monoid[String]: @@ -207,7 +208,7 @@ object Implicits extends Common: object Test extends App: Instances.test() import PostConditions.result - import PostConditions.given + import PostConditions.{given _} val s = List(1, 2, 3).sum s.ensuring(result == 6) end Test @@ -231,9 +232,9 @@ object Completions: // // CompletionArg.from(statusCode) - given fromString : Conversion[String, CompletionArg] = Error(_) - given fromFuture : Conversion[Future[HttpResponse], CompletionArg] = Response(_) - given fromStatusCode : Conversion[Future[StatusCode], CompletionArg] = Status(_) + given fromString as Conversion[String, CompletionArg] = Error(_) + given fromFuture as Conversion[Future[HttpResponse], CompletionArg] = Response(_) + given fromStatusCode as Conversion[Future[StatusCode], CompletionArg] = Status(_) import CompletionArg._ def complete[T](arg: CompletionArg) = arg match diff --git a/tests/pos/reference/extension-methods.scala b/tests/pos/reference/extension-methods.scala index 2a543cf33fb3..5aa2c88ba713 100644 --- a/tests/pos/reference/extension-methods.scala +++ b/tests/pos/reference/extension-methods.scala @@ -14,7 +14,7 @@ object ExtMethods: xs.filter(_.length == maxLength) } } - given ops1: StringSeqOps + given ops1 as StringSeqOps List("here", "is", "a", "list").longestStrings @@ -53,23 +53,23 @@ object ExtMethods: def third: T = xs.tail.tail.head - extension on [T](xs: List[T])(given Ordering[T]): + extension on [T](xs: List[T]) with Ordering[T] : def largest(n: Int) = xs.sorted.takeRight(n) - given stringOps1: AnyRef { + given stringOps1 as AnyRef { def (xs: Seq[String]).longestStrings: Seq[String] = { val maxLength = xs.map(_.length).max xs.filter(_.length == maxLength) } } - given listOps1: AnyRef { + given listOps1 as AnyRef { def [T](xs: List[T]) second = xs.tail.head def [T](xs: List[T]) third: T = xs.tail.tail.head } given AnyRef { - def [T](xs: List[T]) largest (given Ordering[T])(n: Int) = + def [T](xs: List[T]) largest (n: Int) with Ordering[T] = xs.sorted.takeRight(n) } diff --git a/tests/pos/t5643.scala b/tests/pos/t5643.scala index 1ce34ba36226..b3732a4a93c9 100644 --- a/tests/pos/t5643.scala +++ b/tests/pos/t5643.scala @@ -13,7 +13,7 @@ object TupledEvidenceTest { def f[T : GetResult] = "" - f[(String,String)](getTuple[(String, String)]) + f[(String,String)].with(getTuple[(String, String)]) f[(String,String)] } diff --git a/tests/pos/the.scala b/tests/pos/the.scala index 550abfdcda70..f8559450be23 100644 --- a/tests/pos/the.scala +++ b/tests/pos/the.scala @@ -2,7 +2,7 @@ object Test { trait Foo { type T; val x: T } - given intFoo : Foo { + given intFoo as Foo { type T = Int val x = 3 } diff --git a/tests/pos/toexproftuple.scala b/tests/pos/toexproftuple.scala index 5609678288eb..40d8be189a10 100644 --- a/tests/pos/toexproftuple.scala +++ b/tests/pos/toexproftuple.scala @@ -1,8 +1,8 @@ import scala.quoted._, scala.deriving._ -import scala.quoted.given +import scala.quoted.{given _} inline def mcr: Any = ${mcrImpl} -def mcrImpl(given ctx: QuoteContext): Expr[Any] = { +def mcrImpl with (ctx: QuoteContext) : Expr[Any] = { val tpl: (Expr[1], Expr[2], Expr[3]) = ('{1}, '{2}, '{3}) '{val res: (1, 2, 3) = ${Expr.ofTuple(tpl)}; res} } diff --git a/tests/pos/tupled-function-instances.scala b/tests/pos/tupled-function-instances.scala index 01181dbae103..e7cf2ac85dde 100644 --- a/tests/pos/tupled-function-instances.scala +++ b/tests/pos/tupled-function-instances.scala @@ -30,31 +30,31 @@ object Test { summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T) => R, (given Tuple1[T]) => R]] - summon[TupledFunction[(given T, T) => R, (given (T, T)) => R]] - summon[TupledFunction[(given T, T, T) => R, (given (T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T) => R, (given (T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T) => R, (given (T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T) => R, (given (T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] - summon[TupledFunction[(given T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) => R, (given (T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) => R]] + summon[TupledFunction[T ?=> R, Tuple1[T] ?=> R]] + summon[TupledFunction[(T, T) ?=> R, ((T, T)) ?=> R]] + summon[TupledFunction[(T, T, T) ?=> R, ((T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T) ?=> R, ((T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T) ?=> R, ((T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] + summon[TupledFunction[(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T) ?=> R, ((T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T)) ?=> R]] type F2 = (T, T) => R diff --git a/tests/pos/tupled-given.scala b/tests/pos/tupled-given.scala deleted file mode 100644 index 3d354f2eebe2..000000000000 --- a/tests/pos/tupled-given.scala +++ /dev/null @@ -1,19 +0,0 @@ -class A -class B -class C -class D -class E -trait F - -given A() -given B() -given (A, B) => C() // this one is equivalent to ... -given A, B => D(), F // ... the one without the parens -given ((A, B)) => E() // to demand a tuple, add an extra pair of parens - -@main def Test = - summon[C] - summon[D] - summon[F] - given (A, B) = (summon[A], summon[B]) - summon[E] diff --git a/tests/pos/typetags.scala b/tests/pos/typetags.scala index 38ab45b09c12..e73e79647a1f 100644 --- a/tests/pos/typetags.scala +++ b/tests/pos/typetags.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { - def f[T: Type](given QuoteContext) = { + def f[T: Type] with QuoteContext = { implicitly[Type[Int]] implicitly[Type[List[Int]]] implicitly[Type[T]] diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala index 859c404dd3d6..c28fa19f308a 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def inspectBodyImpl(x: Expr[Int]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} x.unseal match { case Inlined(None, Nil, arg) => arg.symbol.tree.showExtractors case arg => arg.symbol.tree.showExtractors // TODO should all by name parameters be in an inline node? diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala index 523966bf435b..6f8789afbd3d 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def inspectBodyImpl(x: Expr[Int]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} x.unseal match { case Inlined(None, Nil, arg) => arg.symbol.tree.showExtractors case arg => arg.symbol.tree.showExtractors // TODO should all by name parameters be in an inline node? diff --git a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala index e7ded9fa7cf1..d254a5223a8c 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { implicit inline def printOwners[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val buff = new StringBuilder diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala index 35623f76e564..3fbfeb9cc9a5 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala @@ -6,8 +6,8 @@ object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def inspectBodyImpl(x: Expr[Int]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} def definitionString(sym: Symbol): Expr[String] = if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.showExtractors) diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala index 59b19ed56828..b748dbad9bbb 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala @@ -5,8 +5,8 @@ object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def inspectBodyImpl(x: Expr[Int]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} def definitionString(sym: Symbol): Expr[String] = if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.showExtractors) diff --git a/tests/run-custom-args/erased/erased-22.scala b/tests/run-custom-args/erased/erased-22.scala index 99b908602881..628bba4de504 100644 --- a/tests/run-custom-args/erased/erased-22.scala +++ b/tests/run-custom-args/erased/erased-22.scala @@ -10,7 +10,7 @@ object Test { println("foo") 42 } - def fun1 (given erased boo: Int): Int = { + def fun1 with (erased boo: Int) : Int = { println("fun1") 43 } diff --git a/tests/run-custom-args/erased/erased-23.scala b/tests/run-custom-args/erased/erased-23.scala deleted file mode 100644 index e76a0e8b7773..000000000000 --- a/tests/run-custom-args/erased/erased-23.scala +++ /dev/null @@ -1,22 +0,0 @@ -object Test { - - def main(args: Array[String]): Unit = { - fun { (given erased x: Int) => - println("lambda1") - "abc" - } - - fun2 { (given erased x: Int) => - println("lambda2") - "abc" - } - } - - def fun(f: (given erased Int) => String): String = { - f(given 35) - } - - def fun2(f: (given erased Int) => String): String = { - f(given 35) - } -} diff --git a/tests/run-custom-args/erased/erased-frameless.scala b/tests/run-custom-args/erased/erased-frameless.scala index ab372472f3ef..1b146519bd01 100644 --- a/tests/run-custom-args/erased/erased-frameless.scala +++ b/tests/run-custom-args/erased/erased-frameless.scala @@ -26,7 +26,7 @@ trait Dataset[T] { // Use c.label to do an untyped select on actual Spark Dataset, and // cast the result to TypedDataset[A] - def col[S <: String, A](s: S) (given erased ev: Exists[T, s.type, A]) = + def col[S <: String, A](s: S) with (erased ev: Exists[T, s.type, A]) = new Column[T, A](s) // ev is only here to check than this is safe, it's never used at runtime! def collect(): Vector[T] diff --git a/tests/run-custom-args/erased/erased-machine-state.scala b/tests/run-custom-args/erased/erased-machine-state.scala index aa2baa058f48..71c4844467e2 100644 --- a/tests/run-custom-args/erased/erased-machine-state.scala +++ b/tests/run-custom-args/erased/erased-machine-state.scala @@ -23,11 +23,11 @@ object IsOn { } class Machine[S <: State] private { - def turnedOn (given erased s: IsOff[S]): Machine[On] = { + def turnedOn with (erased s: IsOff[S]) : Machine[On] = { println("turnedOn") new Machine[On] } - def turnedOff (given erased s: IsOn[S]): Machine[Off] = { + def turnedOff with (erased s: IsOn[S]) : Machine[Off] = { println("turnedOff") new Machine[Off] } diff --git a/tests/run-custom-args/lambda-serialization-others.scala b/tests/run-custom-args/lambda-serialization-others.scala index abfdb1248b35..59a9612010f6 100644 --- a/tests/run-custom-args/lambda-serialization-others.scala +++ b/tests/run-custom-args/lambda-serialization-others.scala @@ -36,11 +36,11 @@ class C1 { class C2 extends Serializable /* Needed because of #5866 */ { - val impfun: (given Int) => Int = (given x1) => x1 + val impfun: Int ?=> Int = x1 ?=> x1 - val impdepfun: (given x1: Int) => List[x1.type] = (given x1) => List(x1) + val impdepfun: (x1: Int) ?=> List[x1.type] = x1 ?=> List(x1) - val erasedimpfun: (given erased Int) => Int = (given erased x1) => 0 + val erasedimpfun: (erased Int) ?=> Int = (erased x1) ?=> 0 } object Test { @@ -50,10 +50,10 @@ object Test { serializeDeserialize(c1.erasedfun) val c2 = new C2 - serializeDeserialize[(given Int) => Int](c2.impfun) + serializeDeserialize[Int ?=> Int](c2.impfun) // Won't compile until #5841 is merged - // serializeDeserialize[(given Int) => Int](c2.impdepfun) - serializeDeserialize[(given Int) => Int](c2.erasedimpfun) + // serializeDeserialize[Int ?=> Int](c2.impdepfun) + serializeDeserialize[Int ?=> Int](c2.erasedimpfun) } def serializeDeserialize[T <: AnyRef](obj: T): Unit = { diff --git a/tests/run-custom-args/phantom-OnHList.scala b/tests/run-custom-args/phantom-OnHList.scala index 6b376c5918eb..e61fa32dd88a 100644 --- a/tests/run-custom-args/phantom-OnHList.scala +++ b/tests/run-custom-args/phantom-OnHList.scala @@ -77,7 +77,7 @@ trait Appender[L1 <: HList, L2 <: HList] { } object Appender { - implicit def lowLevelAppender[L1 <: HList, L2 <: HList, O <: HList] (given erased p: PhantomAppender.Aux[L1, L2, O]): Appender[L1, L2] { type Out = O } = + implicit def lowLevelAppender[L1 <: HList, L2 <: HList, O <: HList] with (erased p: PhantomAppender.Aux[L1, L2, O]) : Appender[L1, L2] { type Out = O } = new Appender[L1, L2] { type Out = O def apply(l1: L1, l2: L2): Out = HListN(Array.concat(l1.underlying, l2.underlying)).asInstanceOf[O] @@ -89,5 +89,5 @@ object Appender { object PhantomAppender { type Aux[L1 <: HList, L2 <: HList, O <: HList] implicit erased def caseHNil[L <: HList]: Aux[HNil, L, L] = ??? - implicit erased def caseHCons[H, T <: HList, L <: HList, O <: HList] (given erased p: Aux[T, L, O]): Aux[H :: T, L, H :: O] = ??? + implicit erased def caseHCons[H, T <: HList, L <: HList, O <: HList] with (erased p: Aux[T, L, O]) : Aux[H :: T, L, H :: O] = ??? } diff --git a/tests/run-custom-args/run-macros-erased/macro-erased/1.scala b/tests/run-custom-args/run-macros-erased/macro-erased/1.scala index b17b422e505f..4f40794a0503 100644 --- a/tests/run-custom-args/run-macros-erased/macro-erased/1.scala +++ b/tests/run-custom-args/run-macros-erased/macro-erased/1.scala @@ -10,12 +10,12 @@ object Macro { inline def foo7(i: Int) = $ { case7('{ i })(1)('{ i }) } inline def foo8(i: Int) = $ { case8('{ i })('{ i })(1) } - def case1(erased i: Expr[Int])(given QuoteContext): Expr[Int] = '{ 0 } - def case2 (i: Int)(erased j: Expr[Int])(given QuoteContext): Expr[Int] = '{ 0 } - def case3(erased i: Expr[Int]) (j: Int)(given QuoteContext): Expr[Int] = '{ 0 } - def case4 (h: Int)(erased i: Expr[Int], j: Expr[Int])(given QuoteContext): Expr[Int] = '{ 0 } - def case5(erased i: Expr[Int], j: Expr[Int]) (h: Int)(given QuoteContext): Expr[Int] = '{ 0 } - def case6 (h: Int)(erased i: Expr[Int])(erased j: Expr[Int])(given QuoteContext): Expr[Int] = '{ 0 } - def case7(erased i: Expr[Int]) (h: Int)(erased j: Expr[Int])(given QuoteContext): Expr[Int] = '{ 0 } - def case8(erased i: Expr[Int])(erased j: Expr[Int]) (h: Int)(given QuoteContext): Expr[Int] = '{ 0 } + def case1(erased i: Expr[Int]) with QuoteContext : Expr[Int] = '{ 0 } + def case2 (i: Int)(erased j: Expr[Int]) with QuoteContext : Expr[Int] = '{ 0 } + def case3(erased i: Expr[Int]) (j: Int) with QuoteContext : Expr[Int] = '{ 0 } + def case4 (h: Int)(erased i: Expr[Int], j: Expr[Int]) with QuoteContext : Expr[Int] = '{ 0 } + def case5(erased i: Expr[Int], j: Expr[Int]) (h: Int) with QuoteContext : Expr[Int] = '{ 0 } + def case6 (h: Int)(erased i: Expr[Int])(erased j: Expr[Int]) with QuoteContext : Expr[Int] = '{ 0 } + def case7(erased i: Expr[Int]) (h: Int)(erased j: Expr[Int]) with QuoteContext : Expr[Int] = '{ 0 } + def case8(erased i: Expr[Int])(erased j: Expr[Int]) (h: Int) with QuoteContext : Expr[Int] = '{ 0 } } diff --git a/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/macro_1.scala b/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/macro_1.scala index bf2dcbde9492..cd1719e8c21a 100644 --- a/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/macro_1.scala +++ b/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/macro_1.scala @@ -3,31 +3,31 @@ import scala.quoted._ inline def isFunctionType[T:Type]: Boolean = ${ isFunctionTypeImpl('[T]) } -def isFunctionTypeImpl[T](tp: Type[T])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} +def isFunctionTypeImpl[T](tp: Type[T]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} Expr(tp.unseal.tpe.isFunctionType) } inline def isImplicitFunctionType[T:Type]: Boolean = ${ isImplicitFunctionTypeImpl('[T]) } -def isImplicitFunctionTypeImpl[T](tp: Type[T])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} +def isImplicitFunctionTypeImpl[T](tp: Type[T]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} Expr(tp.unseal.tpe.isImplicitFunctionType) } inline def isErasedFunctionType[T:Type]: Boolean = ${ isErasedFunctionTypeImpl('[T]) } -def isErasedFunctionTypeImpl[T](tp: Type[T])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} +def isErasedFunctionTypeImpl[T](tp: Type[T]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} Expr(tp.unseal.tpe.isErasedFunctionType) } inline def isDependentFunctionType[T:Type]: Boolean = ${ isDependentFunctionTypeImpl('[T]) } -def isDependentFunctionTypeImpl[T](tp: Type[T])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} +def isDependentFunctionTypeImpl[T](tp: Type[T]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} Expr(tp.unseal.tpe.isDependentFunctionType) } diff --git a/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/test_2.scala b/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/test_2.scala index ff89ad08c351..7ea0872f1f9e 100644 --- a/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/test_2.scala +++ b/tests/run-custom-args/run-macros-erased/reflect-isFunctionType/test_2.scala @@ -51,7 +51,7 @@ object Test { // type A = (b: Box) => b.T // assert(isDependentFunctionType[A]) - assert(isImplicitFunctionType[(given Int) => Int]) + assert(isImplicitFunctionType[Int ?=> Int]) assert(!isImplicitFunctionType[Int => Int]) // type B = given Set[Int] => Int // assert(isImplicitFunctionType[B]) diff --git a/tests/run-macros/expr-map-1/Macro_1.scala b/tests/run-macros/expr-map-1/Macro_1.scala index 872c072a1b3d..3e7d84d97662 100644 --- a/tests/run-macros/expr-map-1/Macro_1.scala +++ b/tests/run-macros/expr-map-1/Macro_1.scala @@ -3,12 +3,12 @@ import scala.quoted.matching._ inline def rewrite[T](x: => Any): Any = ${ stringRewriter('x) } -private def stringRewriter(e: Expr[Any])(given QuoteContext): Expr[Any] = +private def stringRewriter(e: Expr[Any]) with QuoteContext : Expr[Any] = StringRewriter.transform(e) private object StringRewriter extends util.ExprMap { - def transform[T](e: Expr[T])(given QuoteContext, Type[T]): Expr[T] = e match + def transform[T](e: Expr[T]) with (QuoteContext, Type[T]) : Expr[T] = e match case Const(s: String) => Expr(s.reverse) match case '{ $x: T } => x diff --git a/tests/run-macros/expr-map-2/Macro_1.scala b/tests/run-macros/expr-map-2/Macro_1.scala index 2cbb2297746e..31b355ddb0cb 100644 --- a/tests/run-macros/expr-map-2/Macro_1.scala +++ b/tests/run-macros/expr-map-2/Macro_1.scala @@ -3,12 +3,12 @@ import scala.quoted.matching._ inline def rewrite[T](x: => Any): Any = ${ stringRewriter('x) } -private def stringRewriter(e: Expr[Any])(given QuoteContext): Expr[Any] = +private def stringRewriter(e: Expr[Any]) with QuoteContext : Expr[Any] = StringRewriter.transform(e) private object StringRewriter extends util.ExprMap { - def transform[T](e: Expr[T])(given QuoteContext, Type[T]): Expr[T] = e match + def transform[T](e: Expr[T]) with (QuoteContext, Type[T]) : Expr[T] = e match case '{ ($x: Foo).x } => '{ new Foo(4).x } match case '{ $e: T } => e diff --git a/tests/run-macros/f-interpolation-1/FQuote_1.scala b/tests/run-macros/f-interpolation-1/FQuote_1.scala index cfa888ac01b7..d025f3c4a87b 100644 --- a/tests/run-macros/f-interpolation-1/FQuote_1.scala +++ b/tests/run-macros/f-interpolation-1/FQuote_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.language.implicitConversions @@ -9,8 +9,8 @@ object FQuote { inline def ff(args: => Any*): String = ${impl('this, 'args)} } - /*private*/ def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + /*private*/ def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} def liftListOfAny(lst: List[Term]): Expr[List[Any]] = lst match { case x :: xs => diff --git a/tests/run-macros/f-interpolator-neg/Macros_1.scala b/tests/run-macros/f-interpolator-neg/Macros_1.scala index d21875d53c98..5ea8dbf21fab 100644 --- a/tests/run-macros/f-interpolator-neg/Macros_1.scala +++ b/tests/run-macros/f-interpolator-neg/Macros_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.quoted.matching._ import scala.language.implicitConversions @@ -12,7 +12,7 @@ object TestFooErrors { // Defined in tests object Macro { - def fooErrors(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given QuoteContext): Expr[List[(Boolean, Int, Int, Int, String)]] = { + def fooErrors(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with QuoteContext : Expr[List[(Boolean, Int, Int, Int, String)]] = { (strCtxExpr, argsExpr) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) => fooErrorsImpl(parts, args, argsExpr) @@ -21,7 +21,7 @@ object Macro { } } - def fooErrorsImpl(parts0: Seq[Expr[String]], args: Seq[Expr[Any]], argsExpr: Expr[Seq[Any]])(given QuoteContext)= { + def fooErrorsImpl(parts0: Seq[Expr[String]], args: Seq[Expr[Any]], argsExpr: Expr[Seq[Any]]) with QuoteContext = { val errors = List.newBuilder[Expr[(Boolean, Int, Int, Int, String)]] // true if error, false if warning // 0 if part, 1 if arg, 2 if strCtx, 3 if args diff --git a/tests/run-macros/flops-rewrite-2/Macro_1.scala b/tests/run-macros/flops-rewrite-2/Macro_1.scala index 9b6124ad499a..49fd483fa8bc 100644 --- a/tests/run-macros/flops-rewrite-2/Macro_1.scala +++ b/tests/run-macros/flops-rewrite-2/Macro_1.scala @@ -7,7 +7,7 @@ def plus(x: Int, y: Int): Int = x + y def times(x: Int, y: Int): Int = x * y def power(x: Int, y: Int): Int = if y == 0 then 1 else times(x, power(x, y - 1)) -private def rewriteMacro[T: Type](x: Expr[T])(given QuoteContext): Expr[T] = { +private def rewriteMacro[T: Type](x: Expr[T]) with QuoteContext : Expr[T] = { val rewriter = Rewriter( postTransform = List( Transformation[Int] { @@ -50,7 +50,7 @@ object Transformation { new Transformation(transform) } class Transformation[T: Type](transform: PartialFunction[Expr[T], Expr[T]]) { - def apply[U: Type](e: Expr[U])(given QuoteContext): Expr[U] = { + def apply[U: Type](e: Expr[U]) with QuoteContext : Expr[U] = { e match { case '{ $e: T } => transform.applyOrElse(e, identity) match { case '{ $e2: U } => e2 } case e => e @@ -64,7 +64,7 @@ private object Rewriter { } private class Rewriter(preTransform: List[Transformation[_]] = Nil, postTransform: List[Transformation[_]] = Nil, fixPoint: Boolean) extends util.ExprMap { - def transform[T](e: Expr[T])(given QuoteContext, Type[T]): Expr[T] = { + def transform[T](e: Expr[T]) with (QuoteContext, Type[T]) : Expr[T] = { val e2 = preTransform.foldLeft(e)((ei, transform) => transform(ei)) val e3 = transformChildren(e2) val e4 = postTransform.foldLeft(e3)((ei, transform) => transform(ei)) diff --git a/tests/run-macros/flops-rewrite-3/Macro_1.scala b/tests/run-macros/flops-rewrite-3/Macro_1.scala index 241abe5ccb21..1e7a3a3a2e39 100644 --- a/tests/run-macros/flops-rewrite-3/Macro_1.scala +++ b/tests/run-macros/flops-rewrite-3/Macro_1.scala @@ -7,7 +7,7 @@ def plus(x: Int, y: Int): Int = x + y def times(x: Int, y: Int): Int = x * y def power(x: Int, y: Int): Int = if y == 0 then 1 else times(x, power(x, y - 1)) -private def rewriteMacro[T: Type](x: Expr[T])(given QuoteContext): Expr[T] = { +private def rewriteMacro[T: Type](x: Expr[T]) with QuoteContext : Expr[T] = { val rewriter = Rewriter().withFixPoint.withPost( Transformation.safe[Int] { case '{ plus($x, $y) } => @@ -56,7 +56,7 @@ object Transformation { } class CheckedTransformation(transform: PartialFunction[Expr[Any], Expr[Any]]) extends Transformation { - def apply[T: Type](e: Expr[T])(given QuoteContext): Expr[T] = { + def apply[T: Type](e: Expr[T]) with QuoteContext : Expr[T] = { transform.applyOrElse(e, identity) match { case '{ $e2: T } => e2 case '{ $e2: $t } => @@ -76,7 +76,7 @@ class CheckedTransformation(transform: PartialFunction[Expr[Any], Expr[Any]]) ex } class SafeTransformation[U: Type](transform: PartialFunction[Expr[U], Expr[U]]) extends Transformation { - def apply[T: Type](e: Expr[T])(given QuoteContext): Expr[T] = { + def apply[T: Type](e: Expr[T]) with QuoteContext : Expr[T] = { e match { case '{ $e: U } => transform.applyOrElse(e, identity) match { case '{ $e2: T } => e2 } case e => e @@ -85,7 +85,7 @@ class SafeTransformation[U: Type](transform: PartialFunction[Expr[U], Expr[U]]) } abstract class Transformation { - def apply[T: Type](e: Expr[T])(given QuoteContext): Expr[T] + def apply[T: Type](e: Expr[T]) with QuoteContext : Expr[T] } private object Rewriter { @@ -101,7 +101,7 @@ private class Rewriter private (preTransform: List[Transformation] = Nil, postTr def withPost(transform: Transformation): Rewriter = new Rewriter(preTransform, transform :: postTransform, fixPoint) - def transform[T](e: Expr[T])(given QuoteContext, Type[T]): Expr[T] = { + def transform[T](e: Expr[T]) with (QuoteContext, Type[T]) : Expr[T] = { val e2 = preTransform.foldLeft(e)((ei, transform) => transform(ei)) val e3 = transformChildren(e2) val e4 = postTransform.foldLeft(e3)((ei, transform) => transform(ei)) diff --git a/tests/run-macros/flops-rewrite/Macro_1.scala b/tests/run-macros/flops-rewrite/Macro_1.scala index 65c33bfd2033..062eb31771ae 100644 --- a/tests/run-macros/flops-rewrite/Macro_1.scala +++ b/tests/run-macros/flops-rewrite/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ inline def rewrite[T](x: => T): T = ${ rewriteMacro('x) } -private def rewriteMacro[T: Type](x: Expr[T])(given QuoteContext): Expr[T] = { +private def rewriteMacro[T: Type](x: Expr[T]) with QuoteContext : Expr[T] = { val rewriter = Rewriter( postTransform = { case '{ Nil.map[$t]($f) } => '{ Nil } @@ -29,7 +29,7 @@ private object Rewriter { } private class Rewriter(preTransform: Expr[Any] => Expr[Any], postTransform: Expr[Any] => Expr[Any], fixPoint: Boolean) extends util.ExprMap { - def transform[T](e: Expr[T])(given QuoteContext, Type[T]): Expr[T] = { + def transform[T](e: Expr[T]) with (QuoteContext, Type[T]) : Expr[T] = { val e2 = checkedTransform(e, preTransform) val e3 = transformChildren(e2) val e4 = checkedTransform(e3, postTransform) @@ -37,7 +37,7 @@ private class Rewriter(preTransform: Expr[Any] => Expr[Any], postTransform: Expr else e4 } - private def checkedTransform[T: Type](e: Expr[T], transform: Expr[T] => Expr[Any])(given QuoteContext): Expr[T] = { + private def checkedTransform[T: Type](e: Expr[T], transform: Expr[T] => Expr[Any]) with QuoteContext : Expr[T] = { transform(e) match { case '{ $x: T } => x case '{ $x: $t } => throw new Exception( diff --git a/tests/run-macros/gestalt-optional-staging/Macro_1.scala b/tests/run-macros/gestalt-optional-staging/Macro_1.scala index 2ed4186ea888..7e431731bf56 100644 --- a/tests/run-macros/gestalt-optional-staging/Macro_1.scala +++ b/tests/run-macros/gestalt-optional-staging/Macro_1.scala @@ -17,12 +17,12 @@ final class Optional[+A >: Null](val value: A) extends AnyVal { object Optional { // FIXME fix issue #5097 and enable private - /*private*/ def getOrElseImpl[T >: Null : Type](opt: Expr[Optional[T]], alt: Expr[T])(given QuoteContext): Expr[T] = '{ + /*private*/ def getOrElseImpl[T >: Null : Type](opt: Expr[Optional[T]], alt: Expr[T]) with QuoteContext : Expr[T] = '{ if ($opt.isEmpty) $alt else $opt.value } // FIXME fix issue #5097 and enable private - /*private*/ def mapImpl[A >: Null : Type, B >: Null : Type](opt: Expr[Optional[A]], f: Expr[A => B])(given QuoteContext): Expr[Optional[B]] = '{ + /*private*/ def mapImpl[A >: Null : Type, B >: Null : Type](opt: Expr[Optional[A]], f: Expr[A => B]) with QuoteContext : Expr[Optional[B]] = '{ if ($opt.isEmpty) new Optional(null) else new Optional(${Expr.betaReduce(f)('{$opt.value})}) } diff --git a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala index b51e450fab04..0898ccb834c8 100644 --- a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala +++ b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala @@ -6,96 +6,96 @@ import scala.quoted._ object TypeToolbox { /** are the two types equal? */ inline def =:=[A, B]: Boolean = ${tpEqImpl('[A], '[B])} - private def tpEqImpl[A, B](a: Type[A], b: Type[B])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} + private def tpEqImpl[A, B](a: Type[A], b: Type[B]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} Expr(a.unseal.tpe =:= b.unseal.tpe) } /** is `tp1` a subtype of `tp2` */ inline def <:<[A, B]: Boolean = ${tpLEqImpl('[A], '[B])} - private def tpLEqImpl[A, B](a: Type[A], b: Type[B])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} + private def tpLEqImpl[A, B](a: Type[A], b: Type[B]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} Expr(a.unseal.tpe <:< b.unseal.tpe) } /** type associated with the tree */ inline def typeOf[T, Expected](a: T): Boolean = ${typeOfImpl('a, '[Expected])} - private def typeOfImpl(a: Expr[_], expected: Type[_])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} + private def typeOfImpl(a: Expr[_], expected: Type[_]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} Expr(a.unseal.tpe =:= expected.unseal.tpe) } /** does the type refer to a case class? */ inline def isCaseClass[A]: Boolean = ${isCaseClassImpl('[A])} - private def isCaseClassImpl(tp: Type[_])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} + private def isCaseClassImpl(tp: Type[_]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} val sym = tp.unseal.symbol Expr(sym.isClassDef && sym.flags.is(Flags.Case)) } /** val fields of a case class Type -- only the ones declared in primary constructor */ inline def caseFields[T]: List[String] = ${caseFieldsImpl('[T])} - private def caseFieldsImpl(tp: Type[_])(given qctx: QuoteContext): Expr[List[String]] = { - import qctx.tasty.{_, given} + private def caseFieldsImpl(tp: Type[_]) with (qctx: QuoteContext) : Expr[List[String]] = { + import qctx.tasty.{_, given _} val fields = tp.unseal.symbol.caseFields.map(_.name) Expr(fields) } inline def fieldIn[T](inline mem: String): String = ${fieldInImpl('[T], mem)} - private def fieldInImpl(t: Type[_], mem: String)(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def fieldInImpl(t: Type[_], mem: String) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} val field = t.unseal.symbol.field(mem) Expr(if field.isNoSymbol then "" else field.name) } inline def fieldsIn[T]: Seq[String] = ${fieldsInImpl('[T])} - private def fieldsInImpl(t: Type[_])(given qctx: QuoteContext): Expr[Seq[String]] = { - import qctx.tasty.{_, given} + private def fieldsInImpl(t: Type[_]) with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given _} val fields = t.unseal.symbol.fields Expr(fields.map(_.name).toList) } inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl('[T], mem)} - private def methodInImpl(t: Type[_], mem: String)(given qctx: QuoteContext): Expr[Seq[String]] = { - import qctx.tasty.{_, given} + private def methodInImpl(t: Type[_], mem: String) with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given _} Expr(t.unseal.symbol.classMethod(mem).map(_.name)) } inline def methodsIn[T]: Seq[String] = ${methodsInImpl('[T])} - private def methodsInImpl(t: Type[_])(given qctx: QuoteContext): Expr[Seq[String]] = { - import qctx.tasty.{_, given} + private def methodsInImpl(t: Type[_]) with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given _} Expr(t.unseal.symbol.classMethods.map(_.name)) } inline def method[T](inline mem: String): Seq[String] = ${methodImpl('[T], mem)} - private def methodImpl(t: Type[_], mem: String)(given qctx: QuoteContext): Expr[Seq[String]] = { - import qctx.tasty.{_, given} + private def methodImpl(t: Type[_], mem: String) with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given _} Expr(t.unseal.symbol.method(mem).map(_.name)) } inline def methods[T]: Seq[String] = ${methodsImpl('[T])} - private def methodsImpl(t: Type[_])(given qctx: QuoteContext): Expr[Seq[String]] = { - import qctx.tasty.{_, given} + private def methodsImpl(t: Type[_]) with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given _} Expr(t.unseal.symbol.methods.map(_.name)) } inline def typeTag[T](x: T): String = ${typeTagImpl('[T])} - private def typeTagImpl(tp: Type[_])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def typeTagImpl(tp: Type[_]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} val res = tp.unseal.tpe.show Expr(res) } inline def companion[T1, T2]: Boolean = ${companionImpl('[T1], '[T2])} - private def companionImpl(t1: Type[_], t2: Type[_])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} + private def companionImpl(t1: Type[_], t2: Type[_]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} val res = t1.unseal.symbol.companionModule == t2.unseal.symbol Expr(res) } inline def companionName[T1]: String = ${companionNameImpl('[T1])} - private def companionNameImpl(tp: Type[_])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def companionNameImpl(tp: Type[_]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} val sym = tp.unseal.symbol val companionClass = if sym.isClassDef then sym.companionModule.companionClass diff --git a/tests/run-macros/i4515/Macro_1.scala b/tests/run-macros/i4515/Macro_1.scala index 74808f079207..6df5253ad7ca 100644 --- a/tests/run-macros/i4515/Macro_1.scala +++ b/tests/run-macros/i4515/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def foo[X](x: X): Unit = ${fooImpl('x)} - def fooImpl[X: quoted.Type](x: Expr[X])(given QuoteContext): Expr[Unit] = '{} + def fooImpl[X: quoted.Type](x: Expr[X]) with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/run-macros/i4515b/Macro_1.scala b/tests/run-macros/i4515b/Macro_1.scala index 5c79e6ae692b..88865527e41e 100644 --- a/tests/run-macros/i4515b/Macro_1.scala +++ b/tests/run-macros/i4515b/Macro_1.scala @@ -2,5 +2,5 @@ import scala.quoted._ object Macro { inline def foo: Unit = ${ fooImpl } - def fooImpl(given QuoteContext): Expr[Unit] = '{} + def fooImpl with QuoteContext : Expr[Unit] = '{} } diff --git a/tests/run-macros/i4734/Macro_1.scala b/tests/run-macros/i4734/Macro_1.scala index 280d43208114..ef82c50bad80 100644 --- a/tests/run-macros/i4734/Macro_1.scala +++ b/tests/run-macros/i4734/Macro_1.scala @@ -1,12 +1,12 @@ import scala.annotation.tailrec import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def unrolledForeach(seq: IndexedSeq[Int], f: => Int => Unit, inline unrollSize: Int): Unit = // or f: Int => Unit ${ unrolledForeachImpl('seq, 'f, unrollSize) } - def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSize: Int)(given QuoteContext): Expr[Unit] = '{ + def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSize: Int) with QuoteContext : Expr[Unit] = '{ val size = ($seq).length assert(size % (${unrollSize}) == 0) // for simplicity of the implementation var i = 0 @@ -24,7 +24,7 @@ object Macros { } class UnrolledRange(start: Int, end: Int) { - def foreach(f: Int => Expr[Unit])(given QuoteContext): Expr[Unit] = { + def foreach(f: Int => Expr[Unit]) with QuoteContext : Expr[Unit] = { @tailrec def loop(i: Int, acc: Expr[Unit]): Expr[Unit] = if (i >= 0) loop(i - 1, '{ ${f(i)}; $acc }) else acc diff --git a/tests/run-macros/i4735/Macro_1.scala b/tests/run-macros/i4735/Macro_1.scala index 41b5bb4fde3a..ba902f1c9cf9 100644 --- a/tests/run-macros/i4735/Macro_1.scala +++ b/tests/run-macros/i4735/Macro_1.scala @@ -1,5 +1,5 @@ import scala.annotation.tailrec -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.quoted._ @@ -8,7 +8,7 @@ object Macro { inline def unrolledForeach(inline unrollSize: Int, seq: Array[Int], f: => Int => Unit): Unit = // or f: Int => Unit ${ unrolledForeachImpl(unrollSize, 'seq, 'f) } - private def unrolledForeachImpl(unrollSize: Int, seq: Expr[Array[Int]], f: Expr[Int => Unit])(given QuoteContext): Expr[Unit] = '{ + private def unrolledForeachImpl(unrollSize: Int, seq: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = ($seq).length assert(size % (${unrollSize}) == 0) // for simplicity of the implementation var i = 0 @@ -26,7 +26,7 @@ object Macro { } private class UnrolledRange(start: Int, end: Int) { - def foreach(f: Int => Expr[Unit])(given QuoteContext): Expr[Unit] = { + def foreach(f: Int => Expr[Unit]) with QuoteContext : Expr[Unit] = { @tailrec def loop(i: Int, acc: Expr[Unit]): Expr[Unit] = if (i >= 0) loop(i - 1, '{ ${f(i)}; $acc }) else acc diff --git a/tests/run-macros/i4803/Macro_1.scala b/tests/run-macros/i4803/Macro_1.scala index aaffffec6ea2..624380f82489 100644 --- a/tests/run-macros/i4803/Macro_1.scala +++ b/tests/run-macros/i4803/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long)(given QuoteContext): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode('y, n / 2) } } else '{ $x * ${ powerCode(x, n - 1) } } diff --git a/tests/run-macros/i4803b/Macro_1.scala b/tests/run-macros/i4803b/Macro_1.scala index ce19a3a60d4e..a3c7bdbf2eab 100644 --- a/tests/run-macros/i4803b/Macro_1.scala +++ b/tests/run-macros/i4803b/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long)(given QuoteContext): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode('y, n / 2) } } else '{ $x * ${ powerCode(x, n - 1) } } diff --git a/tests/run-macros/i4803c/Macro_1.scala b/tests/run-macros/i4803c/Macro_1.scala index edcf59027aa4..610d6b2c6132 100644 --- a/tests/run-macros/i4803c/Macro_1.scala +++ b/tests/run-macros/i4803c/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long)(given QuoteContext): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${powerCode('y, n / 2)} } else '{ $x * ${powerCode(x, n - 1)} } diff --git a/tests/run-macros/i4803e/Macro_1.scala b/tests/run-macros/i4803e/Macro_1.scala index 72277b9bbb81..32121be592c7 100644 --- a/tests/run-macros/i4803e/Macro_1.scala +++ b/tests/run-macros/i4803e/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def power2(x: Expr[Double])(given QuoteContext) = '{ + def power2(x: Expr[Double]) with QuoteContext = '{ inline def power(x: Double, n: Long): Double = if (n == 0) 1.0 else if (n % 2 == 0) { val y = x * x; power(y, n / 2) } diff --git a/tests/run-macros/i4803f/Macro_1.scala b/tests/run-macros/i4803f/Macro_1.scala index f81a9dba586a..a53cbeddb5b6 100644 --- a/tests/run-macros/i4803f/Macro_1.scala +++ b/tests/run-macros/i4803f/Macro_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long)(given QuoteContext): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${powerCode('y, n / 2)} } else '{ $x * ${powerCode(x, n - 1)} } - def power2(x: Expr[Double])(given QuoteContext) = '{ + def power2(x: Expr[Double]) with QuoteContext = '{ inline def power(x: Double): Double = ${powerCode('x, 2)} power($x) } diff --git a/tests/run-macros/i4947e/Macro_1.scala b/tests/run-macros/i4947e/Macro_1.scala index cd105d02b8db..de9e1edab2e5 100644 --- a/tests/run-macros/i4947e/Macro_1.scala +++ b/tests/run-macros/i4947e/Macro_1.scala @@ -4,7 +4,7 @@ object Macros { def printStack(tag: String): Unit = { println(tag + ": "+ new Exception().getStackTrace().apply(1)) } - def assertImpl(expr: Expr[Boolean])(given QuoteContext) = '{ + def assertImpl(expr: Expr[Boolean]) with QuoteContext = '{ printStack("assertImpl") println($expr) } diff --git a/tests/run-macros/i4947f/Macro_1.scala b/tests/run-macros/i4947f/Macro_1.scala index b3589adc114c..76cc47e94af8 100644 --- a/tests/run-macros/i4947f/Macro_1.scala +++ b/tests/run-macros/i4947f/Macro_1.scala @@ -4,7 +4,7 @@ object Macros { def printStack(tag: String): Unit = { println(tag + ": "+ new Exception().getStackTrace().apply(1)) } - def assertImpl(expr: Expr[Boolean])(given QuoteContext) = '{ + def assertImpl(expr: Expr[Boolean]) with QuoteContext = '{ printStack("assertImpl") println($expr) } diff --git a/tests/run-macros/i5119/Macro_1.scala b/tests/run-macros/i5119/Macro_1.scala index d143c9b90164..f99c5b01bf25 100644 --- a/tests/run-macros/i5119/Macro_1.scala +++ b/tests/run-macros/i5119/Macro_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macro { class StringContextOps(sc: => StringContext) { inline def ff(args: => Any*): String = ${ Macro.impl('sc, 'args) } } implicit inline def XmlQuote(sc: => StringContext): StringContextOps = new StringContextOps(sc) - def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def impl(sc: Expr[StringContext], args: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} (sc.unseal.underlyingArgument.showExtractors + "\n" + args.unseal.underlyingArgument.showExtractors) } } diff --git a/tests/run-macros/i5119b/Macro_1.scala b/tests/run-macros/i5119b/Macro_1.scala index 399ddfd68f3c..602a2cfd4213 100644 --- a/tests/run-macros/i5119b/Macro_1.scala +++ b/tests/run-macros/i5119b/Macro_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macro { inline def ff(arg1: Any, arg2: Any): String = ${ Macro.impl('{arg1}, '{arg2}) } - def impl(arg1: Expr[Any], arg2: Expr[Any])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def impl(arg1: Expr[Any], arg2: Expr[Any]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} (arg1.unseal.underlyingArgument.showExtractors + "\n" + arg2.unseal.underlyingArgument.showExtractors) } diff --git a/tests/run-macros/i5188a/Macro_1.scala b/tests/run-macros/i5188a/Macro_1.scala index 23c77efe93fa..f22b9b8be1ce 100644 --- a/tests/run-macros/i5188a/Macro_1.scala +++ b/tests/run-macros/i5188a/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Lib { inline def sum(inline args: Int*): Int = ${ impl(args: _*) } - def impl(args: Int*)(given QuoteContext): Expr[Int] = args.sum + def impl(args: Int*) with QuoteContext : Expr[Int] = args.sum } diff --git a/tests/run-macros/i5533/Macro_1.scala b/tests/run-macros/i5533/Macro_1.scala index f5c3f62b689c..9c39c5a425d7 100644 --- a/tests/run-macros/i5533/Macro_1.scala +++ b/tests/run-macros/i5533/Macro_1.scala @@ -7,8 +7,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${assertImpl('condition)} - def assertImpl(condition: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(condition: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = condition.unseal diff --git a/tests/run-macros/i5533b/Macro_1.scala b/tests/run-macros/i5533b/Macro_1.scala index 3a986a9ed021..4a2cf04e290e 100644 --- a/tests/run-macros/i5533b/Macro_1.scala +++ b/tests/run-macros/i5533b/Macro_1.scala @@ -6,8 +6,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${assertImpl('condition)} - def assertImpl(condition: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(condition: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = condition.unseal def exprStr: String = condition.show diff --git a/tests/run-macros/i5536/Macro_1.scala b/tests/run-macros/i5536/Macro_1.scala index c4e1f9acb861..732f4930aead 100644 --- a/tests/run-macros/i5536/Macro_1.scala +++ b/tests/run-macros/i5536/Macro_1.scala @@ -3,8 +3,8 @@ import scala.quoted._ object scalatest { inline def assert(condition: => Boolean): Unit = ${assertImpl('condition)} - def assertImpl(condition: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(condition: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = condition.unseal def exprStr: String = condition.show diff --git a/tests/run-macros/i5629/Macro_1.scala b/tests/run-macros/i5629/Macro_1.scala index 67e5af217012..770b38959f41 100644 --- a/tests/run-macros/i5629/Macro_1.scala +++ b/tests/run-macros/i5629/Macro_1.scala @@ -4,16 +4,16 @@ object Macros { inline def assert(condition: => Boolean): Unit = ${ assertImpl('{condition}, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val b = cond.unseal.underlyingArgument.seal.cast[Boolean] '{ scala.Predef.assert($b) } } inline def thisLineNumber = ${ thisLineNumberImpl } - def thisLineNumberImpl(given qctx: QuoteContext): Expr[Int] = { - import qctx.tasty.{_, given} + def thisLineNumberImpl with (qctx: QuoteContext) : Expr[Int] = { + import qctx.tasty.{_, given _} Expr(rootPosition.startLine) } } diff --git a/tests/run-macros/i5715/Macro_1.scala b/tests/run-macros/i5715/Macro_1.scala index a1205573b5a6..d2bdb99e5b25 100644 --- a/tests/run-macros/i5715/Macro_1.scala +++ b/tests/run-macros/i5715/Macro_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} cond.unseal.underlyingArgument match { case app @ Apply(select @ Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/i5941/macro_1.scala b/tests/run-macros/i5941/macro_1.scala index 44caac2cc43f..4c40cd36c20b 100644 --- a/tests/run-macros/i5941/macro_1.scala +++ b/tests/run-macros/i5941/macro_1.scala @@ -11,8 +11,8 @@ object Lens { def set(t: T, s: S): S = _set(t)(s) } - def impl[S: Type, T: Type](getter: Expr[S => T])(given qctx: QuoteContext): Expr[Lens[S, T]] = { - import qctx.tasty.{_, given} + def impl[S: Type, T: Type](getter: Expr[S => T]) with (qctx: QuoteContext) : Expr[Lens[S, T]] = { + import qctx.tasty.{_, given _} import util._ // obj.copy(a = obj.a.copy(b = a.b.copy(c = v))) @@ -84,8 +84,8 @@ object Iso { def to(s: S): A = _to(s) } - def impl[S: Type, A: Type](given qctx: QuoteContext): Expr[Iso[S, A]] = { - import qctx.tasty.{_, given} + def impl[S: Type, A: Type] with (qctx: QuoteContext) : Expr[Iso[S, A]] = { + import qctx.tasty.{_, given _} import util._ val tpS = typeOf[S] @@ -123,8 +123,8 @@ object Iso { } } - def implUnit[S: Type](given qctx: QuoteContext): Expr[Iso[S, 1]] = { - import qctx.tasty.{_, given} + def implUnit[S: Type] with (qctx: QuoteContext) : Expr[Iso[S, 1]] = { + import qctx.tasty.{_, given _} import util._ val tpS = typeOf[S] @@ -160,7 +160,7 @@ object Iso { } // TODO: require whitebox macro - def implFields[S: Type](given qctx: QuoteContext): Expr[Iso[S, Any]] = ??? + def implFields[S: Type] with (qctx: QuoteContext) : Expr[Iso[S, Any]] = ??? } object GenIso { @@ -195,8 +195,8 @@ object Prism { def apply(a: A): S = app(a) } - def impl[S: Type, A <: S : Type](given qctx: QuoteContext): Expr[Prism[S, A]] = { - import qctx.tasty.{_, given} + def impl[S: Type, A <: S : Type] with (qctx: QuoteContext) : Expr[Prism[S, A]] = { + import qctx.tasty.{_, given _} import util._ '{ diff --git a/tests/run-macros/i6171/Macro_1.scala b/tests/run-macros/i6171/Macro_1.scala index 1cae0f9667f6..455ca48a86fe 100644 --- a/tests/run-macros/i6171/Macro_1.scala +++ b/tests/run-macros/i6171/Macro_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ def isImplicitMethodType(tp: Type): Boolean = tp match diff --git a/tests/run-macros/i6253-b/quoted_1.scala b/tests/run-macros/i6253-b/quoted_1.scala index 6a616308a06f..ae2605c3e806 100644 --- a/tests/run-macros/i6253-b/quoted_1.scala +++ b/tests/run-macros/i6253-b/quoted_1.scala @@ -5,7 +5,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(given QuoteContext): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) with QuoteContext : Expr[String] = { self match { case '{ StringContext($parts: _*) } => '{ diff --git a/tests/run-macros/i6253/quoted_1.scala b/tests/run-macros/i6253/quoted_1.scala index ad51fec640b2..2194e764cf47 100644 --- a/tests/run-macros/i6253/quoted_1.scala +++ b/tests/run-macros/i6253/quoted_1.scala @@ -5,7 +5,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(given QuoteContext): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) with QuoteContext : Expr[String] = { self match { case '{ StringContext($parts: _*) } => '{ StringContext($parts: _*).s($args: _*) } diff --git a/tests/run-macros/i6518/Macro_1.scala b/tests/run-macros/i6518/Macro_1.scala index f513ef6c7bd0..dcd3f6a5c87d 100644 --- a/tests/run-macros/i6518/Macro_1.scala +++ b/tests/run-macros/i6518/Macro_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def test(): String = ${ testImpl } - private def testImpl(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def testImpl with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} val classSym = typeOf[Function1[_, _]].classSymbol.get classSym.classMethod("apply") classSym.classMethods diff --git a/tests/run-macros/i6679/Macro_1.scala b/tests/run-macros/i6679/Macro_1.scala index 06a95ac798cd..e2bd2542e429 100644 --- a/tests/run-macros/i6679/Macro_1.scala +++ b/tests/run-macros/i6679/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ -def makeMatch[A: Type](head : Expr[A])(given qctx : QuoteContext) : Expr[Unit] = { - import qctx.tasty.{_, given} +def makeMatch[A: Type](head : Expr[A]) with (qctx : QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val sacrifice = '{ $head match { case _ => ??? } } sacrifice.unseal diff --git a/tests/run-macros/i6765-b/Macro_1.scala b/tests/run-macros/i6765-b/Macro_1.scala index cbe5a11d1b1b..014f2a5312b8 100644 --- a/tests/run-macros/i6765-b/Macro_1.scala +++ b/tests/run-macros/i6765-b/Macro_1.scala @@ -1,9 +1,9 @@ import scala.quoted._ -import scala.quoted.given +import scala.quoted.{given _} inline def foo = ${fooImpl} -def fooImpl(given qctx: QuoteContext) = { +def fooImpl with (qctx: QuoteContext) = { val res = Expr.ofList(List('{"One"})) Expr(res.show) } diff --git a/tests/run-macros/i6765-c/Macro_1.scala b/tests/run-macros/i6765-c/Macro_1.scala index 3d521e7788c2..739744e6ac67 100644 --- a/tests/run-macros/i6765-c/Macro_1.scala +++ b/tests/run-macros/i6765-c/Macro_1.scala @@ -1,9 +1,9 @@ import scala.quoted._ -import scala.quoted.given +import scala.quoted.{given _} inline def foo(inline n: Int) = ${fooImpl(n)} -def fooImpl(n: Int)(given qctx: QuoteContext) = { +def fooImpl(n: Int) with (qctx: QuoteContext) = { val res = Expr.ofList(List.tabulate(n)(i => Expr("#" + i))) '{ ${Expr(res.show)} + "\n" + $res.toString + "\n" } } diff --git a/tests/run-macros/i6765/Macro_1.scala b/tests/run-macros/i6765/Macro_1.scala index ba896209b190..08e09baed0a5 100644 --- a/tests/run-macros/i6765/Macro_1.scala +++ b/tests/run-macros/i6765/Macro_1.scala @@ -1,10 +1,10 @@ import scala.quoted._ -import scala.quoted.given +import scala.quoted.{given _} inline def foo = ${fooImpl} -def fooImpl(given qctx: QuoteContext) = { - import qctx.tasty.{_, given} +def fooImpl with (qctx: QuoteContext) = { + import qctx.tasty.{_, given _} val res = Expr.ofList(List('{"One"})) Expr(res.show) } diff --git a/tests/run-macros/i6988/FirstArg_1.scala b/tests/run-macros/i6988/FirstArg_1.scala index c3466d0c1b38..5d6f32456c86 100644 --- a/tests/run-macros/i6988/FirstArg_1.scala +++ b/tests/run-macros/i6988/FirstArg_1.scala @@ -8,8 +8,8 @@ object FirstArg { object Macros { import scala.quoted._ - def argsImpl(given qctx: QuoteContext): Expr[FirstArg] = { - import qctx.tasty.{_, given} + def argsImpl with (qctx: QuoteContext) : Expr[FirstArg] = { + import qctx.tasty.{_, given _} def enclosingClass(cur: Symbol = rootContext.owner): Symbol = if (cur.isClassDef) cur diff --git a/tests/run-macros/i6988/Test_2.scala b/tests/run-macros/i6988/Test_2.scala index 0cd8e65d82ee..fe1e3ea3f934 100644 --- a/tests/run-macros/i6988/Test_2.scala +++ b/tests/run-macros/i6988/Test_2.scala @@ -6,7 +6,7 @@ object Test { assert("p1" == firstArgName) assert("something" == firstArgValue) } - def debug(given foo.FirstArg): Unit = { + def debug with foo.FirstArg : Unit = { firstArgName = summon[foo.FirstArg].source firstArgValue = summon[foo.FirstArg].value } diff --git a/tests/run-macros/i7008/macro_1.scala b/tests/run-macros/i7008/macro_1.scala index c2130cc60d6d..4e964af2588e 100644 --- a/tests/run-macros/i7008/macro_1.scala +++ b/tests/run-macros/i7008/macro_1.scala @@ -1,18 +1,18 @@ import scala.quoted._, scala.quoted.matching._ -import scala.quoted.given +import scala.quoted.{given _} import scala.tasty._ case class Box[T](v: T) inline def mcr(expr: => Boolean): Unit = ${mcrProxy('expr)} -def mcrProxy(expr: Expr[Boolean])(given QuoteContext): Expr[Unit] = { +def mcrProxy(expr: Expr[Boolean]) with QuoteContext : Expr[Unit] = { val res = mcrImpl[Boolean]('{ (esx: Seq[Box[Boolean]]) => () }, expr) // println(s"Out: ${res.show}") res } -def mcrImpl[T](func: Expr[Seq[Box[T]] => Unit], expr: Expr[T])(given ctx: QuoteContext, tt: Type[T]): Expr[Unit] = { +def mcrImpl[T](func: Expr[Seq[Box[T]] => Unit], expr: Expr[T]) with (ctx: QuoteContext, tt: Type[T]) : Expr[Unit] = { import ctx.tasty._ val arg = Expr.ofSeq(Seq('{(Box($expr))})) Expr.betaReduce(func)(arg) diff --git a/tests/run-macros/i7048/Lib_1.scala b/tests/run-macros/i7048/Lib_1.scala index 1491f3e0c6a1..c45159dccb98 100644 --- a/tests/run-macros/i7048/Lib_1.scala +++ b/tests/run-macros/i7048/Lib_1.scala @@ -12,13 +12,13 @@ given [U] : IsExpr[Expr[U]] = new IsExpr[Expr[U]] { def f(x: Any): String = x.toString -def g[T](x: T)(given e: IsExpr[T], tu: Type[e.Underlying]): (given QuoteContext) => Expr[String] = { +def g[T](x: T) with (e: IsExpr[T], tu: Type[e.Underlying]) : QuoteContext ?=> Expr[String] = { val underlying: Expr[e.Underlying] = e.toExpr(x) '{f($underlying)} } inline def mcr(): Any = ${mcrImpl} -def mcrImpl(given QuoteContext): Expr[Any] = { +def mcrImpl with QuoteContext : Expr[Any] = { val x = '{1} g(x) } diff --git a/tests/run-macros/i7519c/Macro_1.scala b/tests/run-macros/i7519c/Macro_1.scala index 586a6d39006e..4c87cdc3f2ff 100644 --- a/tests/run-macros/i7519c/Macro_1.scala +++ b/tests/run-macros/i7519c/Macro_1.scala @@ -7,7 +7,7 @@ class Quoted[T] inline def quote[T]: String = ${ quoteImpl[T] } -def quoteImpl[T: Type](given qctx: QuoteContext): Expr[String] = { +def quoteImpl[T: Type] with (qctx: QuoteContext) : Expr[String] = { val value: Expr[Int] = '{ 42 } Expr(('{ new Quoted[T @Annot($value)] }).show) } diff --git a/tests/run-macros/i7715/Macros_1.scala b/tests/run-macros/i7715/Macros_1.scala index 7b16c1b60b5e..dae722a8b100 100644 --- a/tests/run-macros/i7715/Macros_1.scala +++ b/tests/run-macros/i7715/Macros_1.scala @@ -1,6 +1,6 @@ -import scala.quoted.{ given, _ } +import scala.quoted.{ given _, _ } inline def mcr(e: => Any): Any = ${mcrImpl('e)} -def mcrImpl(e: Expr[Any])(given ctx: QuoteContext): Expr[Any] = +def mcrImpl(e: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = e match case '{ $body } => body diff --git a/tests/run-macros/i7898/Macro_1.scala b/tests/run-macros/i7898/Macro_1.scala index d76d0567535e..f3662d2eca92 100644 --- a/tests/run-macros/i7898/Macro_1.scala +++ b/tests/run-macros/i7898/Macro_1.scala @@ -1,8 +1,8 @@ import quoted._ object Main { - def myMacroImpl(body: Expr[_])(given qctx: QuoteContext): Expr[_] = { - import qctx.tasty.{_, given} + def myMacroImpl(body: Expr[_]) with (qctx: QuoteContext) : Expr[_] = { + import qctx.tasty.{_, given _} val bodyTerm = body.underlyingArgument.unseal val showed = bodyTerm.show '{ diff --git a/tests/run-macros/i7964/Macro_1.scala b/tests/run-macros/i7964/Macro_1.scala index 4296cf565ca6..a794192bc831 100644 --- a/tests/run-macros/i7964/Macro_1.scala +++ b/tests/run-macros/i7964/Macro_1.scala @@ -7,7 +7,7 @@ enum Num { inline def foo(inline num: Num): Int = ${ fooExpr(num) } -private def fooExpr(num: Num)(given QuoteContext): Expr[Int] = Expr(toInt(num)) +private def fooExpr(num: Num) with QuoteContext : Expr[Int] = Expr(toInt(num)) private def toInt(num: Num): Int = num match { case Num.One => 1 diff --git a/tests/run-macros/inferred-repeated-result/test_1.scala b/tests/run-macros/inferred-repeated-result/test_1.scala index e84035e40901..1c4c10db47bd 100644 --- a/tests/run-macros/inferred-repeated-result/test_1.scala +++ b/tests/run-macros/inferred-repeated-result/test_1.scala @@ -1,10 +1,10 @@ object Macros { import scala.quoted._ - import scala.quoted.autolift.given + import scala.quoted.autolift.{given _} inline def go[T](t: => T) = ${ impl('t) } - def impl[T](expr: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](expr: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = expr.unseal diff --git a/tests/run-macros/inline-case-objects/Macro_1.scala b/tests/run-macros/inline-case-objects/Macro_1.scala index 562e6a2aad34..c3d5a7ff7ccd 100644 --- a/tests/run-macros/inline-case-objects/Macro_1.scala +++ b/tests/run-macros/inline-case-objects/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { - def impl(foo: Any)(given QuoteContext): Expr[String] = Expr(foo.getClass.getCanonicalName) + def impl(foo: Any) with QuoteContext : Expr[String] = Expr(foo.getClass.getCanonicalName) } case object Bar { diff --git a/tests/run-macros/inline-macro-inner-object/Macro_1.scala b/tests/run-macros/inline-macro-inner-object/Macro_1.scala index d8caaac30902..8e41e851833b 100644 --- a/tests/run-macros/inline-macro-inner-object/Macro_1.scala +++ b/tests/run-macros/inline-macro-inner-object/Macro_1.scala @@ -4,17 +4,17 @@ import scala.quoted._ object A { inline def f: Unit = ${impl} - private def impl(given qctx: QuoteContext): Expr[Unit] = { + private def impl with (qctx: QuoteContext) : Expr[Unit] = { '{println("A.f")} } object B { inline def f: Unit = ${impl} - private def impl(given qctx: QuoteContext): Expr[Unit] = { + private def impl with (qctx: QuoteContext) : Expr[Unit] = { '{println("A.B.f")} } object C { inline def f: Unit = ${impl} - private def impl(given qctx: QuoteContext): Expr[Unit] = { + private def impl with (qctx: QuoteContext) : Expr[Unit] = { '{println("A.B.C.f")} } } diff --git a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala index d930d6f6915e..4dd9a0abed46 100644 --- a/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala +++ b/tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala @@ -5,52 +5,52 @@ object E { inline def eval[T](inline x: E[T]): T = ${ impl(x) } - def impl[T](x: E[T])(given QuoteContext): Expr[T] = x.lift + def impl[T](x: E[T]) with QuoteContext : Expr[T] = x.lift } trait E[T] { - def lift(given QuoteContext): Expr[T] + def lift with QuoteContext : Expr[T] } case class I(n: Int) extends E[Int] { - def lift(given QuoteContext): Expr[Int] = Expr(n) + def lift with QuoteContext : Expr[Int] = Expr(n) } case class D(n: Double) extends E[Double] { - def lift(given QuoteContext): Expr[Double] = Expr(n) + def lift with QuoteContext : Expr[Double] = Expr(n) } case class Plus[T](x: E[T], y: E[T])(implicit op: Plus2[T]) extends E[T] { - def lift(given QuoteContext): Expr[T] = op(x.lift, y.lift) + def lift with QuoteContext : Expr[T] = op(x.lift, y.lift) } case class Times[T](x: E[T], y: E[T])(implicit op: Times2[T]) extends E[T] { - def lift(given QuoteContext): Expr[T] = op(x.lift, y.lift) + def lift with QuoteContext : Expr[T] = op(x.lift, y.lift) } trait Op2[T] { - def apply(x: Expr[T], y: Expr[T])(given QuoteContext): Expr[T] + def apply(x: Expr[T], y: Expr[T]) with QuoteContext : Expr[T] } trait Plus2[T] extends Op2[T] object Plus2 { implicit case object IPlus extends Plus2[Int] { - def apply(x: Expr[Int], y: Expr[Int])(given QuoteContext): Expr[Int] = '{$x + $y} + def apply(x: Expr[Int], y: Expr[Int]) with QuoteContext : Expr[Int] = '{$x + $y} } implicit case object DPlus extends Plus2[Double] { - def apply(x: Expr[Double], y: Expr[Double])(given QuoteContext): Expr[Double] = '{$x + $y} + def apply(x: Expr[Double], y: Expr[Double]) with QuoteContext : Expr[Double] = '{$x + $y} } } trait Times2[T] extends Op2[T] object Times2 { implicit case object ITimes extends Times2[Int] { - def apply(x: Expr[Int], y: Expr[Int])(given QuoteContext): Expr[Int] = '{$x * $y} + def apply(x: Expr[Int], y: Expr[Int]) with QuoteContext : Expr[Int] = '{$x * $y} } implicit case object DTimes extends Times2[Double] { - def apply(x: Expr[Double], y: Expr[Double])(given QuoteContext): Expr[Double] = '{$x * $y} + def apply(x: Expr[Double], y: Expr[Double]) with QuoteContext : Expr[Double] = '{$x * $y} } } diff --git a/tests/run-macros/inline-option/Macro_1.scala b/tests/run-macros/inline-option/Macro_1.scala index 727cb669385b..8dda1ddb9c16 100644 --- a/tests/run-macros/inline-option/Macro_1.scala +++ b/tests/run-macros/inline-option/Macro_1.scala @@ -1,14 +1,14 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { - def impl(opt: Option[Int])(given QuoteContext): Expr[Int] = opt match { + def impl(opt: Option[Int]) with QuoteContext : Expr[Int] = opt match { case Some(i) => i case None => '{-1} } - def impl2(opt: Option[Option[Int]])(given QuoteContext): Expr[Int] = impl(opt.flatten) + def impl2(opt: Option[Option[Int]]) with QuoteContext : Expr[Int] = impl(opt.flatten) } diff --git a/tests/run-macros/inline-tuples-1/Macro_1.scala b/tests/run-macros/inline-tuples-1/Macro_1.scala index 374be1966fe8..7317640726bd 100644 --- a/tests/run-macros/inline-tuples-1/Macro_1.scala +++ b/tests/run-macros/inline-tuples-1/Macro_1.scala @@ -1,28 +1,28 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { - def tup1(tup: Tuple1[Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup2(tup: Tuple2[Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup3(tup: Tuple3[Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup4(tup: Tuple4[Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup5(tup: Tuple5[Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup6(tup: Tuple6[Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup7(tup: Tuple7[Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup8(tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup9(tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup10(tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup11(tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup12(tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup13(tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup14(tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup15(tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup16(tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup17(tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup18(tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup19(tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup20(tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup21(tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum - def tup22(tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int])(given QuoteContext): Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup1(tup: Tuple1[Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup2(tup: Tuple2[Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup3(tup: Tuple3[Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup4(tup: Tuple4[Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup5(tup: Tuple5[Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup6(tup: Tuple6[Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup7(tup: Tuple7[Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup8(tup: Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup9(tup: Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup10(tup: Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup11(tup: Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup12(tup: Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup13(tup: Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup14(tup: Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup15(tup: Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup16(tup: Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup17(tup: Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup18(tup: Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup19(tup: Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup20(tup: Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup21(tup: Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum + def tup22(tup: Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]) with QuoteContext : Expr[Int] = tup.productIterator.map(_.asInstanceOf[Int]).sum } diff --git a/tests/run-macros/inline-tuples-2/Macro_1.scala b/tests/run-macros/inline-tuples-2/Macro_1.scala index 2fd93984ee36..87ccb364674c 100644 --- a/tests/run-macros/inline-tuples-2/Macro_1.scala +++ b/tests/run-macros/inline-tuples-2/Macro_1.scala @@ -1,11 +1,11 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { - def impl(tup: Tuple1[Int])(given QuoteContext): Expr[Int] = tup._1 + def impl(tup: Tuple1[Int]) with QuoteContext : Expr[Int] = tup._1 - def impl2(tup: Tuple1[Tuple1[Int]])(given QuoteContext): Expr[Int] = impl(tup._1) + def impl2(tup: Tuple1[Tuple1[Int]]) with QuoteContext : Expr[Int] = impl(tup._1) } diff --git a/tests/run-macros/inline-varargs-1/Macro_1.scala b/tests/run-macros/inline-varargs-1/Macro_1.scala index 04a6d88760d7..7c8b7cea7653 100644 --- a/tests/run-macros/inline-varargs-1/Macro_1.scala +++ b/tests/run-macros/inline-varargs-1/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { - def sum(nums: Int*)(given QuoteContext): Expr[Int] = nums.sum + def sum(nums: Int*) with QuoteContext : Expr[Int] = nums.sum } diff --git a/tests/run-macros/macros-in-same-project1/Foo.scala b/tests/run-macros/macros-in-same-project1/Foo.scala index 524ccde401f8..b2dbc8b0fbe8 100644 --- a/tests/run-macros/macros-in-same-project1/Foo.scala +++ b/tests/run-macros/macros-in-same-project1/Foo.scala @@ -4,6 +4,6 @@ object Foo { inline def myMacro(): Unit = ${ aMacroImplementation } - def aMacroImplementation(given QuoteContext): Expr[Unit] = '{ println("Hello") } + def aMacroImplementation with QuoteContext : Expr[Unit] = '{ println("Hello") } } \ No newline at end of file diff --git a/tests/run-macros/no-symbol/1.scala b/tests/run-macros/no-symbol/1.scala index fe7c219f7f80..af5c12497a46 100644 --- a/tests/run-macros/no-symbol/1.scala +++ b/tests/run-macros/no-symbol/1.scala @@ -9,7 +9,7 @@ object Macro { ${ fooImpl } def fooImpl[T](implicit t: Type[T], qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} val sym = t.unseal.symbol if sym.isClassDef then '{ "symbol" } else if sym.isNoSymbol then '{ "no symbol" } diff --git a/tests/run-macros/quote-and-splice/Macros_1.scala b/tests/run-macros/quote-and-splice/Macros_1.scala index 358fd7abc7a2..bc51fb02dbde 100644 --- a/tests/run-macros/quote-and-splice/Macros_1.scala +++ b/tests/run-macros/quote-and-splice/Macros_1.scala @@ -3,23 +3,23 @@ import scala.quoted._ object Macros { inline def macro1 = ${ macro1Impl } - def macro1Impl(given QuoteContext) = '{3} + def macro1Impl with QuoteContext = '{3} inline def macro2(inline p: Boolean) = ${ macro2Impl(p) } - def macro2Impl(p: Boolean)(given QuoteContext) = if (p) '{3} else '{4} + def macro2Impl(p: Boolean) with QuoteContext = if (p) '{3} else '{4} inline def macro3(n: Int) = ${ macro3Impl('n) } - def macro3Impl(p: Expr[Int])(given QuoteContext) = '{ 2 + $p } + def macro3Impl(p: Expr[Int]) with QuoteContext = '{ 2 + $p } inline def macro4(i: Int)(j: Int) = ${ macro4Impl('i)('j) } - def macro4Impl(i: Expr[Int])(j: Expr[Int])(given QuoteContext) = '{ $i + $j } + def macro4Impl(i: Expr[Int])(j: Expr[Int]) with QuoteContext = '{ $i + $j } inline def macro5(i: Int, j: Int) = ${ macro5Impl(j = 'j, i = 'i) } - def macro5Impl(i: Expr[Int], j: Expr[Int])(given QuoteContext) = '{ $i + $j } + def macro5Impl(i: Expr[Int], j: Expr[Int]) with QuoteContext = '{ $i + $j } inline def power(inline n: Int, x: Double) = ${ powerCode(n, 'x) } - def powerCode(n: Int, x: Expr[Double])(given QuoteContext): Expr[Double] = + def powerCode(n: Int, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } diff --git a/tests/run-macros/quote-change-owner/Macro_1.scala b/tests/run-macros/quote-change-owner/Macro_1.scala index bb631f713892..5bb0a792f80b 100644 --- a/tests/run-macros/quote-change-owner/Macro_1.scala +++ b/tests/run-macros/quote-change-owner/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Macros { inline def assert2(expr: => Boolean): Unit = ${ assertImpl('expr) } - def assertImpl(expr: Expr[Boolean])(given QuoteContext) = '{ + def assertImpl(expr: Expr[Boolean]) with QuoteContext = '{ def foo(): Unit = $expr foo() } diff --git a/tests/run-macros/quote-elide-prefix/quoted_1.scala b/tests/run-macros/quote-elide-prefix/quoted_1.scala index 4d59ade96458..94cff7c47598 100644 --- a/tests/run-macros/quote-elide-prefix/quoted_1.scala +++ b/tests/run-macros/quote-elide-prefix/quoted_1.scala @@ -5,5 +5,5 @@ object Macro { // By name StringContext is used to elide the prefix inline def (sc: => StringContext) ff (args: => Any*): String = ${ Macro.impl('sc, 'args) } - def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(given QuoteContext): Expr[String] = '{ $args.mkString } + def impl(sc: Expr[StringContext], args: Expr[Seq[Any]]) with QuoteContext : Expr[String] = '{ $args.mkString } } diff --git a/tests/run-macros/quote-force/quoted_1.scala b/tests/run-macros/quote-force/quoted_1.scala index bea6dafb3312..f93c8f26f86d 100644 --- a/tests/run-macros/quote-force/quoted_1.scala +++ b/tests/run-macros/quote-force/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} case class Location(owners: List[String]) @@ -7,7 +7,7 @@ object Location { implicit inline def location: Location = ${impl} - def impl(given QuoteContext): Expr[Location] = { + def impl with QuoteContext : Expr[Location] = { val list = List("a", "b", "c", "d", "e", "f") '{new Location(${list})} } diff --git a/tests/run-macros/quote-implicitMatch/Macro_1.scala b/tests/run-macros/quote-implicitMatch/Macro_1.scala index 180ab11ef5b6..707def9b0b8e 100644 --- a/tests/run-macros/quote-implicitMatch/Macro_1.scala +++ b/tests/run-macros/quote-implicitMatch/Macro_1.scala @@ -5,7 +5,7 @@ import scala.quoted.matching._ inline def f1[T]() = ${ f1Impl[T] } -def f1Impl[T: Type](given QuoteContext) = { +def f1Impl[T: Type] with QuoteContext = { summonExpr[Ordering[T]] match { case Some(ord) => '{ new TreeSet[T]()($ord) } case _ => '{ new HashSet[T] } @@ -17,7 +17,7 @@ class B inline def g = ${ gImpl } -def gImpl(given QuoteContext) = { +def gImpl with QuoteContext = { if (summonExpr[A].isDefined) '{ println("A") } else if (summonExpr[B].isDefined) '{ println("B") } else throw new MatchError("") diff --git a/tests/run-macros/quote-impure-by-name/quoted_1.scala b/tests/run-macros/quote-impure-by-name/quoted_1.scala index 61a750f33b86..ffa86ae1ef84 100644 --- a/tests/run-macros/quote-impure-by-name/quoted_1.scala +++ b/tests/run-macros/quote-impure-by-name/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} class Index[K, Keys](val index: String) extends AnyVal { @@ -11,7 +11,7 @@ object Index { implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${ succImpl[K, H, T]('prev) } - def succImpl[K: Type, H: Type, T: Type](prev: Expr[Index[K, T]])(given QuoteContext): Expr[Index[K, (H, T)]] = { + def succImpl[K: Type, H: Type, T: Type](prev: Expr[Index[K, T]]) with QuoteContext : Expr[Index[K, (H, T)]] = { val value = s"1 + {${prev.show}}" '{new Index(${value})} } diff --git a/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala b/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala index 4dbfccfce5c2..d2a8cd9652f9 100644 --- a/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala +++ b/tests/run-macros/quote-indexed-map-by-name/quoted_1.scala @@ -7,7 +7,7 @@ object Index { implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${succImpl('[K], '[H], '[T])} - def succImpl[K, H, T](k: Type[K], h: Type[H], t: Type[T])(given QuoteContext): Expr[Index[K, (H, T)]] = { + def succImpl[K, H, T](k: Type[K], h: Type[H], t: Type[T]) with QuoteContext : Expr[Index[K, (H, T)]] = { implicit val kk: Type[K] = k implicit val hh: Type[H] = h implicit val tt: Type[T] = t diff --git a/tests/run-macros/quote-inline-function/quoted_1.scala b/tests/run-macros/quote-inline-function/quoted_1.scala index 74ae1c224b72..302f6b1029dd 100644 --- a/tests/run-macros/quote-inline-function/quoted_1.scala +++ b/tests/run-macros/quote-inline-function/quoted_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def foreach1(start: Int, end: Int, f: Int => Unit): String = ${impl('start, 'end, 'f)} inline def foreach2(start: Int, end: Int, f: => Int => Unit): String = ${impl('start, 'end, 'f)} - def impl(start: Expr[Int], end: Expr[Int], f: Expr[Int => Unit])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def impl(start: Expr[Int], end: Expr[Int], f: Expr[Int => Unit]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} val res = '{ var i = $start val j = $end diff --git a/tests/run-macros/quote-matcher-power/Macro_1.scala b/tests/run-macros/quote-matcher-power/Macro_1.scala index e89ce3fc46f6..a32140b582dd 100644 --- a/tests/run-macros/quote-matcher-power/Macro_1.scala +++ b/tests/run-macros/quote-matcher-power/Macro_1.scala @@ -3,7 +3,7 @@ import scala.quoted.matching._ object Macros { - def power_s(x: Expr[Double], n: Int)(given QuoteContext): Expr[Double] = + def power_s(x: Expr[Double], n: Int) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 1) '{ $x * ${power_s(x, n - 1)} } else '{ val y = $x * $x; ${power_s('y, n / 2)} } @@ -16,7 +16,7 @@ object Macros { inline def rewrite(expr: => Double): Double = ${rewrite('expr)} // simple, 1-level, non-recursive rewriter for exponents - def rewrite(expr: Expr[Double])(given QuoteContext): Expr[Double] = { + def rewrite(expr: Expr[Double]) with QuoteContext : Expr[Double] = { val res = expr match { // product rule case '{ power2($a, $x) * power2($b, $y)} if a.matches(b) => '{ power2($a, $x + $y) } diff --git a/tests/run-macros/quote-matcher-runtime/quoted_1.scala b/tests/run-macros/quote-matcher-runtime/quoted_1.scala index 7087b7dc2a80..46e58ec531d4 100644 --- a/tests/run-macros/quote-matcher-runtime/quoted_1.scala +++ b/tests/run-macros/quote-matcher-runtime/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def matches[A, B](a: => A, b: => B): Unit = ${impl('a, 'b)} - private def impl[A, B](a: Expr[A], b: Expr[B])(given qctx: QuoteContext): Expr[Unit] = { + private def impl[A, B](a: Expr[A], b: Expr[B]) with (qctx: QuoteContext) : Expr[Unit] = { import qctx.tasty.{Bind => _, _} val res = scala.internal.quoted.Expr.unapply[Tuple, Tuple](a)(b, true, qctx).map { tup => diff --git a/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala index 280ded9f7554..cb1fd02c0a9a 100644 --- a/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(given QuoteContext): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) with QuoteContext : Expr[String] = { (self, args) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args1)) => val strParts = parts.map { case Const(str) => str.reverse } diff --git a/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala index 63f6fda3a37d..0d9bbaf24b10 100644 --- a/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def (self: => StringContext) S(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(given QuoteContext): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) with QuoteContext : Expr[String] = { self match { case '{ StringContext(${ConstSeq(parts)}: _*) } => val upprerParts: List[String] = parts.toList.map(_.toUpperCase) diff --git a/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala index 0f77a4427bd4..1308c771f4eb 100644 --- a/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(given QuoteContext): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) with QuoteContext : Expr[String] = { self match { case '{ StringContext(${ExprSeq(parts)}: _*) } => val parts2 = Expr.ofList(parts.map(x => '{ $x.reverse })) diff --git a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala index ec5c1a948dc1..bd8e6478fc30 100644 --- a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def lift[T](sym: Symantics[T])(a: => DSL): T = ${impl[T]('sym, 'a)} - private def impl[T: Type](sym: Expr[Symantics[T]], a: Expr[DSL])(given qctx: QuoteContext): Expr[T] = { + private def impl[T: Type](sym: Expr[Symantics[T]], a: Expr[DSL]) with (qctx: QuoteContext) : Expr[T] = { def lift(e: Expr[DSL]): Expr[T] = e match { @@ -20,7 +20,7 @@ object Macros { '{ $sym.times(${lift(x)}, ${lift(y)}) } case _ => - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} error("Expected explicit DSL", e.unseal.pos) '{ ??? } diff --git a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala index e9977c17290c..2edbf97cd4b3 100644 --- a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala @@ -9,7 +9,7 @@ object Macros { inline def liftAST(a: => DSL): ASTNum = ${impl(ASTNum, 'a)} - private def impl[T: Type](sym: Symantics[T], a: Expr[DSL])(given qctx: QuoteContext): Expr[T] = { + private def impl[T: Type](sym: Symantics[T], a: Expr[DSL]) with (qctx: QuoteContext) : Expr[T] = { def lift(e: Expr[DSL])(implicit env: Map[Int, Expr[T]]): Expr[T] = e match { @@ -30,7 +30,7 @@ object Macros { case '{ envVar(${Const(i)}) } => env(i) case _ => - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} error("Expected explicit DSL " + e.show, e.unseal.pos) ??? } @@ -44,7 +44,7 @@ object Macros { } ) case _ => - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} error("Expected explicit DSL => DSL " + e.show, e.unseal.pos) ??? } @@ -54,7 +54,7 @@ object Macros { } -def freshEnvVar()(given QuoteContext): (Int, Expr[DSL]) = { +def freshEnvVar() with QuoteContext : (Int, Expr[DSL]) = { v += 1 (v, '{envVar(${Expr(v)})}) } @@ -76,35 +76,35 @@ case class LitDSL(x: Int) extends DSL // trait Symantics[Num] { - def value(x: Int)(given QuoteContext): Expr[Num] - def plus(x: Expr[Num], y: Expr[Num])(given QuoteContext): Expr[Num] - def times(x: Expr[Num], y: Expr[Num])(given QuoteContext): Expr[Num] - def app(f: Expr[Num => Num], x: Expr[Num])(given QuoteContext): Expr[Num] - def lam(body: Expr[Num] => Expr[Num])(given QuoteContext): Expr[Num => Num] + def value(x: Int) with QuoteContext : Expr[Num] + def plus(x: Expr[Num], y: Expr[Num]) with QuoteContext : Expr[Num] + def times(x: Expr[Num], y: Expr[Num]) with QuoteContext : Expr[Num] + def app(f: Expr[Num => Num], x: Expr[Num]) with QuoteContext : Expr[Num] + def lam(body: Expr[Num] => Expr[Num]) with QuoteContext : Expr[Num => Num] } object StringNum extends Symantics[String] { - def value(x: Int)(given QuoteContext): Expr[String] = Expr(x.toString) - def plus(x: Expr[String], y: Expr[String])(given QuoteContext): Expr[String] = '{ s"${$x} + ${$y}" } // '{ x + " + " + y } - def times(x: Expr[String], y: Expr[String])(given QuoteContext): Expr[String] = '{ s"${$x} * ${$y}" } - def app(f: Expr[String => String], x: Expr[String])(given QuoteContext): Expr[String] = Expr.betaReduce(f)(x) - def lam(body: Expr[String] => Expr[String])(given QuoteContext): Expr[String => String] = '{ (x: String) => ${body('x)} } + def value(x: Int) with QuoteContext : Expr[String] = Expr(x.toString) + def plus(x: Expr[String], y: Expr[String]) with QuoteContext : Expr[String] = '{ s"${$x} + ${$y}" } // '{ x + " + " + y } + def times(x: Expr[String], y: Expr[String]) with QuoteContext : Expr[String] = '{ s"${$x} * ${$y}" } + def app(f: Expr[String => String], x: Expr[String]) with QuoteContext : Expr[String] = Expr.betaReduce(f)(x) + def lam(body: Expr[String] => Expr[String]) with QuoteContext : Expr[String => String] = '{ (x: String) => ${body('x)} } } object ComputeNum extends Symantics[Int] { - def value(x: Int)(given QuoteContext): Expr[Int] = Expr(x) - def plus(x: Expr[Int], y: Expr[Int])(given QuoteContext): Expr[Int] = '{ $x + $y } - def times(x: Expr[Int], y: Expr[Int])(given QuoteContext): Expr[Int] = '{ $x * $y } - def app(f: Expr[Int => Int], x: Expr[Int])(given QuoteContext): Expr[Int] = '{ $f($x) } - def lam(body: Expr[Int] => Expr[Int])(given QuoteContext): Expr[Int => Int] = '{ (x: Int) => ${body('x)} } + def value(x: Int) with QuoteContext : Expr[Int] = Expr(x) + def plus(x: Expr[Int], y: Expr[Int]) with QuoteContext : Expr[Int] = '{ $x + $y } + def times(x: Expr[Int], y: Expr[Int]) with QuoteContext : Expr[Int] = '{ $x * $y } + def app(f: Expr[Int => Int], x: Expr[Int]) with QuoteContext : Expr[Int] = '{ $f($x) } + def lam(body: Expr[Int] => Expr[Int]) with QuoteContext : Expr[Int => Int] = '{ (x: Int) => ${body('x)} } } object ASTNum extends Symantics[ASTNum] { - def value(x: Int)(given QuoteContext): Expr[ASTNum] = '{ LitAST(${Expr(x)}) } - def plus(x: Expr[ASTNum], y: Expr[ASTNum])(given QuoteContext): Expr[ASTNum] = '{ PlusAST($x, $y) } - def times(x: Expr[ASTNum], y: Expr[ASTNum])(given QuoteContext): Expr[ASTNum] = '{ TimesAST($x, $y) } - def app(f: Expr[ASTNum => ASTNum], x: Expr[ASTNum])(given QuoteContext): Expr[ASTNum] = '{ AppAST($f, $x) } - def lam(body: Expr[ASTNum] => Expr[ASTNum])(given QuoteContext): Expr[ASTNum => ASTNum] = '{ (x: ASTNum) => ${body('x)} } + def value(x: Int) with QuoteContext : Expr[ASTNum] = '{ LitAST(${Expr(x)}) } + def plus(x: Expr[ASTNum], y: Expr[ASTNum]) with QuoteContext : Expr[ASTNum] = '{ PlusAST($x, $y) } + def times(x: Expr[ASTNum], y: Expr[ASTNum]) with QuoteContext : Expr[ASTNum] = '{ TimesAST($x, $y) } + def app(f: Expr[ASTNum => ASTNum], x: Expr[ASTNum]) with QuoteContext : Expr[ASTNum] = '{ AppAST($f, $x) } + def lam(body: Expr[ASTNum] => Expr[ASTNum]) with QuoteContext : Expr[ASTNum => ASTNum] = '{ (x: ASTNum) => ${body('x)} } } trait ASTNum diff --git a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala index ea10cf1a8b1c..dceeb303ce30 100644 --- a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala @@ -7,17 +7,17 @@ object Macros { inline def lift[R[_]](sym: Symantics { type Repr = R })(a: => Int): R[Int] = ${impl('sym, 'a)} - private def impl[R[_]: Type](sym: Expr[Symantics { type Repr[X] = R[X] }], expr: Expr[Int])(given QuoteContext): Expr[R[Int]] = { + private def impl[R[_]: Type](sym: Expr[Symantics { type Repr[X] = R[X] }], expr: Expr[Int]) with QuoteContext : Expr[R[Int]] = { type Env = Map[Int, Any] - given ev0 : Env = Map.empty + given ev0 as Env = Map.empty - def envWith[T](id: Int, ref: Expr[R[T]])(given env: Env): Env = + def envWith[T](id: Int, ref: Expr[R[T]]) with (env: Env) : Env = env.updated(id, ref) object FromEnv { - def unapply[T](e: Expr[Any])(given env: Env): Option[Expr[R[T]]] = + def unapply[T](e: Expr[Any]) with (env: Env) : Option[Expr[R[T]]] = e match case '{envVar[$t](${Const(id)})} => env.get(id).asInstanceOf[Option[Expr[R[T]]]] // We can only add binds that have the same type as the refs @@ -25,7 +25,7 @@ object Macros { None } - def lift[T: Type](e: Expr[T])(given env: Env): Expr[R[T]] = ((e: Expr[Any]) match { + def lift[T: Type](e: Expr[T]) with (env: Env) : Expr[R[T]] = ((e: Expr[Any]) match { case Const(e: Int) => '{ $sym.int(${Expr(e)}).asInstanceOf[R[T]] } case Const(e: Boolean) => '{ $sym.bool(${Expr(e)}).asInstanceOf[R[T]] } @@ -47,17 +47,17 @@ object Macros { case '{ (x0: Int) => ($bodyFn: Int => Any)(x0) } => val (i, nEnvVar) = freshEnvVar[Int]() val body2 = Expr.open(bodyFn) { (body1, close) => close(body1)(nEnvVar) } - '{ $sym.lam((x: R[Int]) => ${given Env = envWith(i, 'x)(given env); lift(body2)}).asInstanceOf[R[T]] } + '{ $sym.lam((x: R[Int]) => ${given Env = envWith(i, 'x).with(env); lift(body2)}).asInstanceOf[R[T]] } case '{ (x0: Boolean) => ($bodyFn: Boolean => Any)(x0) } => val (i, nEnvVar) = freshEnvVar[Boolean]() val body2 = Expr.open(bodyFn) { (body1, close) => close(body1)(nEnvVar) } - '{ $sym.lam((x: R[Boolean]) => ${given Env = envWith(i, 'x)(given env); lift(body2)}).asInstanceOf[R[T]] } + '{ $sym.lam((x: R[Boolean]) => ${given Env = envWith(i, 'x).with(env); lift(body2)}).asInstanceOf[R[T]] } case '{ (x0: Int => Int) => ($bodyFn: (Int => Int) => Any)(x0) } => val (i, nEnvVar) = freshEnvVar[Int => Int]() val body2 = Expr.open(bodyFn) { (body1, close) => close(body1)(nEnvVar) } - '{ $sym.lam((x: R[Int => Int]) => ${given Env = envWith(i, 'x)(given env); lift(body2)}).asInstanceOf[R[T]] } + '{ $sym.lam((x: R[Int => Int]) => ${given Env = envWith(i, 'x).with(env); lift(body2)}).asInstanceOf[R[T]] } case '{ Symantics.fix[$t, $u]($f) } => '{ $sym.fix[$t, $u]((x: R[$t => $u]) => $sym.app(${lift(f)}, x)).asInstanceOf[R[T]] } @@ -75,7 +75,7 @@ object Macros { } -def freshEnvVar[T: Type]()(given QuoteContext): (Int, Expr[T]) = { +def freshEnvVar[T: Type]() with QuoteContext : (Int, Expr[T]) = { v += 1 (v, '{envVar[T](${Expr(v)})}) } diff --git a/tests/run-macros/quote-matcher-type-bind/Macro_1.scala b/tests/run-macros/quote-matcher-type-bind/Macro_1.scala index c85850b908e1..d3ed25fffb0c 100644 --- a/tests/run-macros/quote-matcher-type-bind/Macro_1.scala +++ b/tests/run-macros/quote-matcher-type-bind/Macro_1.scala @@ -5,7 +5,7 @@ object Macros { inline def swapFandG(x: => Unit): Unit = ${impl('x)} - private def impl(x: Expr[Unit])(given QuoteContext): Expr[Unit] = { + private def impl(x: Expr[Unit]) with QuoteContext : Expr[Unit] = { x match { case '{ DSL.f[$t]($x) } => '{ DSL.g[$t]($x) } case '{ DSL.g[$t]($x) } => '{ DSL.f[$t]($x) } diff --git a/tests/run-macros/quote-matching-open/Macro_1.scala b/tests/run-macros/quote-matching-open/Macro_1.scala index a39ccf9a592e..d3b43cf9179d 100644 --- a/tests/run-macros/quote-matching-open/Macro_1.scala +++ b/tests/run-macros/quote-matching-open/Macro_1.scala @@ -4,7 +4,7 @@ object Macro { inline def openTest(x: => Any): Any = ${ Macro.impl('x) } - def impl(x: Expr[Any])(given QuoteContext): Expr[Any] = { + def impl(x: Expr[Any]) with QuoteContext : Expr[Any] = { x match { case '{ (x: Int) => ($body: Int => Int)(x) } => Expr.open(body) { (body, close) => close(body)(Expr(2)) } case '{ (x1: Int, x2: Int) => ($body: (Int, Int) => Int)(x1, x2) } => Expr.open(body) { (body, close) => close(body)(Expr(2), Expr(3)) } diff --git a/tests/run-macros/quote-matching-optimize-1/Macro_1.scala b/tests/run-macros/quote-matching-optimize-1/Macro_1.scala index 204e6c621cf4..921d573aab0e 100644 --- a/tests/run-macros/quote-matching-optimize-1/Macro_1.scala +++ b/tests/run-macros/quote-matching-optimize-1/Macro_1.scala @@ -1,11 +1,11 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macro { inline def optimize[T](x: => T): Any = ${ Macro.impl('x) } - def impl[T: Type](x: Expr[T])(given QuoteContext): Expr[Any] = { + def impl[T: Type](x: Expr[T]) with QuoteContext : Expr[Any] = { def optimize(x: Expr[Any]): Expr[Any] = x match { case '{ type $t; ($ls: List[`$t`]).filter($f).filter($g) } => diff --git a/tests/run-macros/quote-matching-optimize-2/Macro_1.scala b/tests/run-macros/quote-matching-optimize-2/Macro_1.scala index 98dacda3df8d..2f37e4630c49 100644 --- a/tests/run-macros/quote-matching-optimize-2/Macro_1.scala +++ b/tests/run-macros/quote-matching-optimize-2/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.tasty.Reflection @@ -7,7 +7,7 @@ object Macro { inline def optimize[T](x: => T): Any = ${ Macro.impl('x) } - def impl[T: Type](x: Expr[T])(given QuoteContext): Expr[Any] = { + def impl[T: Type](x: Expr[T]) with QuoteContext : Expr[Any] = { def optimize(x: Expr[Any]): Expr[Any] = x match { case '{ ($ls: List[$t]).filter($f).filter($g) } => diff --git a/tests/run-macros/quote-matching-optimize-3/Macro_1.scala b/tests/run-macros/quote-matching-optimize-3/Macro_1.scala index 0736dad4e1b7..d69493310e90 100644 --- a/tests/run-macros/quote-matching-optimize-3/Macro_1.scala +++ b/tests/run-macros/quote-matching-optimize-3/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.tasty.Reflection @@ -7,7 +7,7 @@ object Macro { inline def optimize[T](x: => T): Any = ${ Macro.impl('x) } - def impl[T: Type](x: Expr[T])(given QuoteContext): Expr[Any] = { + def impl[T: Type](x: Expr[T]) with QuoteContext : Expr[Any] = { def optimize(x: Expr[Any]): Expr[Any] = x match { case '{ ($ls: List[$t]).filter($f).filter($g) } => diff --git a/tests/run-macros/quote-sep-comp-2/Macro_1.scala b/tests/run-macros/quote-sep-comp-2/Macro_1.scala index ab14867e794d..e37641646299 100644 --- a/tests/run-macros/quote-sep-comp-2/Macro_1.scala +++ b/tests/run-macros/quote-sep-comp-2/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macros { - def assertImpl(expr: Expr[Boolean])(given QuoteContext) = '{ println($expr) } + def assertImpl(expr: Expr[Boolean]) with QuoteContext = '{ println($expr) } } diff --git a/tests/run-macros/quote-sep-comp/Macro_1.scala b/tests/run-macros/quote-sep-comp/Macro_1.scala index a1d701c4f9b4..f709ac0a532c 100644 --- a/tests/run-macros/quote-sep-comp/Macro_1.scala +++ b/tests/run-macros/quote-sep-comp/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macros { inline def assert2(expr: => Boolean): Unit = ${ assertImpl('expr) } - def assertImpl(expr: Expr[Boolean])(given QuoteContext) = '{ println($expr) } + def assertImpl(expr: Expr[Boolean]) with QuoteContext = '{ println($expr) } } diff --git a/tests/run-macros/quote-simple-macro/quoted_1.scala b/tests/run-macros/quote-simple-macro/quoted_1.scala index cba8f5af2be3..580b2b7a8e65 100644 --- a/tests/run-macros/quote-simple-macro/quoted_1.scala +++ b/tests/run-macros/quote-simple-macro/quoted_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def foo(inline i: Int, dummy: Int, j: Int): Int = ${ bar(i, 'j) } - def bar(x: Int, y: Expr[Int])(given QuoteContext): Expr[Int] = '{ ${x} + $y } + def bar(x: Int, y: Expr[Int]) with QuoteContext : Expr[Int] = '{ ${x} + $y } } diff --git a/tests/run-macros/quote-toExprOfSeq/Macro_1.scala b/tests/run-macros/quote-toExprOfSeq/Macro_1.scala index 2e70da6b93df..88b5a356002a 100644 --- a/tests/run-macros/quote-toExprOfSeq/Macro_1.scala +++ b/tests/run-macros/quote-toExprOfSeq/Macro_1.scala @@ -1,8 +1,8 @@ import scala.quoted._ -import scala.quoted.given +import scala.quoted.{given _} inline def seq = ${fooImpl} -def fooImpl(given qctx: QuoteContext) = { +def fooImpl with (qctx: QuoteContext) = { Expr.ofSeq(List('{1}, '{2}, '{3})) } diff --git a/tests/run-macros/quote-toExprOfTuple/Macro_1.scala b/tests/run-macros/quote-toExprOfTuple/Macro_1.scala index 58df1397e20e..0dd47ec8d38a 100644 --- a/tests/run-macros/quote-toExprOfTuple/Macro_1.scala +++ b/tests/run-macros/quote-toExprOfTuple/Macro_1.scala @@ -3,8 +3,8 @@ import scala.quoted._ object Macro { inline def t2[T0, T1](t0: T0, t1: T1): (T0, T1) = ${ impl2('{t0}, '{t1}) } - def impl2[T0: Type, T1: Type](t0: Expr[T0], t1: Expr[T1])(given qctx: QuoteContext): Expr[(T0, T1)] = { - import qctx.tasty.{_, given} + def impl2[T0: Type, T1: Type](t0: Expr[T0], t1: Expr[T1]) with (qctx: QuoteContext) : Expr[(T0, T1)] = { + import qctx.tasty.{_, given _} import util._ val seq = List(t0, t1) diff --git a/tests/run-macros/quote-type-matcher-2/quoted_1.scala b/tests/run-macros/quote-type-matcher-2/quoted_1.scala index 179d4fdaed65..e3360eef133c 100644 --- a/tests/run-macros/quote-type-matcher-2/quoted_1.scala +++ b/tests/run-macros/quote-type-matcher-2/quoted_1.scala @@ -4,7 +4,7 @@ object Macros { inline def lift[A]: String = ${ matchesExpr('[A]) } - private def matchesExpr(tp: Type[_])(given QuoteContext): Expr[String] = { + private def matchesExpr(tp: Type[_]) with QuoteContext : Expr[String] = { def lift(tp: Type[_]): String = tp match { case '[Int] => "%Int%" case '[List[$t]] => s"%List[${lift(t)}]%" diff --git a/tests/run-macros/quote-type-matcher/quoted_1.scala b/tests/run-macros/quote-type-matcher/quoted_1.scala index e536120306cf..23daadda021c 100644 --- a/tests/run-macros/quote-type-matcher/quoted_1.scala +++ b/tests/run-macros/quote-type-matcher/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def matches[A, B]: Unit = ${ matchesExpr('[A], '[B]) } - private def matchesExpr[A, B](a: Type[A], b: Type[B])(given qctx: QuoteContext): Expr[Unit] = { + private def matchesExpr[A, B](a: Type[A], b: Type[B]) with (qctx: QuoteContext) : Expr[Unit] = { import qctx.tasty.{Bind => _, _} val res = scala.internal.quoted.Type.unapply[Tuple, Tuple](a)(b, true, qctx).map { tup => diff --git a/tests/run-macros/quote-unrolled-foreach/quoted_1.scala b/tests/run-macros/quote-unrolled-foreach/quoted_1.scala index 8795c8d7247a..55dc800d9037 100644 --- a/tests/run-macros/quote-unrolled-foreach/quoted_1.scala +++ b/tests/run-macros/quote-unrolled-foreach/quoted_1.scala @@ -1,13 +1,13 @@ import scala.annotation.tailrec import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macro { inline def unrolledForeach(inline unrollSize: Int, seq: Array[Int])(f: => Int => Unit): Unit = // or f: Int => Unit ${unrolledForeachImpl(unrollSize, 'seq, 'f)} - private def unrolledForeachImpl(unrollSize: Int, seq: Expr[Array[Int]], f: Expr[Int => Unit])(given QuoteContext): Expr[Unit] = '{ + private def unrolledForeachImpl(unrollSize: Int, seq: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = $seq.length assert(size % (${unrollSize}) == 0) // for simplicity of the implementation var i = 0 diff --git a/tests/run-macros/quote-whitebox/Macro_1.scala b/tests/run-macros/quote-whitebox/Macro_1.scala index fe307b1b8d4e..8bec03ffb00d 100644 --- a/tests/run-macros/quote-whitebox/Macro_1.scala +++ b/tests/run-macros/quote-whitebox/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl(str) } - def defaultOfImpl(str: String)(given QuoteContext): Expr[Any] = str match { + def defaultOfImpl(str: String) with QuoteContext : Expr[Any] = str match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/run-macros/quoted-expr-block/quoted_1.scala b/tests/run-macros/quoted-expr-block/quoted_1.scala index 7e1f89c84fec..8625741c4b66 100644 --- a/tests/run-macros/quoted-expr-block/quoted_1.scala +++ b/tests/run-macros/quoted-expr-block/quoted_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ inline def replicate(inline times: Int, code: => Any) = ${replicateImpl(times, 'code)} -private def replicateImpl(times: Int, code: Expr[Any])(given QuoteContext) = { +private def replicateImpl(times: Int, code: Expr[Any]) with QuoteContext = { @annotation.tailrec def loop(n: Int, accum: List[Expr[Any]]): List[Expr[Any]] = if (n > 0) loop(n - 1, code :: accum) else accum Expr.block(loop(times, Nil), '{}) diff --git a/tests/run-macros/quoted-matching-docs-2/Macro_1.scala b/tests/run-macros/quoted-matching-docs-2/Macro_1.scala index 811936b9cb0e..6f86dc03e860 100644 --- a/tests/run-macros/quoted-matching-docs-2/Macro_1.scala +++ b/tests/run-macros/quoted-matching-docs-2/Macro_1.scala @@ -6,10 +6,10 @@ def sum(args: =>Int*): Int = args.sum inline def showOptimize(arg: Int): String = ${ showOptimizeExpr('arg) } inline def optimize(arg: Int): Int = ${ optimizeExpr('arg) } -private def showOptimizeExpr(body: Expr[Int])(given QuoteContext): Expr[String] = +private def showOptimizeExpr(body: Expr[Int]) with QuoteContext : Expr[String] = Expr(optimizeExpr(body).show) -private def optimizeExpr(body: Expr[Int])(given QuoteContext): Expr[Int] = body match { +private def optimizeExpr(body: Expr[Int]) with QuoteContext : Expr[Int] = body match { // Match a call to sum without any arguments case '{ sum() } => Expr(0) // Match a call to sum with an argument $n of type Int. n will be the Expr[Int] representing the argument. @@ -19,7 +19,7 @@ private def optimizeExpr(body: Expr[Int])(given QuoteContext): Expr[Int] = body case body => body } -private def sumExpr(args1: Seq[Expr[Int]])(given QuoteContext): Expr[Int] = { +private def sumExpr(args1: Seq[Expr[Int]]) with QuoteContext : Expr[Int] = { def flatSumArgs(arg: Expr[Int]): Seq[Expr[Int]] = arg match { case '{ sum(${ExprSeq(subArgs)}: _*) } => subArgs.flatMap(flatSumArgs) case arg => Seq(arg) diff --git a/tests/run-macros/quoted-matching-docs/Macro_1.scala b/tests/run-macros/quoted-matching-docs/Macro_1.scala index 480e8240d934..e68d04b281dd 100644 --- a/tests/run-macros/quoted-matching-docs/Macro_1.scala +++ b/tests/run-macros/quoted-matching-docs/Macro_1.scala @@ -5,11 +5,11 @@ inline def sum(args: Int*): Int = ${ sumExpr('args) } inline def sumShow(args: Int*): String = ${ sumExprShow('args) } -private def sumExprShow(argsExpr: Expr[Seq[Int]])(given QuoteContext): Expr[String] = +private def sumExprShow(argsExpr: Expr[Seq[Int]]) with QuoteContext : Expr[String] = Expr(sumExpr(argsExpr).show) -private def sumExpr(argsExpr: Expr[Seq[Int]])(given qctx: QuoteContext): Expr[Int] = { - import qctx.tasty.{given, _} +private def sumExpr(argsExpr: Expr[Seq[Int]]) with (qctx: QuoteContext) : Expr[Int] = { + import qctx.tasty.{given _, _} argsExpr.underlyingArgument match { case ConstSeq(args) => // args is of type Seq[Int] Expr(args.sum) // precompute result of sum diff --git a/tests/run-macros/quoted-pattern-open-expr/Macro_1.scala b/tests/run-macros/quoted-pattern-open-expr/Macro_1.scala index 8880f8398fb2..2bc1b3f8eddb 100644 --- a/tests/run-macros/quoted-pattern-open-expr/Macro_1.scala +++ b/tests/run-macros/quoted-pattern-open-expr/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ inline def test(e: Int): String = ${testExpr('e)} -private def testExpr(e: Expr[Int])(given QuoteContext): Expr[String] = { +private def testExpr(e: Expr[Int]) with QuoteContext : Expr[String] = { e match { case '{ val y: Int = 4; $body } => Expr("Matched closed\n" + body.show) case '{ val y: Int = 4; ($body: Int => Int)(y) } => Expr("Matched open\n" + body.show) diff --git a/tests/run-macros/quoted-pattern-type/Macro_1.scala b/tests/run-macros/quoted-pattern-type/Macro_1.scala index 493eaf923437..826f059f491e 100644 --- a/tests/run-macros/quoted-pattern-type/Macro_1.scala +++ b/tests/run-macros/quoted-pattern-type/Macro_1.scala @@ -4,7 +4,7 @@ object Lib { inline def foo[T](arg: => T): T = ${ impl('arg) } - private def impl[T: Type](arg: Expr[T])(given QuoteContext): Expr[T] = { + private def impl[T: Type](arg: Expr[T]) with QuoteContext : Expr[T] = { arg match { case e @ '{ $x: Boolean } => '{ println("Boolean: " + $e); $e } case e @ '{ $x: Int } => '{ println("Int: " + $x); $x } diff --git a/tests/run-macros/refined-selectable-macro/Macro_1.scala b/tests/run-macros/refined-selectable-macro/Macro_1.scala index 86e3d4dad54a..8f229701afcf 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_1.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_1.scala @@ -11,8 +11,8 @@ object Macro { inline def fromTuple[T <: Tuple](s: T) <: Any = ${ fromTupleImpl('s, '{ (x: Array[(String, Any)]) => fromUntypedTuple(x: _*) } ) } } - private def toTupleImpl(s: Expr[Selectable])(given qctx:QuoteContext): Expr[Tuple] = { - import qctx.tasty.{given, _} + private def toTupleImpl(s: Expr[Selectable]) with (qctx:QuoteContext) : Expr[Tuple] = { + import qctx.tasty.{given _, _} val repr = s.unseal.tpe.widenTermRefExpr.dealias @@ -45,8 +45,8 @@ object Macro { Expr.ofTuple(ret) } - private def fromTupleImpl[T: Type](s: Expr[Tuple], newRecord: Expr[Array[(String, Any)] => T])(given qctx:QuoteContext): Expr[Any] = { - import qctx.tasty.{given, _} + private def fromTupleImpl[T: Type](s: Expr[Tuple], newRecord: Expr[Array[(String, Any)] => T]) with (qctx:QuoteContext) : Expr[Any] = { + import qctx.tasty.{given _, _} val repr = s.unseal.tpe.widenTermRefExpr.dealias diff --git a/tests/run-macros/refined-selectable-macro/Macro_2.scala b/tests/run-macros/refined-selectable-macro/Macro_2.scala index 533208230d29..40154c1c7a98 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_2.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_2.scala @@ -16,7 +16,7 @@ object Macro2 { inline def apply[R <: Record](elems: (String, Any)*) : R = ${ applyImpl('elems, '[R]) } - def applyImpl[R <: Record: Type](elems: Expr[Seq[(String, Any)]], ev: Type[R])(given qctx: QuoteContext) = { + def applyImpl[R <: Record: Type](elems: Expr[Seq[(String, Any)]], ev: Type[R]) with (qctx: QuoteContext) = { '{ new Record($elems:_*).asInstanceOf[$ev] } } diff --git a/tests/run-macros/reflect-dsl/assert_1.scala b/tests/run-macros/reflect-dsl/assert_1.scala index 5f8dd23f64fc..218b5484af93 100644 --- a/tests/run-macros/reflect-dsl/assert_1.scala +++ b/tests/run-macros/reflect-dsl/assert_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ def isImplicitMethodType(tp: Type): Boolean = tp match diff --git a/tests/run-macros/reflect-inline/assert_1.scala b/tests/run-macros/reflect-inline/assert_1.scala index d408236f5fe2..3ec70bcacaf0 100644 --- a/tests/run-macros/reflect-inline/assert_1.scala +++ b/tests/run-macros/reflect-inline/assert_1.scala @@ -4,13 +4,13 @@ object api { inline def (inline x: String) stripMargin: String = ${ stripImpl(x) } - private def stripImpl(x: String)(given qctx: QuoteContext): Expr[String] = + private def stripImpl(x: String) with (qctx: QuoteContext) : Expr[String] = Expr(augmentString(x).stripMargin) inline def typeChecks(inline x: String): Boolean = ${ typeChecksImpl(scala.compiletime.testing.typeChecks(x)) } - private def typeChecksImpl(b: Boolean)(given qctx: QuoteContext): Expr[Boolean] = { + private def typeChecksImpl(b: Boolean) with (qctx: QuoteContext) : Expr[Boolean] = { if (b) Expr(true) else Expr(false) } } diff --git a/tests/run-macros/reflect-lambda/assert_1.scala b/tests/run-macros/reflect-lambda/assert_1.scala index 6743eb412b57..c39768add34d 100644 --- a/tests/run-macros/reflect-lambda/assert_1.scala +++ b/tests/run-macros/reflect-lambda/assert_1.scala @@ -4,8 +4,8 @@ object lib { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ cond.unseal.underlyingArgument match { diff --git a/tests/run-macros/reflect-pos-fun/assert_1.scala b/tests/run-macros/reflect-pos-fun/assert_1.scala index c6902daafd46..b89a7176f2b1 100644 --- a/tests/run-macros/reflect-pos-fun/assert_1.scala +++ b/tests/run-macros/reflect-pos-fun/assert_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition) } - def assertImpl(cond: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ cond.unseal.underlyingArgument match { diff --git a/tests/run-macros/reflect-select-constructor/assert_1.scala b/tests/run-macros/reflect-select-constructor/assert_1.scala index 8738d4694206..566e4976321d 100644 --- a/tests/run-macros/reflect-select-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-constructor/assert_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ def isImplicitMethodType(tp: Type): Boolean = tp match diff --git a/tests/run-macros/reflect-select-copy-2/assert_1.scala b/tests/run-macros/reflect-select-copy-2/assert_1.scala index 4293a6a29d1a..32f35038ed9b 100644 --- a/tests/run-macros/reflect-select-copy-2/assert_1.scala +++ b/tests/run-macros/reflect-select-copy-2/assert_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ def isImplicitMethodType(tp: Type): Boolean = tp match diff --git a/tests/run-macros/reflect-select-copy/assert_1.scala b/tests/run-macros/reflect-select-copy/assert_1.scala index 0a5ed60b5149..66a724487def 100644 --- a/tests/run-macros/reflect-select-copy/assert_1.scala +++ b/tests/run-macros/reflect-select-copy/assert_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} cond.unseal.underlyingArgument match { case Apply(select @ Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala index e8e8936ae0de..f62523b6f091 100644 --- a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ def isImplicitMethodType(tp: Type): Boolean = tp match diff --git a/tests/run-macros/reflect-select-value-class/assert_1.scala b/tests/run-macros/reflect-select-value-class/assert_1.scala index 8738d4694206..566e4976321d 100644 --- a/tests/run-macros/reflect-select-value-class/assert_1.scala +++ b/tests/run-macros/reflect-select-value-class/assert_1.scala @@ -4,8 +4,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} import util._ def isImplicitMethodType(tp: Type): Boolean = tp match diff --git a/tests/run-macros/reflect-typeChecks/assert_1.scala b/tests/run-macros/reflect-typeChecks/assert_1.scala index 13b0a25ae8a8..f19d08e397e8 100644 --- a/tests/run-macros/reflect-typeChecks/assert_1.scala +++ b/tests/run-macros/reflect-typeChecks/assert_1.scala @@ -5,7 +5,7 @@ object scalatest { inline def assertCompile(inline code: String): Unit = ${ assertImpl(code, compiletime.testing.typeChecks(code), true) } inline def assertNotCompile(inline code: String): Unit = ${ assertImpl(code, compiletime.testing.typeChecks(code), false) } - def assertImpl(code: String, actual: Boolean, expect: Boolean)(given qctx: QuoteContext): Expr[Unit] = { + def assertImpl(code: String, actual: Boolean, expect: Boolean) with (qctx: QuoteContext) : Expr[Unit] = { '{ assert(${Expr(expect)} == ${Expr(actual)}) } } } diff --git a/tests/run-macros/requiredSymbols/Macro_1.scala b/tests/run-macros/requiredSymbols/Macro_1.scala index ec92c43f2ffe..6e6dd9d92170 100644 --- a/tests/run-macros/requiredSymbols/Macro_1.scala +++ b/tests/run-macros/requiredSymbols/Macro_1.scala @@ -2,8 +2,8 @@ import scala.quoted._ object Macro { inline def foo: String = ${ fooImpl } - def fooImpl(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{given, _} + def fooImpl with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{given _, _} val list = List( rootContext.requiredPackage("java"), rootContext.requiredPackage("java.lang"), diff --git a/tests/run-macros/string-context-implicits/Macro_1.scala b/tests/run-macros/string-context-implicits/Macro_1.scala index 3705d49f38b0..f8dd6315b915 100644 --- a/tests/run-macros/string-context-implicits/Macro_1.scala +++ b/tests/run-macros/string-context-implicits/Macro_1.scala @@ -3,13 +3,13 @@ import scala.quoted.matching._ inline def (sc: StringContext) showMe(args: =>Any*): String = ${ showMeExpr('sc, 'args) } -private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = { +private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = { argsExpr match { case ExprSeq(argExprs) => val argShowedExprs = argExprs.map { case '{ $arg: $tp } => val showTp = '[Show[$tp]] - summonExpr(given showTp) match { + summonExpr.with(showTp) match { case Some(showExpr) => '{ $showExpr.show($arg) } case None => qctx.error(s"could not find implicit for ${showTp.show}", arg); '{???} } diff --git a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala index b97e966eef3f..1f99faecf950 100644 --- a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala +++ b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def inspect[T](x: T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = x.unseal '{ println() diff --git a/tests/run-macros/tasty-custom-show/quoted_1.scala b/tests/run-macros/tasty-custom-show/quoted_1.scala index 361e7ffa1f82..ebcd20a8e7bb 100644 --- a/tests/run-macros/tasty-custom-show/quoted_1.scala +++ b/tests/run-macros/tasty-custom-show/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { @@ -7,8 +7,8 @@ object Macros { implicit inline def printOwners[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val buff = new StringBuilder @@ -38,10 +38,10 @@ object Macros { '{print(${buff.result()})} } - def dummyShow(given qctx: QuoteContext): scala.tasty.reflect.Printer[qctx.tasty.type] = { + def dummyShow with (qctx: QuoteContext) : scala.tasty.reflect.Printer[qctx.tasty.type] = { new scala.tasty.reflect.Printer { val tasty = qctx.tasty - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} def showTree(tree: Tree)(implicit ctx: Context): String = "Tree" def showTypeOrBounds(tpe: TypeOrBounds)(implicit ctx: Context): String = "TypeOrBounds" def showConstant(const: Constant)(implicit ctx: Context): String = "Constant" diff --git a/tests/run-macros/tasty-dealias/quoted_1.scala b/tests/run-macros/tasty-dealias/quoted_1.scala index 86a6a05cf03f..8cce8eaee86b 100644 --- a/tests/run-macros/tasty-dealias/quoted_1.scala +++ b/tests/run-macros/tasty-dealias/quoted_1.scala @@ -4,8 +4,8 @@ object Macros { inline def dealias[T]: String = ${ impl('[T]) } - def impl[T](x: quoted.Type[T])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + def impl[T](x: quoted.Type[T]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} Expr(x.unseal.tpe.dealias.show) } } diff --git a/tests/run-macros/tasty-definitions-1/quoted_1.scala b/tests/run-macros/tasty-definitions-1/quoted_1.scala index 9906b5790142..234c5c50e7e9 100644 --- a/tests/run-macros/tasty-definitions-1/quoted_1.scala +++ b/tests/run-macros/tasty-definitions-1/quoted_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def testDefinitions(): Unit = ${testDefinitionsImpl} - def testDefinitionsImpl(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def testDefinitionsImpl with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val buff = List.newBuilder[String] def printout(x: => String): Unit = { diff --git a/tests/run-macros/tasty-eval/quoted_1.scala b/tests/run-macros/tasty-eval/quoted_1.scala index 6ab7b509ae9c..835ed79b5717 100644 --- a/tests/run-macros/tasty-eval/quoted_1.scala +++ b/tests/run-macros/tasty-eval/quoted_1.scala @@ -1,24 +1,24 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { implicit inline def foo(i: Int): String = ${ impl('i) } - def impl(i: Expr[Int])(given QuoteContext): Expr[String] = { + def impl(i: Expr[Int]) with QuoteContext : Expr[String] = { value(i).toString } inline implicit def value[X](e: Expr[X])(implicit qctx: QuoteContext, ev: Valuable[X]): Option[X] = ev.value(e) trait Valuable[X] { - def value(e: Expr[X])(given QuoteContext): Option[X] + def value(e: Expr[X]) with QuoteContext : Option[X] } implicit def intIsEvalable: Valuable[Int] = new Valuable[Int] { - override def value(e: Expr[Int])(given qctx: QuoteContext): Option[Int] = { - import qctx.tasty.{_, given} + override def value(e: Expr[Int]) with (qctx: QuoteContext) : Option[Int] = { + import qctx.tasty.{_, given _} e.unseal.tpe match { case pre: TermRef if pre.termSymbol.isValDef => diff --git a/tests/run-macros/tasty-extractors-1/quoted_1.scala b/tests/run-macros/tasty-extractors-1/quoted_1.scala index 87b1a3452a08..5e90067b432b 100644 --- a/tests/run-macros/tasty-extractors-1/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-1/quoted_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { implicit inline def printTree[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = x.unseal val treeStr = tree.showExtractors diff --git a/tests/run-macros/tasty-extractors-2/quoted_1.scala b/tests/run-macros/tasty-extractors-2/quoted_1.scala index e4683a928b28..b1010f6fff1d 100644 --- a/tests/run-macros/tasty-extractors-2/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-2/quoted_1.scala @@ -1,13 +1,13 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { implicit inline def printTree[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = x.unseal diff --git a/tests/run-macros/tasty-extractors-3/quoted_1.scala b/tests/run-macros/tasty-extractors-3/quoted_1.scala index 47f046ef8763..2dbbfd65b025 100644 --- a/tests/run-macros/tasty-extractors-3/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-3/quoted_1.scala @@ -1,14 +1,14 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { implicit inline def printTypes[T](x: => T): Unit = ${impl('x)} - def impl[T](x: Expr[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Expr[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val buff = new StringBuilder val traverser = new TreeTraverser { diff --git a/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala b/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala index fb10671b2add..d0b70d9312b9 100644 --- a/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.quoted.matching._ @@ -7,7 +7,7 @@ object Macros { implicit inline def testMacro: Unit = ${impl} - def impl(given QuoteContext): Expr[Unit] = { + def impl with QuoteContext : Expr[Unit] = { val buff = new StringBuilder def stagedPrintln(x: Any): Unit = buff append java.util.Objects.toString(x) append "\n" diff --git a/tests/run-macros/tasty-extractors-types/quoted_1.scala b/tests/run-macros/tasty-extractors-types/quoted_1.scala index 3b1f76337bea..d9dd8c34ed25 100644 --- a/tests/run-macros/tasty-extractors-types/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-types/quoted_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { implicit inline def printType[T]: Unit = ${ impl('[T]) } - def impl[T](x: Type[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl[T](x: Type[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = x.unseal '{ diff --git a/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala b/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala index f325afd34277..99366348dccf 100644 --- a/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala +++ b/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala @@ -1,17 +1,17 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object SourceFiles { - type Macro[X] = (given QuoteContext) => Expr[X] - def tastyContext(given qctx: QuoteContext): QuoteContext = qctx + type Macro[X] = QuoteContext ?=> Expr[X] + def tastyContext with (qctx: QuoteContext) : QuoteContext = qctx implicit inline def getThisFile: String = ${getThisFileImpl} def getThisFileImpl: Macro[String] = { val qctx = tastyContext - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} rootContext.source.getFileName.toString } diff --git a/tests/run-macros/tasty-getfile/Macro_1.scala b/tests/run-macros/tasty-getfile/Macro_1.scala index 47947f67f36b..470ee8912654 100644 --- a/tests/run-macros/tasty-getfile/Macro_1.scala +++ b/tests/run-macros/tasty-getfile/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object SourceFiles { @@ -7,8 +7,8 @@ object SourceFiles { implicit inline def getThisFile: String = ${getThisFileImpl} - private def getThisFileImpl(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def getThisFileImpl with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} rootContext.source.getFileName.toString } diff --git a/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala b/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala index 77f1c904ce11..8fa5e1f24a2d 100644 --- a/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala +++ b/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala @@ -2,13 +2,13 @@ import scala.quoted._ object Foo { - type Macro[X] = (given QuoteContext) => Expr[X] - type Tastier[X] = (given QuoteContext) => X + type Macro[X] = QuoteContext ?=> Expr[X] + type Tastier[X] = QuoteContext ?=> X implicit inline def foo: String = ${fooImpl} - def fooImpl(given QuoteContext): (given QuoteContext) => Tastier[(given QuoteContext) => Macro[String]] = { + def fooImpl with QuoteContext : QuoteContext ?=> Tastier[QuoteContext ?=> Macro[String]] = { '{"abc"} } diff --git a/tests/run-macros/tasty-indexed-map/quoted_1.scala b/tests/run-macros/tasty-indexed-map/quoted_1.scala index c3907b54d137..b51cee3ca8d4 100644 --- a/tests/run-macros/tasty-indexed-map/quoted_1.scala +++ b/tests/run-macros/tasty-indexed-map/quoted_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} class MyMap[Keys](private val underlying: Array[Int]) extends AnyVal { def get[K <: String](implicit i: Index[K, Keys]): Int = underlying(i.index) @@ -26,7 +26,7 @@ object Index { implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${succImpl[K, H, T]} def succImpl[K, H, T](implicit qctx: QuoteContext, k: Type[K], h: Type[H], t: Type[T]): Expr[Index[K, (H, T)]] = { - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} def name(tp: TypeOrBounds): String = tp match { case ConstantType(Constant(str: String)) => str diff --git a/tests/run-macros/tasty-interpolation-1/Macro.scala b/tests/run-macros/tasty-interpolation-1/Macro.scala index b3e1fb06af2a..6f25fe436584 100644 --- a/tests/run-macros/tasty-interpolation-1/Macro.scala +++ b/tests/run-macros/tasty-interpolation-1/Macro.scala @@ -1,7 +1,7 @@ import scala.quoted._ import scala.language.implicitConversions -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macro { @@ -14,24 +14,24 @@ object Macro { } object SIntepolator extends MacroStringInterpolator[String] { - protected def interpolate(strCtx: StringContext, args: List[Expr[Any]])(given QuoteContext): Expr[String] = + protected def interpolate(strCtx: StringContext, args: List[Expr[Any]]) with QuoteContext : Expr[String] = '{(${strCtx}).s(${Expr.ofList(args)}: _*)} } object RawIntepolator extends MacroStringInterpolator[String] { - protected def interpolate(strCtx: StringContext, args: List[Expr[Any]])(given QuoteContext): Expr[String] = + protected def interpolate(strCtx: StringContext, args: List[Expr[Any]]) with QuoteContext : Expr[String] = '{(${strCtx}).raw(${Expr.ofList(args)}: _*)} } object FooIntepolator extends MacroStringInterpolator[String] { - protected def interpolate(strCtx: StringContext, args: List[Expr[Any]])(given QuoteContext): Expr[String] = + protected def interpolate(strCtx: StringContext, args: List[Expr[Any]]) with QuoteContext : Expr[String] = '{(${strCtx}).s(${Expr.ofList(args.map(_ => '{"foo"}))}: _*)} } // TODO put this class in the stdlib or separate project? abstract class MacroStringInterpolator[T] { - final def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[T] = { + final def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[T] = { try interpolate(strCtxExpr, argsExpr) catch { case ex: NotStaticlyKnownError => @@ -49,13 +49,13 @@ abstract class MacroStringInterpolator[T] { } } - protected def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given QuoteContext): Expr[T] = + protected def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with QuoteContext : Expr[T] = interpolate(getStaticStringContext(strCtxExpr), getArgsList(argsExpr)) - protected def interpolate(strCtx: StringContext, argExprs: List[Expr[Any]])(given QuoteContext): Expr[T] + protected def interpolate(strCtx: StringContext, argExprs: List[Expr[Any]]) with QuoteContext : Expr[T] - protected def getStaticStringContext(strCtxExpr: Expr[StringContext])(given qctx: QuoteContext): StringContext = { - import qctx.tasty.{_, given} + protected def getStaticStringContext(strCtxExpr: Expr[StringContext]) with (qctx: QuoteContext) : StringContext = { + import qctx.tasty.{_, given _} strCtxExpr.unseal.underlyingArgument match { case Select(Typed(Apply(_, List(Apply(_, List(Typed(Repeated(strCtxArgTrees, _), Inferred()))))), _), _) => val strCtxArgs = strCtxArgTrees.map { @@ -68,8 +68,8 @@ abstract class MacroStringInterpolator[T] { } } - protected def getArgsList(argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): List[Expr[Any]] = { - import qctx.tasty.{_, given} + protected def getArgsList(argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : List[Expr[Any]] = { + import qctx.tasty.{_, given _} argsExpr.unseal.underlyingArgument match { case Typed(Repeated(args, _), _) => args.map(_.seal) case tree => throw new NotStaticlyKnownError("Expected statically known argument list", tree.seal) diff --git a/tests/run-macros/tasty-linenumber-2/quoted_1.scala b/tests/run-macros/tasty-linenumber-2/quoted_1.scala index e55ba8f1f07f..c61112074e51 100644 --- a/tests/run-macros/tasty-linenumber-2/quoted_1.scala +++ b/tests/run-macros/tasty-linenumber-2/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} class LineNumber(val value: Int) { override def toString: String = value.toString @@ -9,8 +9,8 @@ object LineNumber { implicit inline def line: LineNumber = ${lineImpl} - def lineImpl(given qctx: QuoteContext): Expr[LineNumber] = { - import qctx.tasty.{_, given} + def lineImpl with (qctx: QuoteContext) : Expr[LineNumber] = { + import qctx.tasty.{_, given _} '{new LineNumber(${rootPosition.startLine})} } diff --git a/tests/run-macros/tasty-linenumber/quoted_1.scala b/tests/run-macros/tasty-linenumber/quoted_1.scala index 1645772f11f4..d3bae92734fb 100644 --- a/tests/run-macros/tasty-linenumber/quoted_1.scala +++ b/tests/run-macros/tasty-linenumber/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} class LineNumber(val value: Int) { override def toString: String = value.toString @@ -10,8 +10,8 @@ object LineNumber { implicit inline def line[T >: Unit <: Unit]: LineNumber = ${lineImpl('[T])} - def lineImpl(x: Type[Unit])(given qctx: QuoteContext): Expr[LineNumber] = { - import qctx.tasty.{_, given} + def lineImpl(x: Type[Unit]) with (qctx: QuoteContext) : Expr[LineNumber] = { + import qctx.tasty.{_, given _} '{new LineNumber(${rootPosition.startLine})} } diff --git a/tests/run-macros/tasty-location/quoted_1.scala b/tests/run-macros/tasty-location/quoted_1.scala index 008c1d001a7f..c37166fdea38 100644 --- a/tests/run-macros/tasty-location/quoted_1.scala +++ b/tests/run-macros/tasty-location/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} case class Location(owners: List[String]) @@ -7,8 +7,8 @@ object Location { implicit inline def location: Location = ${impl} - def impl(given qctx: QuoteContext): Expr[Location] = { - import qctx.tasty.{_, given} + def impl with (qctx: QuoteContext) : Expr[Location] = { + import qctx.tasty.{_, given _} def listOwnerNames(sym: Symbol, acc: List[String]): List[String] = if (sym == defn.RootClass || sym == defn.EmptyPackageClass) acc diff --git a/tests/run-macros/tasty-macro-assert/quoted_1.scala b/tests/run-macros/tasty-macro-assert/quoted_1.scala index 48e02875deb9..a284bd15eb5a 100644 --- a/tests/run-macros/tasty-macro-assert/quoted_1.scala +++ b/tests/run-macros/tasty-macro-assert/quoted_1.scala @@ -12,8 +12,8 @@ object Asserts { inline def macroAssert(cond: => Boolean): Unit = ${impl('cond)} - def impl(cond: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(cond: Expr[Boolean]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val tree = cond.unseal diff --git a/tests/run-macros/tasty-macro-const/quoted_1.scala b/tests/run-macros/tasty-macro-const/quoted_1.scala index 072ffcee2c5d..5370b92927db 100644 --- a/tests/run-macros/tasty-macro-const/quoted_1.scala +++ b/tests/run-macros/tasty-macro-const/quoted_1.scala @@ -4,8 +4,8 @@ object Macros { inline def natConst(x: Int): Int = ${ natConstImpl('x) } - def natConstImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[Int] = { - import qctx.tasty.{_, given} + def natConstImpl(x: Expr[Int]) with (qctx: QuoteContext) : Expr[Int] = { + import qctx.tasty.{_, given _} val xTree: Term = x.unseal xTree match { case Inlined(_, _, Literal(Constant(n: Int))) => diff --git a/tests/run-macros/tasty-macro-positions/quoted_1.scala b/tests/run-macros/tasty-macro-positions/quoted_1.scala index 9b101ff66bb5..9a587cfb8662 100644 --- a/tests/run-macros/tasty-macro-positions/quoted_1.scala +++ b/tests/run-macros/tasty-macro-positions/quoted_1.scala @@ -8,8 +8,8 @@ object Macros { inline def fun3[T]: Unit = ${ impl2('[T]) } - def impl(x: Expr[Any])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl(x: Expr[Any]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val pos = x.unseal.underlyingArgument.pos val code = x.unseal.underlyingArgument.show '{ @@ -18,8 +18,8 @@ object Macros { } } - def impl2[T](x: quoted.Type[T])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + def impl2[T](x: quoted.Type[T]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val pos = x.unseal.pos val code = x.unseal.show '{ @@ -30,7 +30,7 @@ object Macros { def posStr(qctx: QuoteContext)(pos: qctx.tasty.Position): Expr[String] = { given QuoteContext = qctx - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} Expr(s"${pos.sourceFile.jpath.getFileName.toString}:[${pos.start}..${pos.end}]") } } diff --git a/tests/run-macros/tasty-original-source/Macros_1.scala b/tests/run-macros/tasty-original-source/Macros_1.scala index b322611c0457..77cce9842e5b 100644 --- a/tests/run-macros/tasty-original-source/Macros_1.scala +++ b/tests/run-macros/tasty-original-source/Macros_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { implicit inline def withSource(arg: Any): (String, Any) = ${ impl('arg) } - private def impl(arg: Expr[Any])(given qctx: QuoteContext): Expr[(String, Any)] = { - import qctx.tasty.{_, given} + private def impl(arg: Expr[Any]) with (qctx: QuoteContext) : Expr[(String, Any)] = { + import qctx.tasty.{_, given _} val source = arg.unseal.underlyingArgument.pos.sourceCode.toString '{Tuple2($source, $arg)} } diff --git a/tests/run-macros/tasty-positioned/quoted_1.scala b/tests/run-macros/tasty-positioned/quoted_1.scala index 1d8442c0152b..c5c07f9fb054 100644 --- a/tests/run-macros/tasty-positioned/quoted_1.scala +++ b/tests/run-macros/tasty-positioned/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} case class Position(path: String, start: Int, end: Int, startLine: Int, startColumn: Int, endLine: Int, endColumn: Int) @@ -11,7 +11,7 @@ object Positioned { implicit inline def apply[T](x: => T): Positioned[T] = ${impl('x)} def impl[T](x: Expr[T])(implicit ev: Type[T], qctx: QuoteContext): Expr[Positioned[T]] = { - import qctx.tasty.{Position => _, _, given} + import qctx.tasty.{Position => _, _, given _} val pos = rootPosition val path = pos.sourceFile.jpath.toString diff --git a/tests/run-macros/tasty-seal-method/quoted_1.scala b/tests/run-macros/tasty-seal-method/quoted_1.scala index b3f9c662681d..bf9be727b5fc 100644 --- a/tests/run-macros/tasty-seal-method/quoted_1.scala +++ b/tests/run-macros/tasty-seal-method/quoted_1.scala @@ -6,8 +6,8 @@ object Asserts { ${ zeroLastArgsImpl('x) } /** Replaces last argument list by 0s */ - def zeroLastArgsImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[Int] = { - import qctx.tasty.{_, given} + def zeroLastArgsImpl(x: Expr[Int]) with (qctx: QuoteContext) : Expr[Int] = { + import qctx.tasty.{_, given _} // For simplicity assumes that all parameters are Int and parameter lists have no more than 3 elements x.unseal.underlyingArgument match { case Apply(fn, args) => @@ -28,8 +28,8 @@ object Asserts { ${ zeroAllArgsImpl('x) } /** Replaces all argument list by 0s */ - def zeroAllArgsImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[Int] = { - import qctx.tasty.{_, given} + def zeroAllArgsImpl(x: Expr[Int]) with (qctx: QuoteContext) : Expr[Int] = { + import qctx.tasty.{_, given _} // For simplicity assumes that all parameters are Int and parameter lists have no more than 3 elements def rec(term: Term): Term = term match { case Apply(fn, args) => diff --git a/tests/run-macros/tasty-simplified/quoted_1.scala b/tests/run-macros/tasty-simplified/quoted_1.scala index 1c382f252b8a..d2b4fb9515fc 100644 --- a/tests/run-macros/tasty-simplified/quoted_1.scala +++ b/tests/run-macros/tasty-simplified/quoted_1.scala @@ -5,8 +5,8 @@ object Macros { inline def simplified[T <: Tuple]: Seq[String] = ${ impl[T] } - def impl[T: Type](given qctx: QuoteContext): Expr[Seq[String]] = { - import qctx.tasty.{_, given} + def impl[T: Type] with (qctx: QuoteContext) : Expr[Seq[String]] = { + import qctx.tasty.{_, given _} def unpackTuple(tp: Type): List[Type] = { @tailrec diff --git a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala index f5f44a5b6919..059afb5037dc 100644 --- a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala +++ b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.quoted.matching._ import scala.language.implicitConversions @@ -19,12 +19,12 @@ object TestFooErrors { // Defined in tests object Macro { - def foo(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = { + def foo(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[String] = { (sc, argsExpr) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) => val reporter = new Reporter { def errorOnPart(msg: String, partIdx: Int): Unit = { - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} error(msg, parts(partIdx).unseal.pos) } } @@ -32,13 +32,13 @@ object Macro { } } - def fooErrors(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[List[(Int, Int, Int, String)]] = { + def fooErrors(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[List[(Int, Int, Int, String)]] = { (sc, argsExpr) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) => val errors = List.newBuilder[Expr[(Int, Int, Int, String)]] val reporter = new Reporter { def errorOnPart(msg: String, partIdx: Int): Unit = { - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} val pos = parts(partIdx).unseal.pos errors += '{ Tuple4($partIdx, ${pos.start}, ${pos.end}, $msg) } } @@ -51,7 +51,7 @@ object Macro { } - private def fooCore(parts: Seq[Expr[String]], args: Seq[Expr[Any]], reporter: Reporter)(given QuoteContext): Expr[String] = { + private def fooCore(parts: Seq[Expr[String]], args: Seq[Expr[Any]], reporter: Reporter) with QuoteContext : Expr[String] = { for ((part, idx) <- parts.zipWithIndex) { val Const(v: String) = part if (v.contains("#")) diff --git a/tests/run-macros/tasty-subtyping/quoted_1.scala b/tests/run-macros/tasty-subtyping/quoted_1.scala index 5f3cdea1d42b..dc809f2dd691 100644 --- a/tests/run-macros/tasty-subtyping/quoted_1.scala +++ b/tests/run-macros/tasty-subtyping/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { @@ -9,14 +9,14 @@ object Macros { inline def isSubTypeOf[T, U]: Boolean = ${isSubTypeOfImpl('[T], '[U])} - def isTypeEqualImpl[T, U](t: Type[T], u: Type[U])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} + def isTypeEqualImpl[T, U](t: Type[T], u: Type[U]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} val isTypeEqual = t.unseal.tpe =:= u.unseal.tpe isTypeEqual } - def isSubTypeOfImpl[T, U](t: Type[T], u: Type[U])(given qctx: QuoteContext): Expr[Boolean] = { - import qctx.tasty.{_, given} + def isSubTypeOfImpl[T, U](t: Type[T], u: Type[U]) with (qctx: QuoteContext) : Expr[Boolean] = { + import qctx.tasty.{_, given _} val isTypeEqual = t.unseal.tpe <:< u.unseal.tpe isTypeEqual } diff --git a/tests/run-macros/tasty-tree-map/quoted_1.scala b/tests/run-macros/tasty-tree-map/quoted_1.scala index ba9126412170..e88234325f2d 100644 --- a/tests/run-macros/tasty-tree-map/quoted_1.scala +++ b/tests/run-macros/tasty-tree-map/quoted_1.scala @@ -4,8 +4,8 @@ object Macros { implicit inline def identityMaped[T](x: => T): T = ${ impl('x) } - def impl[T: Type](x: Expr[T])(given qctx: QuoteContext): Expr[T] = { - import qctx.tasty.{_, given} + def impl[T: Type](x: Expr[T]) with (qctx: QuoteContext) : Expr[T] = { + import qctx.tasty.{_, given _} val identityMap = new TreeMap { } val transformed = identityMap.transformTerm(x.unseal).seal.cast[T] transformed diff --git a/tests/run-macros/tasty-typeof/Macro_1.scala b/tests/run-macros/tasty-typeof/Macro_1.scala index 4f1e0ca69c25..85530dc420ef 100644 --- a/tests/run-macros/tasty-typeof/Macro_1.scala +++ b/tests/run-macros/tasty-typeof/Macro_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def testTypeOf(): Unit = ${ testTypeOfImpl } - private def testTypeOfImpl(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + private def testTypeOfImpl with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} '{ assert(${(typeOf[Unit] =:= defn.UnitType)}, "Unit") assert(${(typeOf[Byte] =:= defn.ByteType)}, "Byte") diff --git a/tests/run-macros/tasty-unsafe-let/quoted_1.scala b/tests/run-macros/tasty-unsafe-let/quoted_1.scala index 397a47d8d0d1..c7295b3a2c18 100644 --- a/tests/run-macros/tasty-unsafe-let/quoted_1.scala +++ b/tests/run-macros/tasty-unsafe-let/quoted_1.scala @@ -5,8 +5,8 @@ object Macros { inline def let[T](rhs: => T)(body: => T => Unit): Unit = ${ impl('rhs, 'body) } - private def impl[T](rhs: Expr[T], body: Expr[T => Unit])(given qctx: QuoteContext): Expr[Unit] = { - import qctx.tasty.{_, given} + private def impl[T](rhs: Expr[T], body: Expr[T => Unit]) with (qctx: QuoteContext) : Expr[Unit] = { + import qctx.tasty.{_, given _} val rhsTerm = rhs.unseal diff --git a/tests/run-macros/type-show/Macro_1.scala b/tests/run-macros/type-show/Macro_1.scala index 3d4e77649f6b..fda1bf8f006f 100644 --- a/tests/run-macros/type-show/Macro_1.scala +++ b/tests/run-macros/type-show/Macro_1.scala @@ -2,8 +2,8 @@ import scala.quoted._ object TypeToolbox { inline def show[A]: String = ${ showImpl('[A]) } - private def showImpl[A, B](a: Type[A])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def showImpl[A, B](a: Type[A]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} Expr(a.show) } } diff --git a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala index 88f9f0301968..fba59cea1f36 100644 --- a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.language.implicitConversions @@ -13,8 +13,8 @@ object XmlQuote { } def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]]) - (given qctx: QuoteContext): Expr[Xml] = { - import qctx.tasty.{_, given} + with (qctx: QuoteContext) : Expr[Xml] = { + import qctx.tasty.{_, given _} // for debugging purpose def pp(tree: Tree): Unit = { diff --git a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala index 4ec2c1b4257d..a6cef4f057c5 100644 --- a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala @@ -1,6 +1,6 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.language.implicitConversions @@ -14,8 +14,8 @@ object XmlQuote { } implicit inline def SCOps(ctx: => StringContext): SCOps = new SCOps(ctx) - def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[Xml] = { - import qctx.tasty.{_, given} + def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]]) with (qctx: QuoteContext) : Expr[Xml] = { + import qctx.tasty.{_, given _} // for debugging purpose def pp(tree: Tree): Unit = { diff --git a/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala index 40d52cd561a2..d9b2f288db3a 100644 --- a/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-3/XmlQuote_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.language.implicitConversions @@ -12,7 +12,7 @@ object XmlQuote { ${XmlQuote.impl(ctx, 'args)} } - def impl(receiver: StringContext, args: Expr[Seq[Any]])(given QuoteContext): Expr[Xml] = { + def impl(receiver: StringContext, args: Expr[Seq[Any]]) with QuoteContext : Expr[Xml] = { val string = receiver.parts.mkString("??") '{new Xml(${string}, $args.toList)} } diff --git a/tests/run-macros/xml-interpolation-4/Macros_1.scala b/tests/run-macros/xml-interpolation-4/Macros_1.scala index 0867cba6178f..add33064cc93 100644 --- a/tests/run-macros/xml-interpolation-4/Macros_1.scala +++ b/tests/run-macros/xml-interpolation-4/Macros_1.scala @@ -1,17 +1,17 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.language.implicitConversions object XmlQuote { implicit object SCOps { - inline def (ctx: => StringContext) xml (args: => ((given Scope) => Any)*)(given Scope): String = + inline def (ctx: => StringContext) xml (args: => (Scope ?=> Any)*) with Scope : String = ${XmlQuote.impl('ctx, 'args, '{implicitly[Scope]})} } - private def impl(receiver: Expr[StringContext], args: Expr[Seq[(given Scope) => Any]], scope: Expr[Scope])(given QuoteContext): Expr[String] = '{ - $receiver.s($args.map(_(given $scope.inner)): _*) + private def impl(receiver: Expr[StringContext], args: Expr[Seq[Scope ?=> Any]], scope: Expr[Scope]) with QuoteContext : Expr[String] = '{ + $receiver.s($args.map(_.with($scope.inner)): _*) } } diff --git a/tests/run-staging/i3876-b.scala b/tests/run-staging/i3876-b.scala index 39d0d8b7d6dc..674e40d1e3f3 100644 --- a/tests/run-staging/i3876-b.scala +++ b/tests/run-staging/i3876-b.scala @@ -4,9 +4,9 @@ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def x(given QuoteContext): Expr[Int] = '{3} + def x with QuoteContext : Expr[Int] = '{3} - def f2(given QuoteContext): Expr[Int => Int] = '{ + def f2 with QuoteContext : Expr[Int => Int] = '{ def f(x: Int): Int = x + x f } diff --git a/tests/run-staging/i3876-c.scala b/tests/run-staging/i3876-c.scala index f7b450f0b5e5..0c4bda3f02fb 100644 --- a/tests/run-staging/i3876-c.scala +++ b/tests/run-staging/i3876-c.scala @@ -4,9 +4,9 @@ object Test { def main(args: Array[String]): Unit = { implicit def toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader) - def x(given QuoteContext): Expr[Int] = '{3} + def x with QuoteContext : Expr[Int] = '{3} - def f3(given QuoteContext): Expr[Int => Int] = '{ + def f3 with QuoteContext : Expr[Int => Int] = '{ val f: (x: Int) => Int = x => x + x f } diff --git a/tests/run-staging/i3876-d.scala b/tests/run-staging/i3876-d.scala index aa383745eb58..391ee357d0f4 100644 --- a/tests/run-staging/i3876-d.scala +++ b/tests/run-staging/i3876-d.scala @@ -4,9 +4,9 @@ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def x(given QuoteContext): Expr[Int] = '{3} + def x with QuoteContext : Expr[Int] = '{3} - def f4(given QuoteContext): Expr[Int => Int] = '{ + def f4 with QuoteContext : Expr[Int => Int] = '{ inlineLambda } println(run(Expr.betaReduce(f4)(x))) diff --git a/tests/run-staging/i3876-e.scala b/tests/run-staging/i3876-e.scala index 4f324c943ae2..b53bda6f7256 100644 --- a/tests/run-staging/i3876-e.scala +++ b/tests/run-staging/i3876-e.scala @@ -4,9 +4,9 @@ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def x(given QuoteContext): Expr[Int] = '{ println(); 3 } + def x with QuoteContext : Expr[Int] = '{ println(); 3 } - def f4(given QuoteContext): Expr[Int => Int] = '{ + def f4 with QuoteContext : Expr[Int => Int] = '{ inlineLambda } println(run(Expr.betaReduce(f4)(x))) diff --git a/tests/run-staging/i3876.scala b/tests/run-staging/i3876.scala index e4d0146bff3d..bc51bc9f7541 100644 --- a/tests/run-staging/i3876.scala +++ b/tests/run-staging/i3876.scala @@ -4,9 +4,9 @@ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def x(given QuoteContext): Expr[Int] = '{3} + def x with QuoteContext : Expr[Int] = '{3} - def f(given QuoteContext): Expr[Int => Int] = '{ (x: Int) => x + x } + def f with QuoteContext : Expr[Int => Int] = '{ (x: Int) => x + x } println(run(Expr.betaReduce(f)(x))) println(withQuoteContext(Expr.betaReduce(f)(x).show)) diff --git a/tests/run-staging/i3946.scala b/tests/run-staging/i3946.scala index 07d32e1c2b71..4aa5f83e7536 100644 --- a/tests/run-staging/i3946.scala +++ b/tests/run-staging/i3946.scala @@ -3,7 +3,7 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def u(given QuoteContext): Expr[Unit] = '{} + def u with QuoteContext : Expr[Unit] = '{} println(withQuoteContext(u.show)) println(run(u)) } diff --git a/tests/run-staging/i3947b2.scala b/tests/run-staging/i3947b2.scala index 6d4254a5e097..f2959802aec2 100644 --- a/tests/run-staging/i3947b2.scala +++ b/tests/run-staging/i3947b2.scala @@ -7,7 +7,7 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = run { - def test[T: Type](clazz: (given QuoteContext) => java.lang.Class[T]) = { + def test[T: Type](clazz: QuoteContext ?=> java.lang.Class[T]) = { val lclazz = Expr(clazz) val name = '{ ($lclazz).getCanonicalName } println() diff --git a/tests/run-staging/i4044b.scala b/tests/run-staging/i4044b.scala index c1cb8058662c..c2c143527737 100644 --- a/tests/run-staging/i4044b.scala +++ b/tests/run-staging/i4044b.scala @@ -2,17 +2,17 @@ import scala.quoted._ import scala.quoted.staging._ sealed abstract class VarRef[T] { - def update(expr: Expr[T])(given QuoteContext): Expr[Unit] - def expr(given QuoteContext): Expr[T] + def update(expr: Expr[T]) with QuoteContext : Expr[Unit] + def expr with QuoteContext : Expr[T] } object VarRef { - def apply[T: Type, U: Type](init: Expr[T])(body: VarRef[T] => Expr[U])(given QuoteContext): Expr[U] = '{ + def apply[T: Type, U: Type](init: Expr[T])(body: VarRef[T] => Expr[U]) with QuoteContext : Expr[U] = '{ var x = $init ${body( new VarRef { - def update(e: Expr[T])(given QuoteContext): Expr[Unit] = '{ x = $e } - def expr(given QuoteContext): Expr[T] = 'x + def update(e: Expr[T]) with QuoteContext : Expr[Unit] = '{ x = $e } + def expr with QuoteContext : Expr[T] = 'x } )} } diff --git a/tests/run-staging/i4350.scala b/tests/run-staging/i4350.scala index 836f9845c6fd..ce06aebe79f2 100644 --- a/tests/run-staging/i4350.scala +++ b/tests/run-staging/i4350.scala @@ -3,7 +3,7 @@ import scala.quoted._ import scala.quoted.staging._ class Foo[T: Type] { - def q(given QuoteContext) = '{(null: Any).asInstanceOf[T]} + def q with QuoteContext = '{(null: Any).asInstanceOf[T]} } object Test { diff --git a/tests/run-staging/i4591.scala b/tests/run-staging/i4591.scala index 58b14a1b6a2f..02d4341a9495 100644 --- a/tests/run-staging/i4591.scala +++ b/tests/run-staging/i4591.scala @@ -3,7 +3,7 @@ import scala.quoted.staging._ object Test { - def foo[T: Type](init: Expr[T])(given QuoteContext): Expr[Unit] = '{ + def foo[T: Type](init: Expr[T]) with QuoteContext : Expr[Unit] = '{ var x = $init println(x) } diff --git a/tests/run-staging/i4730.scala b/tests/run-staging/i4730.scala index 5c2d3c551388..6282a0bd9caf 100644 --- a/tests/run-staging/i4730.scala +++ b/tests/run-staging/i4730.scala @@ -3,7 +3,7 @@ import scala.quoted.staging._ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) - def ret(given QuoteContext): Expr[Int => Int] = '{ (x: Int) => + def ret with QuoteContext : Expr[Int => Int] = '{ (x: Int) => ${ val z = run('{x + 1}) // throws a RunScopeException Expr(z) diff --git a/tests/run-staging/i5144.scala b/tests/run-staging/i5144.scala index ee4dcb58b00b..842d247e8fd4 100644 --- a/tests/run-staging/i5144.scala +++ b/tests/run-staging/i5144.scala @@ -3,9 +3,9 @@ import scala.quoted.staging._ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) - def eval1(ff: Expr[Int => Int])(given QuoteContext): Expr[Int] = '{$ff(42)} + def eval1(ff: Expr[Int => Int]) with QuoteContext : Expr[Int] = '{$ff(42)} - def peval1()(given QuoteContext): Expr[Unit] = '{ + def peval1() with QuoteContext : Expr[Unit] = '{ def f(x: Int): Int = ${eval1('f)} } diff --git a/tests/run-staging/i5144b.scala b/tests/run-staging/i5144b.scala index ae270f37cb7f..008253ce38ee 100644 --- a/tests/run-staging/i5144b.scala +++ b/tests/run-staging/i5144b.scala @@ -3,9 +3,9 @@ import scala.quoted.staging._ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) - def eval1(ff: Expr[Int => Int])(given QuoteContext): Expr[Int] = Expr.betaReduce(ff)('{42}) + def eval1(ff: Expr[Int => Int]) with QuoteContext : Expr[Int] = Expr.betaReduce(ff)('{42}) - def peval1()(given QuoteContext): Expr[Unit] = '{ + def peval1() with QuoteContext : Expr[Unit] = '{ def f(x: Int): Int = ${eval1('f)} } diff --git a/tests/run-staging/i5152.scala b/tests/run-staging/i5152.scala index 930632af23b0..44634eea4514 100644 --- a/tests/run-staging/i5152.scala +++ b/tests/run-staging/i5152.scala @@ -3,9 +3,9 @@ import scala.quoted.staging._ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) - def eval1(ff: Expr[Int => Int])(given QuoteContext): Expr[Int => Int] = '{identity} + def eval1(ff: Expr[Int => Int]) with QuoteContext : Expr[Int => Int] = '{identity} - def peval1()(given QuoteContext): Expr[Unit] = '{ + def peval1() with QuoteContext : Expr[Unit] = '{ lazy val f: Int => Int = ${eval1('{(y: Int) => f(y)})} } diff --git a/tests/run-staging/i5161.scala b/tests/run-staging/i5161.scala index a9aa13d0463f..3dd1c8e7c247 100644 --- a/tests/run-staging/i5161.scala +++ b/tests/run-staging/i5161.scala @@ -10,7 +10,7 @@ object Test { } import Exp._ - def evalTest(e: Exp)(given QuoteContext): Expr[Option[Int]] = e match { + def evalTest(e: Exp) with QuoteContext : Expr[Option[Int]] = e match { case Int2(x) => '{ Some(${Expr(x)}) } case Add(e1, e2) => '{ @@ -25,7 +25,7 @@ object Test { def main(args: Array[String]): Unit = { val test = Add(Int2(1), Int2(1)) - def res(given QuoteContext) = evalTest(test) + def res with QuoteContext = evalTest(test) println("run : " + run(res)) println("show : " + withQuoteContext(res.show)) } diff --git a/tests/run-staging/i5161b.scala b/tests/run-staging/i5161b.scala index d32a9de09e2b..927325b85451 100644 --- a/tests/run-staging/i5161b.scala +++ b/tests/run-staging/i5161b.scala @@ -5,7 +5,7 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = { - def res(given QuoteContext) = '{ + def res with QuoteContext = '{ val x: Option[Int] = Option(3) if (x.isInstanceOf[Some[_]]) Option(1) else None diff --git a/tests/run-staging/i5247.scala b/tests/run-staging/i5247.scala index 684f0fa3f3c7..d10d61db60c6 100644 --- a/tests/run-staging/i5247.scala +++ b/tests/run-staging/i5247.scala @@ -7,11 +7,11 @@ object Test { println(foo[Object].show) println(bar[Object].show) } - def foo[H : Type](given QuoteContext): Expr[H] = { + def foo[H : Type] with QuoteContext : Expr[H] = { val t = '[H] '{ null.asInstanceOf[$t] } } - def bar[H : Type](given QuoteContext): Expr[List[H]] = { + def bar[H : Type] with QuoteContext : Expr[List[H]] = { val t = '[List[H]] '{ null.asInstanceOf[$t] } } diff --git a/tests/run-staging/i5965.scala b/tests/run-staging/i5965.scala index ae67c95ccff5..f08614a61ef0 100644 --- a/tests/run-staging/i5965.scala +++ b/tests/run-staging/i5965.scala @@ -7,20 +7,20 @@ object Test { def main(args: Array[String]): Unit = { withQuoteContext('[List]) - def list(given QuoteContext) = bound('{List(1, 2, 3)}) + def list with QuoteContext = bound('{List(1, 2, 3)}) println(withQuoteContext(list.show)) println(run(list)) - def opt(given QuoteContext) = bound('{Option(4)}) + def opt with QuoteContext = bound('{Option(4)}) println(withQuoteContext(opt.show)) println(run(opt)) - def map(given QuoteContext) = bound('{Map(4 -> 1)}) + def map with QuoteContext = bound('{Map(4 -> 1)}) println(withQuoteContext(map.show)) println(run(map)) } - def bound[T: Type, S[_]: Type](x: Expr[S[T]])(given QuoteContext): Expr[S[T]] = '{ + def bound[T: Type, S[_]: Type](x: Expr[S[T]]) with QuoteContext : Expr[S[T]] = '{ val y: S[T] = $x y } diff --git a/tests/run-staging/i5965b.scala b/tests/run-staging/i5965b.scala index cec76470478d..f0388f9d90de 100644 --- a/tests/run-staging/i5965b.scala +++ b/tests/run-staging/i5965b.scala @@ -7,20 +7,20 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) withQuoteContext('[List]) - def list(given QuoteContext) = bound('{List(1, 2, 3)}) + def list with QuoteContext = bound('{List(1, 2, 3)}) println(withQuoteContext(list.show)) println(run(list)) - def opt(given QuoteContext) = bound('{Option(4)}) + def opt with QuoteContext = bound('{Option(4)}) println(withQuoteContext(opt.show)) println(run(opt)) - def map(given QuoteContext) = bound('{Map(4 -> 1)}) + def map with QuoteContext = bound('{Map(4 -> 1)}) println(withQuoteContext(map.show)) println(run(map)) } - def bound[T: Type, S[_]: Type](x: Expr[S[T]])(given QuoteContext): Expr[S[T]] = '{ + def bound[T: Type, S[_]: Type](x: Expr[S[T]]) with QuoteContext : Expr[S[T]] = '{ val y = $x y } diff --git a/tests/run-staging/i6281.scala b/tests/run-staging/i6281.scala index a20586881d6e..75f8faa068b2 100644 --- a/tests/run-staging/i6281.scala +++ b/tests/run-staging/i6281.scala @@ -18,31 +18,31 @@ object Test extends App { } trait Effects[L <: HList] { - def reify[A](given Type[A]): STM[A, L] => Expr[Stm[A, L]] - def reflect[A](given Type[A]): Expr[Stm[A, L]] => STM[A, L] + def reify[A] with Type[A] : STM[A, L] => Expr[Stm[A, L]] + def reflect[A] with Type[A] : Expr[Stm[A, L]] => STM[A, L] } - given empty : Effects[HNil] { - def reify[A](given Type[A]) = m => m - def reflect[A](given Type[A]) = m => m + given empty as Effects[HNil] { + def reify[A] with Type[A] = m => m + def reflect[A] with Type[A] = m => m } // for reify, we need type tags for E and also strangely for L. - implicit def cons [E, L <: HList](given Effects[L])(given Type[E])(given Type[L])(given QuoteContext): Effects[E :: L] = new Effects[E :: L] { - def reify[A](given Type[A]) = m => '{ k => ${ Effects[L].reify[E] { m( a => Effects[L].reflect[E](Expr.betaReduce('k)(a))) } }} - def reflect[A](given Type[A]) = m => k => Effects[L].reflect[E] { Expr.betaReduce(m)('{ a => ${ Effects[L].reify[E]( k('a)) } })} + implicit def cons [E, L <: HList] with Effects[L] with Type[E] with Type[L] with QuoteContext : Effects[E :: L] = new Effects[E :: L] { + def reify[A] with Type[A] = m => '{ k => ${ Effects[L].reify[E] { m( a => Effects[L].reflect[E](Expr.betaReduce('k)(a))) } }} + def reflect[A] with Type[A] = m => k => Effects[L].reflect[E] { Expr.betaReduce(m)('{ a => ${ Effects[L].reify[E]( k('a)) } })} } - def Effects[L <: HList](given Effects[L]): Effects[L] = summon[Effects[L]] + def Effects[L <: HList] with Effects[L] : Effects[L] = summon[Effects[L]] type RS = Boolean :: RS2 type RS2 = Int :: String :: HNil - def m(given QuoteContext): STM[Int, RS] = k => k('{42}) + def m with QuoteContext : STM[Int, RS] = k => k('{42}) implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader) withQuoteContext { println(Effects[RS].reify[Int] { m }.show) - val effects = cons[Boolean, RS2](given cons[Int, String :: HNil](given cons[String, HNil](given empty))) + val effects = cons[Boolean, RS2].with(cons[Int, String :: HNil].with(cons[String, HNil].with(empty))) println(effects.reify[Int] { m }.show) val res : Expr[Stm[Int, RS]] = '{ k => ${ Effects[RS2].reify[Boolean] { m(a => Effects[RS2].reflect[Boolean](Expr.betaReduce('k)(a))) }}} diff --git a/tests/run-staging/i6754.scala b/tests/run-staging/i6754.scala index c8d2ba78523a..41b97b435ea7 100644 --- a/tests/run-staging/i6754.scala +++ b/tests/run-staging/i6754.scala @@ -6,8 +6,8 @@ object Test { implicit val tbx: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = { - def y(given QuoteContext): Expr[Unit] = '{ - def x(given QuoteContext): Expr[Unit] = '{println("bar")} + def y with QuoteContext : Expr[Unit] = '{ + def x with QuoteContext : Expr[Unit] = '{println("bar")} println("foo") run(x) } diff --git a/tests/run-staging/i6992/Macro_1.scala b/tests/run-staging/i6992/Macro_1.scala index d5d2cd4cb0c7..3e2e16df83da 100644 --- a/tests/run-staging/i6992/Macro_1.scala +++ b/tests/run-staging/i6992/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._, scala.quoted.matching._ import scala.quoted.staging._ -import scala.quoted.given +import scala.quoted.{given _} given Toolbox = Toolbox.make(getClass.getClassLoader) @@ -10,7 +10,7 @@ object macros { class Foo { val x = 10 } - def mcrImpl(body: Expr[Any])(given ctx: QuoteContext): Expr[Any] = { + def mcrImpl(body: Expr[Any]) with (ctx: QuoteContext) : Expr[Any] = { import ctx.tasty._ try { body match { diff --git a/tests/run-staging/inline-quote.scala b/tests/run-staging/inline-quote.scala index f94782efbe7c..f73fa66feefc 100644 --- a/tests/run-staging/inline-quote.scala +++ b/tests/run-staging/inline-quote.scala @@ -3,7 +3,7 @@ import scala.quoted.staging._ object Test { - inline def foo(x: Expr[Int])(given QuoteContext): Expr[Int] = '{ + inline def foo(x: Expr[Int]) with QuoteContext : Expr[Int] = '{ println("foo") $x } diff --git a/tests/run-staging/quote-ackermann-1.scala b/tests/run-staging/quote-ackermann-1.scala index f1e5a5424d85..11be62848456 100644 --- a/tests/run-staging/quote-ackermann-1.scala +++ b/tests/run-staging/quote-ackermann-1.scala @@ -12,7 +12,7 @@ object Test { println(ack3(4)) } - def ackermann(m: Int)(given QuoteContext): Expr[Int => Int] = { + def ackermann(m: Int) with QuoteContext : Expr[Int => Int] = { if (m == 0) '{ n => n + 1 } else '{ n => def `ackermann(m-1)`(n: Int): Int = ${Expr.betaReduce(ackermann(m - 1))('n)} // Expr[Int => Int] applied to Expr[Int] diff --git a/tests/run-staging/quote-fun-app-1.scala b/tests/run-staging/quote-fun-app-1.scala index 0b052319cf22..2dd0e42d8cd7 100644 --- a/tests/run-staging/quote-fun-app-1.scala +++ b/tests/run-staging/quote-fun-app-1.scala @@ -12,8 +12,8 @@ object Test { println(f(43)) } - def f1(given QuoteContext): Expr[Int => Int] = '{ n => ${Expr.betaReduce(f2)('n)} } - def f2(given QuoteContext): Expr[Int => Int] = '{ n => ${Expr.betaReduce(f3)('n)} } - def f3(given QuoteContext): Expr[Int => Int] = '{ n => ${Expr.betaReduce(f4)('n)} } - def f4(given QuoteContext): Expr[Int => Int] = '{ n => n } + def f1 with QuoteContext : Expr[Int => Int] = '{ n => ${Expr.betaReduce(f2)('n)} } + def f2 with QuoteContext : Expr[Int => Int] = '{ n => ${Expr.betaReduce(f3)('n)} } + def f3 with QuoteContext : Expr[Int => Int] = '{ n => ${Expr.betaReduce(f4)('n)} } + def f4 with QuoteContext : Expr[Int => Int] = '{ n => n } } diff --git a/tests/run-staging/quote-function-applied-to.scala b/tests/run-staging/quote-function-applied-to.scala index 94af9f477454..2b0c87c0249d 100644 --- a/tests/run-staging/quote-function-applied-to.scala +++ b/tests/run-staging/quote-function-applied-to.scala @@ -1,11 +1,11 @@ import scala.quoted._ -import scala.quoted.given +import scala.quoted.{given _} import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def show(expr: (given QuoteContext) => Expr[_]): String = withQuoteContext(expr.show) + def show(expr: QuoteContext ?=> Expr[_]): String = withQuoteContext(expr.show) println(show(Expr.betaReduce('{ () => x(0) })())) println(show(Expr.betaReduce('{ (x1: Int) => x1 })('{x(1)}))) println(show(Expr.betaReduce('{ (x1: Int, x2: Int) => x1 + x2 })('{x(1)}, '{x(2)}))) @@ -30,28 +30,28 @@ object Test { println(show(Expr.betaReduce('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}))) println(show(Expr.betaReduce('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}, '{x(22)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int) => x1 })('{x(1)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int) => x1 + x2 })('{x(1)}, '{x(2)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 })('{x(1)}, '{x(2)}, '{x(3)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1 + x2 + x3 + x4 + x5 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1 + x2 + x3 + x4 + x5 + x6 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}))) - println(show(Expr.betaReduceGiven('{ (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}, '{x(22)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int) ?=> x1 })('{x(1)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int) ?=> x1 + x2 })('{x(1)}, '{x(2)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int) ?=> x1 + x2 + x3 })('{x(1)}, '{x(2)}, '{x(3)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int) ?=> x1 + x2 + x3 + x4 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) ?=> x1 + x2 + x3 + x4 + x5 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}))) + println(show(Expr.betaReduceGiven('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) ?=> x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 })('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}, '{x(5)}, '{x(6)}, '{x(7)}, '{x(8)}, '{x(9)}, '{x(10)}, '{x(11)}, '{x(12)}, '{x(13)}, '{x(14)}, '{x(15)}, '{x(16)}, '{x(17)}, '{x(18)}, '{x(19)}, '{x(20)}, '{x(21)}, '{x(22)}))) } def x(i: Int): Int = i diff --git a/tests/run-staging/quote-lib.scala b/tests/run-staging/quote-lib.scala index 7fe391c50186..74ba1d064c06 100644 --- a/tests/run-staging/quote-lib.scala +++ b/tests/run-staging/quote-lib.scala @@ -1,7 +1,7 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import liftable.Units._ import liftable.Lets._ @@ -116,7 +116,7 @@ package liftable { object Exprs { implicit class LiftExprOps[T](x: T) extends AnyVal { - def toExpr(given Liftable[T], QuoteContext): Expr[T] = + def toExpr with (Liftable[T], QuoteContext) : Expr[T] = summon[Liftable[T]].toExpr(x) } } @@ -137,8 +137,8 @@ package liftable { } object Loops { - def liftedWhile(cond: Expr[Boolean])(body: Expr[Unit])(given QuoteContext): Expr[Unit] = '{ while ($cond) $body } - def liftedDoWhile(body: Expr[Unit])(cond: Expr[Boolean])(given QuoteContext): Expr[Unit] = '{ while { $body ; $cond } do () } + def liftedWhile(cond: Expr[Boolean])(body: Expr[Unit]) with QuoteContext : Expr[Unit] = '{ while ($cond) $body } + def liftedDoWhile(body: Expr[Unit])(cond: Expr[Boolean]) with QuoteContext : Expr[Unit] = '{ while { $body ; $cond } do () } } @@ -147,7 +147,7 @@ package liftable { implicit class LiftedOps[T: Liftable](list: Expr[List[T]])(implicit t: Type[T]) { def foldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U], qctx: QuoteContext): Expr[U] = '{ ($list).foldLeft[$u]($acc)($f) } - def foreach(f: Expr[T => Unit])(given QuoteContext): Expr[Unit] = + def foreach(f: Expr[T => Unit]) with QuoteContext : Expr[Unit] = '{ ($list).foreach($f) } } diff --git a/tests/run-staging/quote-lift-Array.scala b/tests/run-staging/quote-lift-Array.scala index 3188a4ee7521..df6bac192dbe 100644 --- a/tests/run-staging/quote-lift-Array.scala +++ b/tests/run-staging/quote-lift-Array.scala @@ -1,6 +1,6 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Test { implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader) diff --git a/tests/run-staging/quote-lift-IArray.scala b/tests/run-staging/quote-lift-IArray.scala index 543dc4466042..32e62a2ad94b 100644 --- a/tests/run-staging/quote-lift-IArray.scala +++ b/tests/run-staging/quote-lift-IArray.scala @@ -1,6 +1,6 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Test { implicit val toolbox: scala.quoted.staging.Toolbox = scala.quoted.staging.Toolbox.make(getClass.getClassLoader) diff --git a/tests/run-staging/quote-macro-in-splice/quoted_1.scala b/tests/run-staging/quote-macro-in-splice/quoted_1.scala index cbcdac6d5d9c..8476ca3e8062 100644 --- a/tests/run-staging/quote-macro-in-splice/quoted_1.scala +++ b/tests/run-staging/quote-macro-in-splice/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macros { - def impl(x: Expr[Int])(given QuoteContext): Expr[Int] = '{ $x + 1 } + def impl(x: Expr[Int]) with QuoteContext : Expr[Int] = '{ $x + 1 } } diff --git a/tests/run-staging/quote-nested-1.scala b/tests/run-staging/quote-nested-1.scala index f21c63c57db4..434c32b69891 100644 --- a/tests/run-staging/quote-nested-1.scala +++ b/tests/run-staging/quote-nested-1.scala @@ -4,7 +4,7 @@ import scala.quoted.staging._ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = withQuoteContext { - val q = '{ (given qctx: QuoteContext) => '{3} } + val q = '{ (qctx: QuoteContext) ?=> '{3} } println(q.show) } } diff --git a/tests/run-staging/quote-nested-2.scala b/tests/run-staging/quote-nested-2.scala index 9e24853b0f47..5838a3af3f03 100644 --- a/tests/run-staging/quote-nested-2.scala +++ b/tests/run-staging/quote-nested-2.scala @@ -5,7 +5,7 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = withQuoteContext { - val q = '{(given qctx: QuoteContext) => + val q = '{(qctx: QuoteContext) ?=> val a = '{4} '{${a}} } diff --git a/tests/run-staging/quote-nested-5.scala b/tests/run-staging/quote-nested-5.scala index a70658228fe0..8e0f646c8e3c 100644 --- a/tests/run-staging/quote-nested-5.scala +++ b/tests/run-staging/quote-nested-5.scala @@ -5,9 +5,9 @@ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = withQuoteContext { - val q = '{(given qctx: QuoteContext) => + val q = '{(qctx: QuoteContext) ?=> val a = '{4} - ${'{(given qctx2: QuoteContext) => + ${'{(qctx2: QuoteContext) ?=> '{${a}} }} diff --git a/tests/run-staging/quote-owners-2.scala b/tests/run-staging/quote-owners-2.scala index 0b0ce18b6697..6bf423c97ea1 100644 --- a/tests/run-staging/quote-owners-2.scala +++ b/tests/run-staging/quote-owners-2.scala @@ -10,7 +10,7 @@ object Test { '{ println($q) } } - def f(t: Type[List[Int]])(given QuoteContext): Expr[Int] = '{ + def f(t: Type[List[Int]]) with QuoteContext : Expr[Int] = '{ def ff: Int = { val a: $t = { type T = $t @@ -22,5 +22,5 @@ object Test { ff } - def g[T](a: Type[T])(given QuoteContext): Type[List[T]] = '[List[$a]] + def g[T](a: Type[T]) with QuoteContext : Type[List[T]] = '[List[$a]] } diff --git a/tests/run-staging/quote-owners.scala b/tests/run-staging/quote-owners.scala index 60a891336bc5..53a425c17892 100644 --- a/tests/run-staging/quote-owners.scala +++ b/tests/run-staging/quote-owners.scala @@ -4,19 +4,19 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def q(given QuoteContext) = f + def q with QuoteContext = f println(run(q)) println(withQuoteContext(q.show)) } - def f(given QuoteContext): Expr[Int] = '{ + def f with QuoteContext : Expr[Int] = '{ def ff: Int = { $g } ff } - def g(given QuoteContext): Expr[Int] = '{ + def g with QuoteContext : Expr[Int] = '{ val a = 9 a + 0 } diff --git a/tests/run-staging/quote-run-b.scala b/tests/run-staging/quote-run-b.scala index 29e61d41f0dd..dc37997bffec 100644 --- a/tests/run-staging/quote-run-b.scala +++ b/tests/run-staging/quote-run-b.scala @@ -5,7 +5,7 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def lambdaExpr(given QuoteContext) = '{ + def lambdaExpr with QuoteContext = '{ (x: Int) => println("lambda(" + x + ")") } println() diff --git a/tests/run-staging/quote-run-c.scala b/tests/run-staging/quote-run-c.scala index f902981b63a1..df21b34303c6 100644 --- a/tests/run-staging/quote-run-c.scala +++ b/tests/run-staging/quote-run-c.scala @@ -5,13 +5,13 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def classExpr(given QuoteContext) = '{ + def classExpr with QuoteContext = '{ class A { override def toString: String = "Foo" } new A } - def classExpr2(given QuoteContext) = '{ + def classExpr2 with QuoteContext = '{ class A { override def toString: String = "Bar" } diff --git a/tests/run-staging/quote-run-constants.scala b/tests/run-staging/quote-run-constants.scala index b6a051225d72..49afdb8cd3a5 100644 --- a/tests/run-staging/quote-run-constants.scala +++ b/tests/run-staging/quote-run-constants.scala @@ -1,5 +1,5 @@ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} import scala.quoted._ import scala.quoted.staging._ @@ -7,7 +7,7 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def runAndPrint[T](expr: (given QuoteContext) => Expr[T]): Unit = println(run(expr)) + def runAndPrint[T](expr: QuoteContext ?=> Expr[T]): Unit = println(run(expr)) runAndPrint(true) runAndPrint('a') diff --git a/tests/run-staging/quote-run-large.scala b/tests/run-staging/quote-run-large.scala index 90382dcc75d5..e5c663b4690f 100644 --- a/tests/run-staging/quote-run-large.scala +++ b/tests/run-staging/quote-run-large.scala @@ -3,7 +3,7 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { - def a(given QuoteContext) = '{ // ' + def a with QuoteContext = '{ // ' class Foo(x: Int) { override def toString(): String = s"Foo($x)" def foo1: Int = x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x + x diff --git a/tests/run-staging/quote-run-many.scala b/tests/run-staging/quote-run-many.scala index 3430c9804bc7..72b8eaeaf4ac 100644 --- a/tests/run-staging/quote-run-many.scala +++ b/tests/run-staging/quote-run-many.scala @@ -1,11 +1,11 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def expr(i: Int)(given QuoteContext) = '{ + def expr(i: Int) with QuoteContext = '{ val a = 3 + ${i} 2 + a } diff --git a/tests/run-staging/quote-run-staged-interpreter.scala b/tests/run-staging/quote-run-staged-interpreter.scala index 7471cfae8c84..73e494049b74 100644 --- a/tests/run-staging/quote-run-staged-interpreter.scala +++ b/tests/run-staging/quote-run-staged-interpreter.scala @@ -1,6 +1,6 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} enum Exp { case Num(n: Int) @@ -12,7 +12,7 @@ enum Exp { object Test { import Exp._ - def compile(e: Exp, env: Map[String, Expr[Int]], keepLets: Boolean)(given QuoteContext): Expr[Int] = { + def compile(e: Exp, env: Map[String, Expr[Int]], keepLets: Boolean) with QuoteContext : Expr[Int] = { def compileImpl(e: Exp, env: Map[String, Expr[Int]]): Expr[Int] = e match { case Num(n) => n case Plus(e1, e2) => '{${compileImpl(e1, env)} + ${compileImpl(e2, env)}} @@ -32,7 +32,7 @@ object Test { val exp = Plus(Plus(Num(2), Var("x")), Num(4)) val letExp = Let("x", Num(3), exp) - def res1(given QuoteContext) = '{ (x: Int) => ${compile(exp, Map("x" -> 'x), false)} } + def res1 with QuoteContext = '{ (x: Int) => ${compile(exp, Map("x" -> 'x), false)} } println(withQuoteContext(res1.show)) @@ -44,13 +44,13 @@ object Test { println("---") - def res2(given QuoteContext) = compile(letExp, Map(), false) + def res2 with QuoteContext = compile(letExp, Map(), false) println(withQuoteContext(res2.show)) println(run(res2)) println("---") - def res3(given QuoteContext) = compile(letExp, Map(), true) + def res3 with QuoteContext = compile(letExp, Map(), true) println(withQuoteContext(res3.show)) println(run(res3)) } diff --git a/tests/run-staging/quote-run-with-settings.scala b/tests/run-staging/quote-run-with-settings.scala index 5021ed685830..4a9d81dc92ca 100644 --- a/tests/run-staging/quote-run-with-settings.scala +++ b/tests/run-staging/quote-run-with-settings.scala @@ -7,7 +7,7 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def expr(given QuoteContext) = '{ + def expr with QuoteContext = '{ val a = 3 println("foo") 2 + a diff --git a/tests/run-staging/quote-run.scala b/tests/run-staging/quote-run.scala index b4f354fb6a43..4b7b8fedd183 100644 --- a/tests/run-staging/quote-run.scala +++ b/tests/run-staging/quote-run.scala @@ -4,7 +4,7 @@ import scala.quoted.staging._ object Test { def main(args: Array[String]): Unit = { given Toolbox = Toolbox.make(getClass.getClassLoader) - def expr(given QuoteContext) = '{ + def expr with QuoteContext = '{ val a = 3 println("foo") 2 + a diff --git a/tests/run-staging/quote-show-blocks.scala b/tests/run-staging/quote-show-blocks.scala index 1e6752a8da09..79b00648f985 100644 --- a/tests/run-staging/quote-show-blocks.scala +++ b/tests/run-staging/quote-show-blocks.scala @@ -1,6 +1,6 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) diff --git a/tests/run-staging/quote-unrolled-foreach.scala b/tests/run-staging/quote-unrolled-foreach.scala index fbc4acb46645..2a19e99fe589 100644 --- a/tests/run-staging/quote-unrolled-foreach.scala +++ b/tests/run-staging/quote-unrolled-foreach.scala @@ -1,36 +1,36 @@ import scala.annotation.tailrec import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = run { - def code1(given QuoteContext) = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('arr, 'f) } } + def code1 with QuoteContext = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('arr, 'f) } } println(code1.show) println() - def code1Tpe(given QuoteContext) = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } + def code1Tpe with QuoteContext = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } println(code1Tpe.show) println() - def code1Tpe2(given QuoteContext) = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } + def code1Tpe2 with QuoteContext = '{ (arr: Array[String], f: String => Unit) => ${ foreach1Tpe1('arr, 'f) } } println(code1Tpe2.show) println() - def code2(given QuoteContext) = '{ (arr: Array[Int]) => ${ foreach1('arr, '{i => System.out.println(i)}) } } + def code2 with QuoteContext = '{ (arr: Array[Int]) => ${ foreach1('arr, '{i => System.out.println(i)}) } } println(code2.show) println() - def code3(given QuoteContext) = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach3('arr, 'f) } } + def code3 with QuoteContext = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach3('arr, 'f) } } println(code3.show) println() - def code4(given QuoteContext) = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach4('arr, 'f, 4) } } + def code4 with QuoteContext = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach4('arr, 'f, 4) } } println(code4.show) println() - def liftedArray(given QuoteContext): Expr[Array[Int]] = Array(1, 2, 3, 4) + def liftedArray with QuoteContext : Expr[Array[Int]] = Array(1, 2, 3, 4) println(liftedArray.show) println() @@ -44,7 +44,7 @@ object Test { '{} } - def foreach1(arrRef: Expr[Array[Int]], f: Expr[Int => Unit])(given QuoteContext): Expr[Unit] = '{ + def foreach1(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = ($arrRef).length var i = 0 while (i < size) { @@ -64,7 +64,7 @@ object Test { } } - def foreach1Tpe2[T: Type](arrRef: Expr[Array[T]], f: Expr[T => Unit])(given QuoteContext): Expr[Unit] = '{ + def foreach1Tpe2[T: Type](arrRef: Expr[Array[T]], f: Expr[T => Unit]) with QuoteContext : Expr[Unit] = '{ val size = ($arrRef).length var i = 0 while (i < size) { @@ -74,7 +74,7 @@ object Test { } } - def foreach2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit])(given QuoteContext): Expr[Unit] = '{ + def foreach2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = ($arrRef).length var i = 0 while (i < size) { @@ -84,7 +84,7 @@ object Test { } } - def foreach3(arrRef: Expr[Array[Int]], f: Expr[Int => Unit])(given QuoteContext): Expr[Unit] = '{ + def foreach3(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = ($arrRef).length var i = 0 if (size % 3 != 0) throw new Exception("...")// for simplicity of the implementation @@ -96,7 +96,7 @@ object Test { } } - def foreach3_2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit])(given QuoteContext): Expr[Unit] = '{ + def foreach3_2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]) with QuoteContext : Expr[Unit] = '{ val size = ($arrRef).length var i = 0 if (size % 3 != 0) throw new Exception("...")// for simplicity of the implementation @@ -108,7 +108,7 @@ object Test { } } - def foreach4(arrRef: Expr[Array[Int]], f: Expr[Int => Unit], unrollSize: Int)(given QuoteContext): Expr[Unit] = '{ + def foreach4(arrRef: Expr[Array[Int]], f: Expr[Int => Unit], unrollSize: Int) with QuoteContext : Expr[Unit] = '{ val size = ($arrRef).length var i = 0 if (size % ${unrollSize} != 0) throw new Exception("...") // for simplicity of the implementation @@ -126,7 +126,7 @@ object Test { } } - def foreachInRange(start: Int, end: Int)(f: Int => Expr[Unit])(given QuoteContext): Expr[Unit] = { + def foreachInRange(start: Int, end: Int)(f: Int => Expr[Unit]) with QuoteContext : Expr[Unit] = { @tailrec def unroll(i: Int, acc: Expr[Unit]): Expr[Unit] = if (i < end) unroll(i + 1, '{ $acc; ${f(i)} }) else acc if (start < end) unroll(start + 1, f(start)) else '{} diff --git a/tests/run-staging/quote-valueof-list.scala b/tests/run-staging/quote-valueof-list.scala index 53efc0d69be1..6a68cffb5274 100644 --- a/tests/run-staging/quote-valueof-list.scala +++ b/tests/run-staging/quote-valueof-list.scala @@ -8,7 +8,7 @@ object Test { def main(args: Array[String]): Unit = withQuoteContext { implicit def ValueOfExprInt: ValueOfExpr[Int] = new { - def apply(n: Expr[Int])(given QuoteContext): Option[Int] = n match { + def apply(n: Expr[Int]) with QuoteContext : Option[Int] = n match { case '{ 0 } => Some(0) case '{ 1 } => Some(1) case '{ 2 } => Some(1) @@ -17,7 +17,7 @@ object Test { } implicit def ValueOfExprBoolean: ValueOfExpr[Boolean] = new ValueOfExpr[Boolean] { - def apply(b: Expr[Boolean])(given QuoteContext): Option[Boolean] = b match { + def apply(b: Expr[Boolean]) with QuoteContext : Option[Boolean] = b match { case '{ true } => Some(true) case '{ false } => Some(false) case _ => None @@ -25,7 +25,7 @@ object Test { } implicit def ValueOfExprList[T: ValueOfExpr: Type]: ValueOfExpr[List[T]] = new { - def apply(xs: Expr[List[T]])(given QuoteContext): Option[List[T]] = (xs: Expr[Any]) match { + def apply(xs: Expr[List[T]]) with QuoteContext : Option[List[T]] = (xs: Expr[Any]) match { case '{ ($xs1: List[T]).::($x) } => for { head <- x.getValue; tail <- xs1.getValue } yield head :: tail @@ -35,7 +35,7 @@ object Test { } implicit def ValueOfExprOption[T: ValueOfExpr: Type]: ValueOfExpr[Option[T]] = new { - def apply(expr: Expr[Option[T]])(given QuoteContext): Option[Option[T]] = expr match { + def apply(expr: Expr[Option[T]]) with QuoteContext : Option[Option[T]] = expr match { case '{ Some[T]($x) } => for (v <- x.getValue) yield Some(v) case '{ None } => Some(None) case _ => None diff --git a/tests/run-staging/quote-var.scala b/tests/run-staging/quote-var.scala index 109982246938..61ff8b78124f 100644 --- a/tests/run-staging/quote-var.scala +++ b/tests/run-staging/quote-var.scala @@ -4,18 +4,18 @@ import scala.quoted.staging._ object Test { sealed trait Var { - def get(given QuoteContext): Expr[String] - def update(x: Expr[String])(given QuoteContext): Expr[Unit] + def get with QuoteContext : Expr[String] + def update(x: Expr[String]) with QuoteContext : Expr[Unit] } object Var { - def apply(init: Expr[String])(body: Var => Expr[String])(given QuoteContext): Expr[String] = '{ + def apply(init: Expr[String])(body: Var => Expr[String]) with QuoteContext : Expr[String] = '{ var x = $init ${ body( new Var { - def get(given QuoteContext): Expr[String] = 'x - def update(e: Expr[String])(given QuoteContext): Expr[Unit] = '{ x = $e } + def get with QuoteContext : Expr[String] = 'x + def update(e: Expr[String]) with QuoteContext : Expr[Unit] = '{ x = $e } } ) } @@ -23,7 +23,7 @@ object Test { } - def test1()(given QuoteContext): Expr[String] = Var('{"abc"}) { x => + def test1() with QuoteContext : Expr[String] = Var('{"abc"}) { x => '{ ${ x.update('{"xyz"}) } ${ x.get } diff --git a/tests/run-staging/quoted-show-name.scala b/tests/run-staging/quoted-show-name.scala index 42a42872b5e6..f7fe12f4a959 100644 --- a/tests/run-staging/quoted-show-name.scala +++ b/tests/run-staging/quoted-show-name.scala @@ -9,10 +9,10 @@ object Test { println(powerCode(77).show) } - def powerCode(n: Long)(given QuoteContext): Expr[Double => Double] = + def powerCode(n: Long) with QuoteContext : Expr[Double => Double] = '{ x1 => ${powerCode(n, 2, 'x1)} } - def powerCode(n: Long, idx: Int, x: Expr[Double])(given QuoteContext): Expr[Double] = + def powerCode(n: Long, idx: Int, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n % 2 == 0) '{ @showName(${Expr("x" + idx)}) val y = $x * $x; ${powerCode(n / 2, idx * 2, '{y})} } diff --git a/tests/run-staging/shonan-hmm-simple.scala b/tests/run-staging/shonan-hmm-simple.scala index 8a70a47f3a96..f4ab7f1eae86 100644 --- a/tests/run-staging/shonan-hmm-simple.scala +++ b/tests/run-staging/shonan-hmm-simple.scala @@ -1,6 +1,6 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} trait Ring[T] val zero: T @@ -18,7 +18,7 @@ class RingInt extends Ring[Int] val mul = (x, y) => x * y -class RingIntExpr(given QuoteContext) extends Ring[Expr[Int]] +class RingIntExpr with QuoteContext extends Ring[Expr[Int]] val zero = '{0} val one = '{1} val add = (x, y) => '{$x + $y} @@ -34,15 +34,15 @@ class RingComplex[U](u: Ring[U]) extends Ring[Complex[U]] { } sealed trait PV[T] - def expr(given Liftable[T], QuoteContext): Expr[T] + def expr with (Liftable[T], QuoteContext) : Expr[T] case class Sta[T](x: T) extends PV[T] - def expr(given Liftable[T], QuoteContext): Expr[T] = x + def expr with (Liftable[T], QuoteContext) : Expr[T] = x case class Dyn[T](x: Expr[T]) extends PV[T] - def expr(given Liftable[T], QuoteContext): Expr[T] = x + def expr with (Liftable[T], QuoteContext) : Expr[T] = x -class RingPV[U: Liftable](u: Ring[U], eu: Ring[Expr[U]])(given QuoteContext) extends Ring[PV[U]] { +class RingPV[U: Liftable](u: Ring[U], eu: Ring[Expr[U]]) with QuoteContext extends Ring[PV[U]] { val zero: PV[U] = Sta(u.zero) val one: PV[U] = Sta(u.one) val add = (x: PV[U], y: PV[U]) => (x, y) match { @@ -96,7 +96,7 @@ class StaticVecOps[T] extends VecOps[Int, T] { } } -class ExprVecOps[T: Type](given QuoteContext) extends VecOps[Expr[Int], Expr[T]] +class ExprVecOps[T: Type] with QuoteContext extends VecOps[Expr[Int], Expr[T]] val reduce: ((Expr[T], Expr[T]) => Expr[T], Expr[T], Vec[Expr[Int], Expr[T]]) => Expr[T] = (plus, zero, vec) => '{ var sum = $zero var i = 0 @@ -137,8 +137,8 @@ object Test { println(res2) println() - def blasStaticIntExpr(given QuoteContext) = new Blas1(new RingIntExpr, new StaticVecOps) - def resCode1(given QuoteContext) = blasStaticIntExpr.dot( + def blasStaticIntExpr with QuoteContext = new Blas1(new RingIntExpr, new StaticVecOps) + def resCode1 with QuoteContext = blasStaticIntExpr.dot( vec1.map(Expr(_)), vec2.map(Expr(_)) ) @@ -146,8 +146,8 @@ object Test { println(run(resCode1)) println() - def blasExprIntExpr(given QuoteContext) = new Blas1(new RingIntExpr, new ExprVecOps) - def resCode2(given QuoteContext): Expr[(Array[Int], Array[Int]) => Int] = '{ + def blasExprIntExpr with QuoteContext = new Blas1(new RingIntExpr, new ExprVecOps) + def resCode2 with QuoteContext : Expr[(Array[Int], Array[Int]) => Int] = '{ (arr1, arr2) => if (arr1.length != arr2.length) throw new Exception("...") ${ @@ -161,8 +161,8 @@ object Test { println(run(resCode2).apply(arr1, arr2)) println() - def blasStaticIntPVExpr(given QuoteContext) = new Blas1(new RingPV[Int](new RingInt, new RingIntExpr), new StaticVecOps) - def resCode3(given QuoteContext) = blasStaticIntPVExpr.dot( + def blasStaticIntPVExpr with QuoteContext = new Blas1(new RingPV[Int](new RingInt, new RingIntExpr), new StaticVecOps) + def resCode3 with QuoteContext = blasStaticIntPVExpr.dot( vec1.map(i => Dyn(i)), vec2.map(i => Sta(i)) ).expr @@ -170,8 +170,8 @@ object Test { println(run(resCode3)) println() - def blasExprIntPVExpr(given QuoteContext) = new Blas1(new RingPV[Int](new RingInt, new RingIntExpr), new StaticVecOps) - def resCode4(given QuoteContext): Expr[Array[Int] => Int] = '{ + def blasExprIntPVExpr with QuoteContext = new Blas1(new RingPV[Int](new RingInt, new RingIntExpr), new StaticVecOps) + def resCode4 with QuoteContext : Expr[Array[Int] => Int] = '{ arr => if (arr.length != ${vec2.size}) throw new Exception("...") ${ @@ -187,8 +187,8 @@ object Test { println() import Complex.isLiftable - def blasExprComplexPVInt(given QuoteContext) = new Blas1[Int, Complex[PV[Int]]](new RingComplex(new RingPV[Int](new RingInt, new RingIntExpr)), new StaticVecOps) - def resCode5(given QuoteContext): Expr[Array[Complex[Int]] => Complex[Int]] = '{ + def blasExprComplexPVInt with QuoteContext = new Blas1[Int, Complex[PV[Int]]](new RingComplex(new RingPV[Int](new RingInt, new RingIntExpr)), new StaticVecOps) + def resCode5 with QuoteContext : Expr[Array[Complex[Int]] => Complex[Int]] = '{ arr => if (arr.length != ${cmpxVec2.size}) throw new Exception("...") ${ @@ -203,12 +203,12 @@ object Test { println(run(resCode5).apply(cmpxArr1)) println() - def RingPVInt(given QuoteContext) = new RingPV[Int](new RingInt, new RingIntExpr) + def RingPVInt with QuoteContext = new RingPV[Int](new RingInt, new RingIntExpr) // Staged loop of dot product on vectors of Int or Expr[Int] - def dotIntOptExpr(given QuoteContext) = new Blas1(RingPVInt, new StaticVecOps).dot + def dotIntOptExpr with QuoteContext = new Blas1(RingPVInt, new StaticVecOps).dot // will generate the code '{ ((arr: scala.Array[scala.Int]) => arr.apply(1).+(arr.apply(3))) } - def staticVec(given QuoteContext) = Vec[Int, PV[Int]](5, i => Sta((i % 2))) - def code(given QuoteContext) = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } + def staticVec with QuoteContext = Vec[Int, PV[Int]](5, i => Sta((i % 2))) + def code with QuoteContext = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } println(withQuoteContext(code.show)) println() } diff --git a/tests/run-staging/shonan-hmm/Complex.scala b/tests/run-staging/shonan-hmm/Complex.scala index 1a884094bee7..0e834e6bb33b 100644 --- a/tests/run-staging/shonan-hmm/Complex.scala +++ b/tests/run-staging/shonan-hmm/Complex.scala @@ -8,8 +8,6 @@ object Complex { def toExpr(c: Complex[T]) = '{ Complex(${Expr(c.re)}, ${Expr(c.im)}) } } - def of_complex_expr(x: Expr[Complex[Int]])(given QuoteContext): Complex[Expr[Int]] = Complex('{$x.re}, '{$x.im}) - def of_expr_complex(x: Complex[Expr[Int]])(given QuoteContext): Expr[Complex[Int]] = '{Complex(${x.re}, ${x.im})} - - + def of_complex_expr(x: Expr[Complex[Int]]) with QuoteContext : Complex[Expr[Int]] = Complex('{$x.re}, '{$x.im}) + def of_expr_complex(x: Complex[Expr[Int]]) with QuoteContext : Expr[Complex[Int]] = '{Complex(${x.re}, ${x.im})} } \ No newline at end of file diff --git a/tests/run-staging/shonan-hmm/Lifters.scala b/tests/run-staging/shonan-hmm/Lifters.scala index 478047331112..b095975b46f7 100644 --- a/tests/run-staging/shonan-hmm/Lifters.scala +++ b/tests/run-staging/shonan-hmm/Lifters.scala @@ -3,10 +3,10 @@ import UnrolledExpr._ import scala.reflect.ClassTag import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Lifters { - implicit def LiftedClassTag[T: Type: ClassTag] (given QuoteContext): Expr[ClassTag[T]] = { + implicit def LiftedClassTag[T: Type: ClassTag] with QuoteContext : Expr[ClassTag[T]] = { '{ ClassTag(${summon[ClassTag[T]].runtimeClass })} } @@ -24,7 +24,7 @@ object Lifters { } } - private def initArray[T : Liftable : Type](arr: Array[T], array: Expr[Array[T]])(given QuoteContext): Expr[Array[T]] = { + private def initArray[T : Liftable : Type](arr: Array[T], array: Expr[Array[T]]) with QuoteContext : Expr[Array[T]] = { UnrolledExpr.block( arr.zipWithIndex.map { case (x, i) => '{ $array(${i}) = ${x} } diff --git a/tests/run-staging/shonan-hmm/MVmult.scala b/tests/run-staging/shonan-hmm/MVmult.scala index db529e952c08..ff564e8e33b5 100644 --- a/tests/run-staging/shonan-hmm/MVmult.scala +++ b/tests/run-staging/shonan-hmm/MVmult.scala @@ -1,6 +1,6 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} class MVmult[Idx, T, Unt](tring: Ring[T], vec: VecROp[Idx, T, Unt]) { private[this] val blas2 = new Blas2(tring, vec) @@ -22,7 +22,7 @@ object MVmult { MV.mvmult(vout_, a_, v_) } - def mvmult_c(given QuoteContext): Expr[(Array[Int], Array[Array[Int]], Array[Int]) => Unit] = '{ + def mvmult_c with QuoteContext : Expr[(Array[Int], Array[Array[Int]], Array[Int]) => Unit] = '{ (vout, a, v) => { val n = vout.length val m = v.length @@ -37,7 +37,7 @@ object MVmult { } } - def mvmult_mc(n: Int, m: Int)(given QuoteContext): Expr[(Array[Int], Array[Array[Int]], Array[Int]) => Unit] = { + def mvmult_mc(n: Int, m: Int) with QuoteContext : Expr[(Array[Int], Array[Array[Int]], Array[Int]) => Unit] = { val MV = new MVmult[Int, Expr[Int], Expr[Unit]](new RingIntExpr, new VecRStaDim(new RingIntExpr)) '{ (vout, a, v) => { @@ -54,7 +54,7 @@ object MVmult { } } - def mvmult_ac(a: Array[Array[Int]])(given QuoteContext): Expr[(Array[Int], Array[Int]) => Unit] = { + def mvmult_ac(a: Array[Array[Int]]) with QuoteContext : Expr[(Array[Int], Array[Int]) => Unit] = { import Lifters._ '{ val arr = ${a} @@ -65,7 +65,7 @@ object MVmult { } } - def mvmult_opt(a: Array[Array[Int]])(given QuoteContext): Expr[(Array[Int], Array[Int]) => Unit] = { + def mvmult_opt(a: Array[Array[Int]]) with QuoteContext : Expr[(Array[Int], Array[Int]) => Unit] = { import Lifters._ '{ val arr = ${a} @@ -76,7 +76,7 @@ object MVmult { } } - def mvmult_roll(a: Array[Array[Int]])(given QuoteContext): Expr[(Array[Int], Array[Int]) => Unit] = { + def mvmult_roll(a: Array[Array[Int]]) with QuoteContext : Expr[(Array[Int], Array[Int]) => Unit] = { import Lifters._ '{ val arr = ${a} @@ -87,19 +87,19 @@ object MVmult { } } - def mvmult_let1(a: Array[Array[Int]])(given QuoteContext): Expr[(Array[Int], Array[Int]) => Unit] = { + def mvmult_let1(a: Array[Array[Int]]) with QuoteContext : Expr[(Array[Int], Array[Int]) => Unit] = { val (n, m, a2) = amatCopy(a, copy_row1) mvmult_abs0(new RingIntOPExpr, new VecRStaOptDynInt(new RingIntPExpr))(n, m, a2) } - def mvmult_let(a: Array[Array[Int]])(given QuoteContext): Expr[(Array[Int], Array[Int]) => Unit] = { + def mvmult_let(a: Array[Array[Int]]) with QuoteContext : Expr[(Array[Int], Array[Int]) => Unit] = { initRows(a) { rows => val (n, m, a2) = amat2(a, rows) mvmult_abs0(new RingIntOPExpr, new VecRStaOptDynInt(new RingIntPExpr))(n, m, a2) } } - def initRows[T: Type](a: Array[Array[Int]])(cont: Array[Expr[Array[Int]]] => Expr[T])(given QuoteContext): Expr[T] = { + def initRows[T: Type](a: Array[Array[Int]])(cont: Array[Expr[Array[Int]]] => Expr[T]) with QuoteContext : Expr[T] = { import Lifters._ def loop(i: Int, acc: List[Expr[Array[Int]]]): Expr[T] = { if (i >= a.length) cont(acc.toArray.reverse) @@ -114,7 +114,7 @@ object MVmult { loop(0, Nil) } - def amat1(a: Array[Array[Int]], aa: Expr[Array[Array[Int]]])(given QuoteContext): (Int, Int, Vec[PV[Int], Vec[PV[Int], PV[Int]]]) = { + def amat1(a: Array[Array[Int]], aa: Expr[Array[Array[Int]]]) with QuoteContext : (Int, Int, Vec[PV[Int], Vec[PV[Int], PV[Int]]]) = { val n = a.length val m = a(0).length val vec: Vec[PV[Int], Vec[PV[Int], PV[Int]]] = Vec(Sta(n), i => Vec(Sta(m), j => (i, j) match { @@ -125,7 +125,7 @@ object MVmult { (n, m, vec) } - def amat2(a: Array[Array[Int]], refs: Array[Expr[Array[Int]]])(given QuoteContext): (Int, Int, Vec[PV[Int], Vec[PV[Int], PV[Int]]]) = { + def amat2(a: Array[Array[Int]], refs: Array[Expr[Array[Int]]]) with QuoteContext : (Int, Int, Vec[PV[Int], Vec[PV[Int], PV[Int]]]) = { val n = a.length val m = a(0).length val vec: Vec[PV[Int], Vec[PV[Int], PV[Int]]] = Vec(Sta(n), i => Vec(Sta(m), j => (i, j) match { @@ -135,7 +135,7 @@ object MVmult { (n, m, vec) } - def amatCopy(a: Array[Array[Int]], copyRow: Array[Int] => (Expr[Int] => Expr[Int]))(given QuoteContext): (Int, Int, Vec[PV[Int], Vec[PV[Int], PV[Int]]]) = { + def amatCopy(a: Array[Array[Int]], copyRow: Array[Int] => (Expr[Int] => Expr[Int])) with QuoteContext : (Int, Int, Vec[PV[Int], Vec[PV[Int], PV[Int]]]) = { val n = a.length val m = a(0).length val vec: Vec[PV[Int], Vec[PV[Int], PV[Int]]] = Vec(Sta(n), i => Vec(Sta(m), j => (i, j) match { @@ -148,19 +148,19 @@ object MVmult { (n, m, vec) } - def copy_row1(given QuoteContext): Array[Int] => (Expr[Int] => Expr[Int]) = v => { + def copy_row1 with QuoteContext : Array[Int] => (Expr[Int] => Expr[Int]) = v => { import Lifters._ val arr = v i => '{ ($arr).apply($i) } } - def copy_row_let(given QuoteContext): Array[Int] => (Expr[Int] => Expr[Int]) = v => { + def copy_row_let with QuoteContext : Array[Int] => (Expr[Int] => Expr[Int]) = v => { import Lifters._ val arr: Expr[Array[Int]] = ??? // FIXME used genlet v i => '{ ($arr).apply($i) } } - private def mvmult_abs0(ring: Ring[PV[Int]], vecOp: VecROp[PV[Int], PV[Int], Expr[Unit]])(n: Int, m: Int, a: Vec[PV[Int], Vec[PV[Int], PV[Int]]])(given QuoteContext): Expr[(Array[Int], Array[Int]) => Unit] = { + private def mvmult_abs0(ring: Ring[PV[Int]], vecOp: VecROp[PV[Int], PV[Int], Expr[Unit]])(n: Int, m: Int, a: Vec[PV[Int], Vec[PV[Int], PV[Int]]]) with QuoteContext : Expr[(Array[Int], Array[Int]) => Unit] = { '{ (vout, v) => { if (${n} != vout.length) throw new IndexOutOfBoundsException(${n.toString}) diff --git a/tests/run-staging/shonan-hmm/PV.scala b/tests/run-staging/shonan-hmm/PV.scala index aaec80bcfbd4..c56fc92ff4bf 100644 --- a/tests/run-staging/shonan-hmm/PV.scala +++ b/tests/run-staging/shonan-hmm/PV.scala @@ -8,9 +8,9 @@ case class Sta[T](x: T) extends PV[T] case class Dyn[T](x: Expr[T]) extends PV[T] object Dyns { - def dyn[T: Liftable](pv: PV[T])(given QuoteContext): Expr[T] = pv match { + def dyn[T: Liftable](pv: PV[T]) with QuoteContext : Expr[T] = pv match { case Sta(x) => Expr(x) case Dyn(x) => x } - def dyni(given QuoteContext): PV[Int] => Expr[Int] = dyn[Int] + def dyni with QuoteContext : PV[Int] => Expr[Int] = dyn[Int] } diff --git a/tests/run-staging/shonan-hmm/Ring.scala b/tests/run-staging/shonan-hmm/Ring.scala index 8d1e7ba6e0d1..7cde34ca3d04 100644 --- a/tests/run-staging/shonan-hmm/Ring.scala +++ b/tests/run-staging/shonan-hmm/Ring.scala @@ -24,7 +24,7 @@ object RingInt extends Ring[Int] { override def toString(): String = "RingInt" } -class RingIntExpr(given QuoteContext) extends Ring[Expr[Int]] { +class RingIntExpr with QuoteContext extends Ring[Expr[Int]] { val zero = '{0} val one = '{1} val add = (x, y) => '{$x + $y} @@ -43,7 +43,7 @@ case class RingComplex[U](u: Ring[U]) extends Ring[Complex[U]] { override def toString(): String = s"RingComplex($u)" } -case class RingPV[U: Liftable](staRing: Ring[U], dynRing: Ring[Expr[U]])(given QuoteContext) extends Ring[PV[U]] { +case class RingPV[U: Liftable](staRing: Ring[U], dynRing: Ring[Expr[U]]) with QuoteContext extends Ring[PV[U]] { type T = PV[U] val dyn = Dyns.dyn[U] @@ -66,9 +66,9 @@ case class RingPV[U: Liftable](staRing: Ring[U], dynRing: Ring[Expr[U]])(given Q } } -class RingIntPExpr(given QuoteContext) extends RingPV(RingInt, new RingIntExpr) +class RingIntPExpr with QuoteContext extends RingPV(RingInt, new RingIntExpr) -class RingIntOPExpr(given QuoteContext) extends RingIntPExpr { +class RingIntOPExpr with QuoteContext extends RingIntPExpr { override def add = (x: PV[Int], y: PV[Int]) => (x, y) match { case (Sta(0), y) => y case (x, Sta(0)) => x diff --git a/tests/run-staging/shonan-hmm/UnrolledExpr.scala b/tests/run-staging/shonan-hmm/UnrolledExpr.scala index 0ecb495322b0..c48b0d5b784a 100644 --- a/tests/run-staging/shonan-hmm/UnrolledExpr.scala +++ b/tests/run-staging/shonan-hmm/UnrolledExpr.scala @@ -8,7 +8,7 @@ object UnrolledExpr { } // TODO support blocks in the compiler to avoid creating trees of blocks? - def block[T: Type](stats: Iterable[Expr[_]], expr: Expr[T])(given QuoteContext): Expr[T] = { + def block[T: Type](stats: Iterable[Expr[_]], expr: Expr[T]) with QuoteContext : Expr[T] = { def rec(stats: List[Expr[_]]): Expr[T] = stats match { case x :: xs => '{ $x; ${rec(xs)} } case Nil => expr @@ -21,10 +21,10 @@ object UnrolledExpr { class UnrolledExpr[T: Liftable, It <: Iterable[T]](xs: It) { import UnrolledExpr._ - def foreach[U](f: T => Expr[U])(given QuoteContext): Expr[Unit] = block(xs.map(f), '{}) + def foreach[U](f: T => Expr[U]) with QuoteContext : Expr[Unit] = block(xs.map(f), '{}) - def withFilter(f: T => Boolean)(given QuoteContext): UnrolledExpr[T, Iterable[T]] = new UnrolledExpr(xs.filter(f)) + def withFilter(f: T => Boolean) with QuoteContext : UnrolledExpr[T, Iterable[T]] = new UnrolledExpr(xs.filter(f)) - def foldLeft[U](acc: Expr[U])(f: (Expr[U], T) => Expr[U])(given QuoteContext): Expr[U] = + def foldLeft[U](acc: Expr[U])(f: (Expr[U], T) => Expr[U]) with QuoteContext : Expr[U] = xs.foldLeft(acc)((acc, x) => f(acc, x)) } diff --git a/tests/run-staging/shonan-hmm/VecOp.scala b/tests/run-staging/shonan-hmm/VecOp.scala index 39f3b89272db..b0590f132206 100644 --- a/tests/run-staging/shonan-hmm/VecOp.scala +++ b/tests/run-staging/shonan-hmm/VecOp.scala @@ -12,7 +12,7 @@ class VecSta extends VecOp[Int, Unit] { override def toString(): String = s"StaticVec" } -class VecDyn(given QuoteContext) extends VecOp[Expr[Int], Expr[Unit]] { +class VecDyn with QuoteContext extends VecOp[Expr[Int], Expr[Unit]] { def iter: Vec[Expr[Int], Expr[Unit]] => Expr[Unit] = arr => '{ var i = 0 while (i < ${arr.size}) { diff --git a/tests/run-staging/shonan-hmm/VecROp.scala b/tests/run-staging/shonan-hmm/VecROp.scala index f03cc86ec09e..fbdd2468b9b1 100644 --- a/tests/run-staging/shonan-hmm/VecROp.scala +++ b/tests/run-staging/shonan-hmm/VecROp.scala @@ -1,6 +1,6 @@ import scala.quoted._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} trait VecROp[Idx, T, Unt] extends VecOp[Idx, Unt] { def reduce: ((T, T) => T, T, Vec[Idx, T]) => T @@ -17,7 +17,7 @@ class StaticVecR[T](r: Ring[T]) extends VecSta with VecROp[Int, T, Unit] { override def toString(): String = s"StaticVecR($r)" } -class VecRDyn[T: Type](given QuoteContext) extends VecDyn with VecROp[Expr[Int], Expr[T], Expr[Unit]] { +class VecRDyn[T: Type] with QuoteContext extends VecDyn with VecROp[Expr[Int], Expr[T], Expr[Unit]] { def reduce: ((Expr[T], Expr[T]) => Expr[T], Expr[T], Vec[Expr[Int], Expr[T]]) => Expr[T] = { (plus, zero, vec) => '{ var sum = $zero @@ -32,7 +32,7 @@ class VecRDyn[T: Type](given QuoteContext) extends VecDyn with VecROp[Expr[Int], override def toString(): String = s"VecRDyn" } -class VecRStaDim[T: Type](r: Ring[T])(given QuoteContext) extends VecROp[Int, T, Expr[Unit]] { +class VecRStaDim[T: Type](r: Ring[T]) with QuoteContext extends VecROp[Int, T, Expr[Unit]] { val M = new StaticVecR[T](r) def reduce: ((T, T) => T, T, Vec[Int, T]) => T = M.reduce val seq: (Expr[Unit], Expr[Unit]) => Expr[Unit] = (e1, e2) => '{ $e1; $e2 } @@ -46,7 +46,7 @@ class VecRStaDim[T: Type](r: Ring[T])(given QuoteContext) extends VecROp[Int, T, override def toString(): String = s"VecRStaDim($r)" } -class VecRStaDyn[T : Type : Liftable](r: Ring[PV[T]])(given QuoteContext) extends VecROp[PV[Int], PV[T], Expr[Unit]] { +class VecRStaDyn[T : Type : Liftable](r: Ring[PV[T]]) with QuoteContext extends VecROp[PV[Int], PV[T], Expr[Unit]] { val VSta: VecROp[Int, PV[T], Expr[Unit]] = new VecRStaDim(r) val VDyn = new VecRDyn val dyn = Dyns.dyn[T] @@ -74,7 +74,7 @@ object VecRStaOptDynInt { val threshold = 3 } -class VecRStaOptDynInt(r: Ring[PV[Int]]) (given QuoteContext) extends VecRStaDyn(r) { +class VecRStaOptDynInt(r: Ring[PV[Int]]) with QuoteContext extends VecRStaDyn(r) { val M: VecROp[PV[Int], PV[Int], Expr[Unit]] = new VecRStaDyn(r) override def reduce: ((PV[Int], PV[Int]) => PV[Int], PV[Int], Vec[PV[Int], PV[Int]]) => PV[Int] = (plus, zero, vec) => vec match { diff --git a/tests/run-staging/shonan-hmm/Vmults.scala b/tests/run-staging/shonan-hmm/Vmults.scala index 4d365b635b17..fcd63e52ec3b 100644 --- a/tests/run-staging/shonan-hmm/Vmults.scala +++ b/tests/run-staging/shonan-hmm/Vmults.scala @@ -19,7 +19,7 @@ object Vmults { V.vmult(vout_, v1_, v2_) } - def vmultCA(given QuoteContext): Expr[(Array[Complex[Int]], Array[Complex[Int]], Array[Complex[Int]]) => Unit] = '{ + def vmultCA with QuoteContext : Expr[(Array[Complex[Int]], Array[Complex[Int]], Array[Complex[Int]]) => Unit] = '{ (vout, v1, v2) => { val n = vout.length ${ diff --git a/tests/run-staging/staged-streams_1.scala b/tests/run-staging/staged-streams_1.scala index eb446aa8973a..d99f707a8a03 100644 --- a/tests/run-staging/staged-streams_1.scala +++ b/tests/run-staging/staged-streams_1.scala @@ -1,14 +1,14 @@ import scala.quoted._ import scala.quoted.staging._ import scala.quoted.util._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} /** * Port of the strymonas library as described in O. Kiselyov et al., Stream fusion, to completeness (POPL 2017) */ object Test { - type E[T] = (given QuoteContext) => Expr[T] + type E[T] = QuoteContext ?=> Expr[T] /*** Producer represents a linear production of values with a loop structure. * @@ -205,7 +205,7 @@ object Test { * @return a new stream consisting of all elements of the input stream that do satisfy the given * predicate `pred`. */ - def filter(pred: (Expr[A] => Expr[Boolean]))(given QuoteContext): Stream[A] = { + def filter(pred: (Expr[A] => Expr[Boolean])) with QuoteContext : Stream[A] = { val filterStream = (a: Expr[A]) => new Producer[Expr[A]] { @@ -305,7 +305,7 @@ object Test { * @tparam A the type of the producer's elements. * @return a linear or nested stream aware of the variable reference to decrement. */ - private def takeRaw[A: Type](n: Expr[Int], stream: StagedStream[A])(given QuoteContext): StagedStream[A] = { + private def takeRaw[A: Type](n: Expr[Int], stream: StagedStream[A]) with QuoteContext : StagedStream[A] = { stream match { case linear: Linear[A] => { val enhancedProducer: Producer[(Var[Int], A)] = addCounter[A](n, linear.producer) @@ -334,9 +334,9 @@ object Test { } /** A stream containing the first `n` elements of this stream. */ - def take(n: Expr[Int])(given QuoteContext): Stream[A] = Stream(takeRaw[Expr[A]](n, stream)) + def take(n: Expr[Int]) with QuoteContext : Stream[A] = Stream(takeRaw[Expr[A]](n, stream)) - private def zipRaw[A: Type, B: Type](stream1: StagedStream[Expr[A]], stream2: StagedStream[B])(given QuoteContext): StagedStream[(Expr[A], B)] = { + private def zipRaw[A: Type, B: Type](stream1: StagedStream[Expr[A]], stream2: StagedStream[B]) with QuoteContext : StagedStream[(Expr[A], B)] = { (stream1, stream2) match { case (Linear(producer1), Linear(producer2)) => @@ -404,7 +404,7 @@ object Test { * @tparam A * @return */ - private def makeLinear[A: Type](stream: StagedStream[Expr[A]])(given QuoteContext): Producer[Expr[A]] = { + private def makeLinear[A: Type](stream: StagedStream[Expr[A]]) with QuoteContext : Producer[Expr[A]] = { stream match { case Linear(producer) => producer case Nested(producer, nestedf) => { @@ -507,7 +507,7 @@ object Test { } } - private def pushLinear[A, B, C](producer: Producer[A], nestedProducer: Producer[B], nestedf: (B => StagedStream[C]))(given QuoteContext): StagedStream[(A, C)] = { + private def pushLinear[A, B, C](producer: Producer[A], nestedProducer: Producer[B], nestedf: (B => StagedStream[C])) with QuoteContext : StagedStream[(A, C)] = { val newProducer = new Producer[(Var[Boolean], producer.St, B)] { type St = (Var[Boolean], producer.St, nestedProducer.St) @@ -565,14 +565,14 @@ object Test { } /** zip **/ - def zip[B: Type, C: Type](f: (Expr[A] => Expr[B] => Expr[C]), stream2: Stream[B])(given QuoteContext): Stream[C] = { + def zip[B: Type, C: Type](f: (Expr[A] => Expr[B] => Expr[C]), stream2: Stream[B]) with QuoteContext : Stream[C] = { val Stream(stream_b) = stream2 Stream(mapRaw[(Expr[A], Expr[B]), Expr[C]]((t => k => k(f(t._1)(t._2))), zipRaw[A, Expr[B]](stream, stream_b))) } } object Stream { - def of[A: Type](arr: Expr[Array[A]])(given QuoteContext): Stream[A] = { + def of[A: Type](arr: Expr[Array[A]]) with QuoteContext : Stream[A] = { val prod = new Producer[Expr[A]] { type St = (Var[Int], Var[Int], Expr[Array[A]]) @@ -607,52 +607,52 @@ object Test { } } - def test1()(given QuoteContext) = Stream + def test1() with QuoteContext = Stream .of('{Array(1, 2, 3)}) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test2()(given QuoteContext) = Stream + def test2() with QuoteContext = Stream .of('{Array(1, 2, 3)}) .map((a: Expr[Int]) => '{ $a * 2 }) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test3()(given QuoteContext) = Stream + def test3() with QuoteContext = Stream .of('{Array(1, 2, 3)}) .flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).map((dp: Expr[Int]) => '{ $d * $dp })) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test4()(given QuoteContext) = Stream + def test4() with QuoteContext = Stream .of('{Array(1, 2, 3)}) .filter((d: Expr[Int]) => '{ $d % 2 == 0 }) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test5()(given QuoteContext) = Stream + def test5() with QuoteContext = Stream .of('{Array(1, 2, 3)}) .take('{2}) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test6()(given QuoteContext) = Stream + def test6() with QuoteContext = Stream .of('{Array(1, 1, 1)}) .flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).take('{2})) .take('{5}) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test7()(given QuoteContext) = Stream + def test7() with QuoteContext = Stream .of('{Array(1, 2, 3)}) .zip(((a : Expr[Int]) => (b : Expr[Int]) => '{ $a + $b }), Stream.of('{Array(1, 2, 3)})) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test8()(given QuoteContext) = Stream + def test8() with QuoteContext = Stream .of('{Array(1, 2, 3)}) .zip(((a : Expr[Int]) => (b : Expr[Int]) => '{ $a + $b }), Stream.of('{Array(1, 2, 3)}).flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).map((dp: Expr[Int]) => '{ $d + $dp }))) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test9()(given QuoteContext) = Stream + def test9() with QuoteContext = Stream .of('{Array(1, 2, 3)}).flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).map((dp: Expr[Int]) => '{ $d + $dp })) .zip(((a : Expr[Int]) => (b : Expr[Int]) => '{ $a + $b }), Stream.of('{Array(1, 2, 3)}) ) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) - def test10()(given QuoteContext) = Stream + def test10() with QuoteContext = Stream .of('{Array(1, 2, 3)}).flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).map((dp: Expr[Int]) => '{ $d + $dp })) .zip(((a : Expr[Int]) => (b : Expr[Int]) => '{ $a + $b }), Stream.of('{Array(1, 2, 3)}).flatMap((d: Expr[Int]) => Stream.of('{Array(1, 2, 3)}).map((dp: Expr[Int]) => '{ $d + $dp })) ) .fold('{0}, ((a: Expr[Int], b : Expr[Int]) => '{ $a + $b })) diff --git a/tests/run-staging/staged-tuples/StagedTuple.scala b/tests/run-staging/staged-tuples/StagedTuple.scala index 7455af47ea5e..765b320323d2 100644 --- a/tests/run-staging/staged-tuples/StagedTuple.scala +++ b/tests/run-staging/staged-tuples/StagedTuple.scala @@ -12,7 +12,7 @@ object StagedTuple { private final val specialize = true - def toArrayStaged(tup: Expr[Tuple], size: Option[Int])(given QuoteContext): Expr[Array[Object]] = { + def toArrayStaged(tup: Expr[Tuple], size: Option[Int]) with QuoteContext : Expr[Array[Object]] = { if (!specialize) '{dynamicToArray($tup)} else size match { case Some(0) => @@ -34,7 +34,7 @@ object StagedTuple { } } - def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int])(given QuoteContext): Expr[T] = { + def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int]) with QuoteContext : Expr[T] = { if (!specialize) '{dynamicFromArray[T]($xs)} else xs.bind { xs => val tup: Expr[Any] = size match { @@ -68,7 +68,7 @@ object StagedTuple { } } - def sizeStaged[Res <: Int : Type](tup: Expr[Tuple], size: Option[Int])(given QuoteContext): Expr[Res] = { + def sizeStaged[Res <: Int : Type](tup: Expr[Tuple], size: Option[Int]) with QuoteContext : Expr[Res] = { val res = if (!specialize) '{dynamicSize($tup)} else size match { @@ -78,7 +78,7 @@ object StagedTuple { res.as[Res] } - def headStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int])(given QuoteContext): Expr[Head[Tup]] = { + def headStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int]) with QuoteContext : Expr[Head[Tup]] = { if (!specialize) '{dynamicApply[Tup, 0]($tup, 0)} else { val resVal = size match { @@ -101,7 +101,7 @@ object StagedTuple { } } - def tailStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int])(given QuoteContext): Expr[Tail[Tup]] = { + def tailStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int]) with QuoteContext : Expr[Tail[Tup]] = { if (!specialize) '{dynamicTail[Tup]($tup)} else { val res = size match { @@ -125,7 +125,7 @@ object StagedTuple { } } - def applyStaged[Tup <: NonEmptyTuple : Type, N <: Int : Type](tup: Expr[Tup], size: Option[Int], n: Expr[N], nValue: Option[Int])(given qctx: QuoteContext): Expr[Elem[Tup, N]] = { + def applyStaged[Tup <: NonEmptyTuple : Type, N <: Int : Type](tup: Expr[Tup], size: Option[Int], n: Expr[N], nValue: Option[Int]) with (qctx: QuoteContext) : Expr[Elem[Tup, N]] = { import reflect._ if (!specialize) '{dynamicApply($tup, $n)} @@ -185,7 +185,7 @@ object StagedTuple { } } - def consStaged[T <: Tuple & Singleton : Type, H : Type](self: Expr[T], x: Expr[H], tailSize: Option[Int])(given QuoteContext): Expr[H *: T] = + def consStaged[T <: Tuple & Singleton : Type, H : Type](self: Expr[T], x: Expr[H], tailSize: Option[Int]) with QuoteContext : Expr[H *: T] = if (!specialize) '{dynamicCons[H, T]($x, $self)} else { val res = tailSize match { @@ -207,7 +207,7 @@ object StagedTuple { res.as[H *: T] } - def concatStaged[Self <: Tuple & Singleton : Type, That <: Tuple & Singleton : Type](self: Expr[Self], selfSize: Option[Int], that: Expr[That], thatSize: Option[Int])(given QuoteContext): Expr[Concat[Self, That]] = { + def concatStaged[Self <: Tuple & Singleton : Type, That <: Tuple & Singleton : Type](self: Expr[Self], selfSize: Option[Int], that: Expr[That], thatSize: Option[Int]) with QuoteContext : Expr[Concat[Self, That]] = { if (!specialize) '{dynamicConcat[Self, That]($self, $that)} else { def genericConcat(xs: Expr[Tuple], ys: Expr[Tuple]): Expr[Tuple] = @@ -258,9 +258,9 @@ object StagedTuple { private implicit class ExprOps[U: Type](expr: Expr[U]) { - def as[T: Type](given QuoteContext): Expr[T] = '{ $expr.asInstanceOf[T] } + def as[T: Type] with QuoteContext : Expr[T] = '{ $expr.asInstanceOf[T] } - def bind[T: Type](in: Expr[U] => Expr[T])(given QuoteContext): Expr[T] = '{ + def bind[T: Type](in: Expr[U] => Expr[T]) with QuoteContext : Expr[T] = '{ val t: U = $expr ${in('t)} } diff --git a/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala b/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala index cb7bc0fd688f..617ae13e8b6c 100644 --- a/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-staging/tasty-extractors-constants-2/quoted_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ import scala.quoted.staging._ -import scala.quoted.autolift.given +import scala.quoted.autolift.{given _} object Macros { inline def testMacro: Unit = ${impl} - def impl(given QuoteContext): Expr[Unit] = { + def impl with QuoteContext : Expr[Unit] = { given Toolbox = Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant val show1 = withQuoteContext(power(2, 3.0).show) @@ -22,7 +22,7 @@ object Macros { val run3 = run(power('{2}, 5.0)) // n2 is not a constant - def n2(given QuoteContext) = '{ println("foo"); 2 } + def n2 with QuoteContext = '{ println("foo"); 2 } val show4 = withQuoteContext(power(n2, 6.0).show) val run4 = run(power(n2, 6.0)) @@ -41,7 +41,7 @@ object Macros { } } - def power(n: Expr[Int], x: Expr[Double])(given QuoteContext): Expr[Double] = { + def power(n: Expr[Int], x: Expr[Double]) with QuoteContext : Expr[Double] = { import quoted.matching.Const n match { case Const(n1) => powerCode(n1, x) @@ -49,7 +49,7 @@ object Macros { } } - def powerCode(n: Int, x: Expr[Double])(given QuoteContext): Expr[Double] = + def powerCode(n: Int, x: Expr[Double]) with QuoteContext : Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala index 9a1bdd9c6c64..e73846f25780 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala @@ -6,7 +6,7 @@ import scala.tasty.file.TastyConsumer class TastyInterpreter extends TastyConsumer { final def apply(reflect: Reflection)(root: reflect.Tree): Unit = { - import reflect.{_, given} + import reflect.{_, given _} object Traverser extends TreeTraverser { override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match { @@ -14,7 +14,7 @@ class TastyInterpreter extends TastyConsumer { case DefDef("main", _, _, _, Some(rhs)) => val interpreter = new jvm.Interpreter(reflect) - interpreter.eval(rhs)(given Map.empty) + interpreter.eval(rhs).with(Map.empty) // TODO: recurse only for PackageDef, ClassDef case tree => super.traverseTree(tree) diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala index 499ce7aa014d..eab43e09e177 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala @@ -4,7 +4,7 @@ import scala.tasty.interpreter.jvm.JVMReflection import scala.tasty.Reflection abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) { - import reflect.{_, given} + import reflect.{_, given _} final val LOG = false @@ -13,15 +13,15 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) { /** Representation of objects and values in the interpreter */ type AbstractAny - type Result = (given Env) => AbstractAny + type Result = Env ?=> AbstractAny def localValue(sym: Symbol)(implicit env: Env): LocalValue = env(sym) - def withLocalValue[T](sym: Symbol, value: LocalValue)(in: (given Env) => T)(implicit env: Env): T = - in(given env.updated(sym, value)) + def withLocalValue[T](sym: Symbol, value: LocalValue)(in: Env ?=> T)(implicit env: Env): T = + in.with(env.updated(sym, value)) - def withLocalValues[T](syms: List[Symbol], values: List[LocalValue])(in: (given Env) => T)(implicit env: Env): T = - in(given env ++ syms.zip(values)) + def withLocalValues[T](syms: List[Symbol], values: List[LocalValue])(in: Env ?=> T)(implicit env: Env): T = + in.with(env ++ syms.zip(values)) def interpretCall(inst: AbstractAny, sym: Symbol, args: List[AbstractAny]): Result = { // TODO @@ -68,7 +68,7 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) { def interpretBlock(stats: List[Statement], expr: Term): Result = { val newEnv = stats.foldLeft(implicitly[Env])((accEnv, stat) => stat match { case ValDef(name, tpt, Some(rhs)) => - def evalRhs = eval(rhs)(given accEnv) + def evalRhs = eval(rhs).with(accEnv) val evalRef: LocalValue = if (stat.symbol.flags.is(Flags.Lazy)) LocalValue.lazyValFrom(evalRhs) else if (stat.symbol.flags.is(Flags.Mutable)) LocalValue.varFrom(evalRhs) @@ -79,10 +79,10 @@ abstract class TreeInterpreter[R <: Reflection & Singleton](val reflect: R) { // TODO: record the environment for closure purposes accEnv case stat => - eval(stat)(given accEnv) + eval(stat).with(accEnv) accEnv }) - eval(expr)(given newEnv) + eval(expr).with(newEnv) } def interpretUnit(): AbstractAny diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala index 06ea08ae67fd..aa822ad7b73f 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala @@ -5,7 +5,7 @@ import scala.tasty.interpreter.jvm.JVMReflection import scala.tasty.Reflection class Interpreter[R <: Reflection & Singleton](reflect0: R) extends TreeInterpreter[R](reflect0) { - import reflect.{_, given} + import reflect.{_, given _} // All references are represented by themselves and values are boxed type AbstractAny = Any diff --git a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala index 7b505880bbff..b38091b8c494 100644 --- a/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala +++ b/tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/jvm/JVMReflection.scala @@ -3,7 +3,7 @@ package scala.tasty.interpreter.jvm import scala.tasty.Reflection class JVMReflection[R <: Reflection & Singleton](val reflect: R) { - import reflect.{_, given} + import reflect.{_, given _} import java.lang.reflect.{InvocationTargetException, Method} private val classLoader: ClassLoader = getClass.getClassLoader diff --git a/tests/run-with-compiler/BigFloat/BigFloat_1.scala b/tests/run-with-compiler/BigFloat/BigFloat_1.scala index 0ef14e84c20d..b4c790579038 100644 --- a/tests/run-with-compiler/BigFloat/BigFloat_1.scala +++ b/tests/run-with-compiler/BigFloat/BigFloat_1.scala @@ -30,7 +30,7 @@ object BigFloat extends App { BigFloat(BigInt(intPart), exponent) } - private def fromDigitsImpl(digits: Expr[String])(given ctx: QuoteContext): Expr[BigFloat] = + private def fromDigitsImpl(digits: Expr[String]) with (ctx: QuoteContext) : Expr[BigFloat] = digits match { case Const(ds) => try { diff --git a/tests/run-with-compiler/i6201/macro_1.scala b/tests/run-with-compiler/i6201/macro_1.scala index 9343f9ebb361..cf3472856ca2 100644 --- a/tests/run-with-compiler/i6201/macro_1.scala +++ b/tests/run-with-compiler/i6201/macro_1.scala @@ -3,12 +3,12 @@ import scala.quoted._ inline def (inline x: String) strip: String = ${ stripImpl(x) } -def stripImpl(x: String)(given qctx: QuoteContext): Expr[String] = +def stripImpl(x: String) with (qctx: QuoteContext) : Expr[String] = Expr(x.stripMargin) inline def isHello(inline x: String): Boolean = ${ isHelloImpl(x) } -def isHelloImpl(x: String)(given qctx: QuoteContext): Expr[Boolean] = +def isHelloImpl(x: String) with (qctx: QuoteContext) : Expr[Boolean] = if (x == "hello") Expr(true) else Expr(false) diff --git a/tests/run-with-compiler/i6270/Macro_1.scala b/tests/run-with-compiler/i6270/Macro_1.scala index 0b8b16ab5124..ab0e44e83894 100644 --- a/tests/run-with-compiler/i6270/Macro_1.scala +++ b/tests/run-with-compiler/i6270/Macro_1.scala @@ -5,16 +5,16 @@ object api { inline def (x: => String) reflect : String = ${ reflImpl('x) } - private def reflImpl(x: Expr[String])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def reflImpl(x: Expr[String]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} Expr(x.show) } inline def (x: => String) reflectColor : String = ${ reflImplColor('x) } - private def reflImplColor(x: Expr[String])(given qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + private def reflImplColor(x: Expr[String]) with (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty.{_, given _} Expr(x.show(ANSI)) } } diff --git a/tests/run-with-compiler/reflect-sourceCode/Macro_1.scala b/tests/run-with-compiler/reflect-sourceCode/Macro_1.scala index ec6d11ac2698..75efd83f5809 100644 --- a/tests/run-with-compiler/reflect-sourceCode/Macro_1.scala +++ b/tests/run-with-compiler/reflect-sourceCode/Macro_1.scala @@ -5,7 +5,7 @@ object api { ${ reflImpl('x) } private def reflImpl[T](x: Expr[T])(implicit qctx: QuoteContext): Expr[String] = { - import qctx.tasty.{_, given} + import qctx.tasty.{_, given _} Expr(x.unseal.pos.sourceCode) } } diff --git a/tests/run-with-compiler/tasty-comment-consumer/Test.scala b/tests/run-with-compiler/tasty-comment-consumer/Test.scala index afe07c067528..0980dc5d6a32 100644 --- a/tests/run-with-compiler/tasty-comment-consumer/Test.scala +++ b/tests/run-with-compiler/tasty-comment-consumer/Test.scala @@ -10,7 +10,7 @@ object Test { class CommentConsumer extends TastyConsumer { final def apply(reflect: Reflection)(root: reflect.Tree): Unit = { - import reflect.{_, given} + import reflect.{_, given _} object Traverser extends TreeTraverser { override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match { diff --git a/tests/run-with-compiler/tasty-consumer/Test.scala b/tests/run-with-compiler/tasty-consumer/Test.scala index ecbde79572e6..87e4aab461e7 100644 --- a/tests/run-with-compiler/tasty-consumer/Test.scala +++ b/tests/run-with-compiler/tasty-consumer/Test.scala @@ -10,7 +10,7 @@ object Test { class DBConsumer extends TastyConsumer { final def apply(reflect: Reflection)(root: reflect.Tree): Unit = { - import reflect.{_, given} + import reflect.{_, given _} object Traverser extends TreeTraverser { override def traverseTree(tree: Tree)(implicit ctx: Context): Unit = tree match { diff --git a/tests/run/Signals.scala b/tests/run/Signals.scala index 0a0862815068..b9cec0b1000e 100644 --- a/tests/run/Signals.scala +++ b/tests/run/Signals.scala @@ -2,17 +2,17 @@ import annotation.unchecked._ package frp: - sealed class Signal[+T](expr: (given Signal.Caller) => T): + sealed class Signal[+T](expr: Signal.Caller ?=> T): private var myExpr: Signal.Caller => T = _ private var myValue: T = _ private var observers: Set[Signal.Caller] = Set() changeTo(expr) - protected def changeTo(expr: (given Signal.Caller) => T @uncheckedVariance): Unit = - myExpr = (caller => expr(given caller)) + protected def changeTo(expr: Signal.Caller ?=> T @uncheckedVariance): Unit = + myExpr = (caller => expr.with(caller)) computeValue() - def apply()(given caller: Signal.Caller) = + def apply() with (caller: Signal.Caller) = observers += caller assert(!caller.observers.contains(this), "cyclic signal definition") myValue @@ -28,12 +28,12 @@ package frp: object Signal: type Caller = Signal[?] - given noCaller: Caller(???): + given noCaller as Caller(???): override def computeValue() = () end Signal - class Var[T](expr: (given Signal.Caller) => T) extends Signal[T](expr): - def update(expr: (given Signal.Caller) => T): Unit = changeTo(expr) + class Var[T](expr: Signal.Caller ?=> T) extends Signal[T](expr): + def update(expr: Signal.Caller ?=> T): Unit = changeTo(expr) end Var end frp diff --git a/tests/run/Signals1.scala b/tests/run/Signals1.scala index 978c85b3b4e8..30fffdae5878 100644 --- a/tests/run/Signals1.scala +++ b/tests/run/Signals1.scala @@ -3,7 +3,7 @@ import annotation.unchecked._ package frp: trait Signal[+T]: - def apply()(given caller: Signal.Caller): T + def apply() with (caller: Signal.Caller) : T object Signal: @@ -22,28 +22,28 @@ package frp: observers = Set() obs.foreach(_.computeValue()) - def apply()(given caller: Caller): T = + def apply() with (caller: Caller) : T = observers += caller assert(!caller.observers.contains(this), "cyclic signal definition") currentValue end AbstractSignal - def apply[T](expr: (given Caller) => T): Signal[T] = + def apply[T](expr: Caller ?=> T): Signal[T] = new AbstractSignal[T]: - protected val eval = expr(given _) + protected val eval = expr.with(_) computeValue() - class Var[T](expr: (given Caller) => T) extends AbstractSignal[T]: - protected var eval: Caller => T = expr(given _) + class Var[T](expr: Caller ?=> T) extends AbstractSignal[T]: + protected var eval: Caller => T = expr.with(_) computeValue() - def update(expr: (given Caller) => T): Unit = - eval = expr(given _) + def update(expr: Caller ?=> T): Unit = + eval = expr.with(_) computeValue() end Var opaque type Caller = AbstractSignal[?] - given noCaller: Caller = new AbstractSignal[Nothing]: + given noCaller as Caller = new AbstractSignal[Nothing]: override def eval = ??? override def computeValue() = () diff --git a/tests/run/builder.scala b/tests/run/builder.scala index 120fa0389026..8202cedc8cf9 100644 --- a/tests/run/builder.scala +++ b/tests/run/builder.scala @@ -16,13 +16,13 @@ case class Cell(elem: String) object Test { - def table(init: (given Table) => Unit) = { + def table(init: Table ?=> Unit) = { implicit val t = new Table init t } - def row(init: (given Row) => Unit)(implicit t: Table) = { + def row(init: Row ?=> Unit)(implicit t: Table) = { implicit val r = new Row init t.add(r) diff --git a/tests/run/cochis-example.scala b/tests/run/cochis-example.scala index ece509c23568..ff7a57955be9 100644 --- a/tests/run/cochis-example.scala +++ b/tests/run/cochis-example.scala @@ -1,11 +1,11 @@ import Predef.{$conforms => _} trait A { - given id[X] : (X => X) = x => x - def trans[X](x: X)(given f: X => X) = f(x) // (2) + given id[X] as (X => X) = x => x + def trans[X](x: X) with (f: X => X) = f(x) // (2) } object Test extends A with App{ - given succ : (Int => Int) = x => x + 1 // (3) + given succ as (Int => Int) = x => x + 1 // (3) def bad[X](x: X): X = trans[X](x) // (4) unstable definition ! val v1 = bad [Int] (3) // (5) evaluates to 3 assert(v1 == 3) diff --git a/tests/run/colltest6/CollectionStrawMan6_1.scala b/tests/run/colltest6/CollectionStrawMan6_1.scala index 3e045c8cd722..c102582ff816 100644 --- a/tests/run/colltest6/CollectionStrawMan6_1.scala +++ b/tests/run/colltest6/CollectionStrawMan6_1.scala @@ -754,11 +754,11 @@ object CollectionStrawMan6 extends LowPriority { def elemTag: ClassTag[A] = ClassTag(xs.getClass.getComponentType) - protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A](elemTag) + protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A].with(elemTag) def fromIterable[B: ClassTag](coll: Iterable[B]): Array[B] = coll.toArray[B] - protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(elemTag)) + protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray.with(elemTag)) override def knownSize = xs.length diff --git a/tests/run/config.scala b/tests/run/config.scala index efc516ebaae4..7e04e50f10e4 100644 --- a/tests/run/config.scala +++ b/tests/run/config.scala @@ -29,13 +29,13 @@ object Imperative { ).onError(None) def main(args: Array[String]) = { - println(readPerson(given Config("John Doe", 20))) - println(readPerson(given Config("Incognito", 99))) + println(readPerson.with(Config("John Doe", 20))) + println(readPerson.with(Config("Incognito", 99))) } } object Configs { - type Configured[T] = (given Config) => T + type Configured[T] = Config ?=> T def config: Configured[Config] = implicitly[Config] } @@ -47,7 +47,7 @@ object Exceptions { private[Exceptions] def throwE() = throw new E } - type Possibly[T] = (given CanThrow) => T + type Possibly[T] = CanThrow ?=> T def require(p: Boolean)(implicit ct: CanThrow): Unit = if (!p) ct.throwE() @@ -56,7 +56,7 @@ object Exceptions { class OnError[T](op: Possibly[T]) { def onError(fallback: => T): T = - try op(given new CanThrow) + try op.with(new CanThrow) catch { case ex: E => fallback } } } @@ -85,8 +85,8 @@ object Test extends App { val config1 = Config("John Doe", 20) val config2 = Config("Incognito", 99) - println(readPerson(given config1)) - println(readPerson(given config2)) + println(readPerson.with(config1)) + println(readPerson.with(config2)) } object OptionTest extends App { diff --git a/tests/run/eff-dependent.scala b/tests/run/eff-dependent.scala index dc7bf7660d5d..a90ad721ef6a 100644 --- a/tests/run/eff-dependent.scala +++ b/tests/run/eff-dependent.scala @@ -5,7 +5,7 @@ object Test extends App { // Type X => Y abstract class Fun[-X, +Y] { type Eff <: Effect - def apply(x: X): (given Eff) => Y + def apply(x: X): Eff ?=> Y } class CanThrow extends Effect @@ -18,18 +18,18 @@ object Test extends App { implicit val ci: CanIO = new CanIO // def map(f: A => B)(xs: List[A]): List[B] - def map[A, B](f: Fun[A, B])(xs: List[A]): (given f.Eff) => List[B] = + def map[A, B](f: Fun[A, B])(xs: List[A]): f.Eff ?=> List[B] = xs.map(f.apply) // def mapFn[A, B]: (A => B) -> List[A] -> List[B] - def mapFn[A, B]: (f: Fun[A, B]) => List[A] => (given f.Eff) => List[B] = + def mapFn[A, B]: (f: Fun[A, B]) => List[A] => f.Eff ?=> List[B] = f => xs => map(f)(xs) // def compose(f: A => B)(g: B => C)(x: A): C - def compose[A, B, C](f: Fun[A, B])(g: Fun[B, C])(x: A): (given f.Eff) => (given g.Eff) => C = g(f(x)) + def compose[A, B, C](f: Fun[A, B])(g: Fun[B, C])(x: A): f.Eff ?=> g.Eff ?=> C = g(f(x)) // def composeFn: (A => B) -> (B => C) -> A -> C - def composeFn[A, B, C]: (f: Fun[A, B]) => (g: Fun[B, C]) => A => (given f.Eff) => (given g.Eff) => C = + def composeFn[A, B, C]: (f: Fun[A, B]) => (g: Fun[B, C]) => A => f.Eff ?=> g.Eff ?=> C = f => g => x => compose(f)(g)(x) assert(mapFn(i2s)(List(1, 2, 3)).mkString == "123") diff --git a/tests/run/exports.scala b/tests/run/exports.scala index 54ca2235fee7..288cc70aa880 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 - given config : Config + given config as Config } class Scanner { diff --git a/tests/run/extmethod-overload.scala b/tests/run/extmethod-overload.scala index 463cee98cc6e..edb88dd90990 100644 --- a/tests/run/extmethod-overload.scala +++ b/tests/run/extmethod-overload.scala @@ -22,7 +22,7 @@ object Test extends App { // Test with extension methods in given object object test1 { - given Foo: AnyRef { + given Foo as AnyRef { def (x: Int) |+| (y: Int) = x + y def (x: Int) |+| (y: String) = x + y.length @@ -61,7 +61,7 @@ object Test extends App { def [T](xs: List[T]) +++ (ys: List[T]): List[T] = xs ++ ys ++ ys def [T](xs: List[T]) +++ (ys: Iterator[T]): List[T] = xs ++ ys ++ ys } - given Bar : Foo + given Bar as Foo assert((1 |+| 2) == 3) assert((1 |+| "2") == 2) diff --git a/tests/run/extmethods2.scala b/tests/run/extmethods2.scala index a45a4b5abfdd..b975d8d7bbde 100644 --- a/tests/run/extmethods2.scala +++ b/tests/run/extmethods2.scala @@ -2,18 +2,18 @@ object Test extends App { class TC - given stringListOps: TC => Object { + given stringListOps with TC as Object { type T = List[String] def (x: T).foo(y: T) = (x ++ y, summon[TC]) def (x: T).bar(y: Int) = (x(0)(y), summon[TC]) } - def test(given TC) = { + def test with TC = { assert(List("abc").foo(List("def"))._1 == List("abc", "def")) assert(List("abc").bar(2)._1 == 'c') } - test(given TC()) + test.with(TC()) object A { extension listOps on [T](xs: List[T]) { @@ -30,7 +30,7 @@ object Test extends App { } object B { - import A.given + import A.{given _} val xs = List(1, 2, 3) assert(xs.second[Int] == 2) assert(xs.third == 3) diff --git a/tests/run/given-eta.scala b/tests/run/given-eta.scala index 29d9893c477f..cbc1e73713a0 100644 --- a/tests/run/given-eta.scala +++ b/tests/run/given-eta.scala @@ -4,8 +4,8 @@ trait D type T def trans(other: T): T -def f(x: Int)(given c: C)(y: Int) = x + c.x + y -def g(x: Int)(given d: D)(y: d.T): d.T = d.trans(y) +def f(x: Int) with (c: C) (y: Int) = x + c.x + y +def g(x: Int) with (d: D) (y: d.T): d.T = d.trans(y) @main def Test = given C(1) diff --git a/tests/run/i2146.scala b/tests/run/i2146.scala index 5a7b2bcf2dcb..9b5e8a7f8413 100644 --- a/tests/run/i2146.scala +++ b/tests/run/i2146.scala @@ -2,12 +2,12 @@ object Test { case class A() case class B() - def simple[A]: (given A) => A = implicitly[A] + def simple[A]: A ?=> A = implicitly[A] - def foo[A, B]: (given A) => (given B) => (A, B) = + def foo[A, B]: A ?=> B ?=> (A, B) = (implicitly[A], implicitly[B]) - def bar[A, B]: (given A) => (given B) => (A, B) = {(given a: A) => + def bar[A, B]: A ?=> B ?=> (A, B) = {(a: A) ?=> (implicitly[A], implicitly[B]) } @@ -16,17 +16,17 @@ object Test { def main(args: Array[String]) = { println(foo[A, B]) - println(foo[A, B](given a)) - println(foo(given a)(given b)) - val s: (given A) => A = simple[A] + println(foo[A, B].with(a)) + println(foo.with(a).with(b)) + val s: A ?=> A = simple[A] println(s) - val x0: (given A) => (given B) => (A, B) = foo[A, B] + val x0: A ?=> B ?=> (A, B) = foo[A, B] println(x0) - val x1: (given B) => (A, B) = foo[A, B] + val x1: B ?=> (A, B) = foo[A, B] println(x1) println(bar[A, B]) - println(bar[A, B](given a)) - println(bar(given a)(given b)) + println(bar[A, B].with(a)) + println(bar.with(a).with(b)) } } diff --git a/tests/run/i2567.scala b/tests/run/i2567.scala index 6206e84575f9..c59c73a5a7c9 100644 --- a/tests/run/i2567.scala +++ b/tests/run/i2567.scala @@ -2,15 +2,15 @@ class TC given tc : TC -class Foo(given TC) { +class Foo with TC { println("hi") } object Test extends App { new Foo - new Foo(given tc) + new Foo.with(tc) new Foo() - new Foo()(given tc) + new Foo().with(tc) Foo() - Foo()(given tc) + Foo().with(tc) } \ No newline at end of file diff --git a/tests/run/i2939.scala b/tests/run/i2939.scala index fc44503d42db..569a3dedd6fa 100644 --- a/tests/run/i2939.scala +++ b/tests/run/i2939.scala @@ -7,8 +7,8 @@ class Tag(val name: String, val buffer: Buffer[Tag] = ArrayBuffer()) { s"${" " * n}" } - def apply[U](f: (given Tag) => U)(implicit tag: Tag = null): this.type = { - f(given this) + def apply[U](f: Tag ?=> U)(implicit tag: Tag = null): this.type = { + f.with(this) if(tag != null) tag.buffer += this this } diff --git a/tests/run/i3448.scala b/tests/run/i3448.scala index 467fd6cb542d..294590221dde 100644 --- a/tests/run/i3448.scala +++ b/tests/run/i3448.scala @@ -1,13 +1,13 @@ object Test extends App { case class C(x: Int) - type IF[T] = (given C) => T + type IF[T] = C ?=> T val x: IF[Int] = implicitly[C].x - val xs0: List[IF[Int]] = List((given _) => x) + val xs0: List[IF[Int]] = List(_ ?=> x) val xs: List[IF[Int]] = List(x) val ys: IF[List[Int]] = xs.map(x => x) - val zs = ys(given C(22)) + val zs = ys.with(C(22)) assert(zs == List(22)) } diff --git a/tests/run/i7788.scala b/tests/run/i7788.scala index 74950b73ede1..bb88841e77d6 100644 --- a/tests/run/i7788.scala +++ b/tests/run/i7788.scala @@ -4,9 +4,10 @@ trait Show[-A]: given Show[String] = x => x given Show[Int] = _.toString -given showEither[A,B]: (sA: Show[A]) => Show[B] => Show[Either[A,B]] = +given showEither[A,B] with (sA: Show[A]) with Show[B] as Show[Either[A,B]] = _.fold(a => s"Left(${summon[Show[A]].show(a)})", b => s"Right(${summon[Show[B]].show(b)})") -given [A,B]: (sA: Show[A]) => (sB: Show[B]) => Show[(A,B)] = (a,b) => s"(${sA.show(a)}), ${sB.show(b)})" +given [A,B] with (sA: Show[A]) with (sB: Show[B]) as Show[(A,B)] = (a,b) => s"(${sA.show(a)}), ${sB.show(b)})" + @main def Test = println(summon[Show[(Int, String)]].show(0 -> "hello")) diff --git a/tests/run/i7868.scala b/tests/run/i7868.scala index ddcae3e08fb7..8d4132ccfe7d 100644 --- a/tests/run/i7868.scala +++ b/tests/run/i7868.scala @@ -1,8 +1,8 @@ import scala.compiletime.S object Test extends App { - def plusOne[I <: Int](given x: ValueOf[S[I]]): S[I] = x.value - def plusTwo[I <: Int](given x: ValueOf[S[S[I]]]): S[S[I]] = x.value + def plusOne[I <: Int] with (x: ValueOf[S[I]]) : S[I] = x.value + def plusTwo[I <: Int] with (x: ValueOf[S[S[I]]]) : S[S[I]] = x.value assert(plusOne[0] == 1) assert(plusTwo[0] == 2) } diff --git a/tests/run/implicit-alias.scala b/tests/run/implicit-alias.scala index f7e7e7caa494..aab501f124a8 100644 --- a/tests/run/implicit-alias.scala +++ b/tests/run/implicit-alias.scala @@ -22,7 +22,7 @@ object Test extends App { locally{ println("= new") - given t : TC = new TC + given t as TC = new TC summon[TC] summon[TC] } @@ -34,7 +34,7 @@ object Test extends App { locally{ println("= new VC") - given t : TV = new TV(new TC) + given t as TV = new TV(new TC) summon[TV] summon[TV] } @@ -46,21 +46,21 @@ object Test extends App { val tcc = new TCC locally { println("= x.y") - given t : TC = tcc.tc + given t as TC = tcc.tc summon[TC] summon[TC] } locally { println("with given") - given t: TC1 => TC = new TC + given t with TC1 as TC = new TC summon[TC] summon[TC] } locally { println("with type params") - given t[X] : TC = new TC + given t[X] as TC = new TC summon[TC] summon[TC] } diff --git a/tests/run/implicit-disambiguation.scala b/tests/run/implicit-disambiguation.scala index fece83998c26..7ca65906a3d3 100644 --- a/tests/run/implicit-disambiguation.scala +++ b/tests/run/implicit-disambiguation.scala @@ -8,13 +8,13 @@ class C extends A { def show = "C" } object M { - def f(given B, C): String = { - given a : A = summon[B] + def f with (B, C) : String = { + given a as A = summon[B] summon[A].show } } object Test extends App { - given b : B - given c : C + given b as B + given c as C println(M.f) } diff --git a/tests/run/implicit-shortcut-bridge.scala b/tests/run/implicit-shortcut-bridge.scala index f153bd8351ad..811d57b56174 100644 --- a/tests/run/implicit-shortcut-bridge.scala +++ b/tests/run/implicit-shortcut-bridge.scala @@ -1,17 +1,17 @@ abstract class A[T] { def foo: T } -class B extends A[(given Int) => Int] { +class B extends A[Int ?=> Int] { // No bridge needed for foo$direct - def foo: (given Int) => Int = 1 + def foo: Int ?=> Int = 1 } -abstract class X[T] extends A[(given T) => T] { - def foo: (given T) => T +abstract class X[T] extends A[T ?=> T] { + def foo: T ?=> T } class Y extends X[Int] { - def foo: (given Int) => Int = 1 + def foo: Int ?=> Int = 1 } object Test { diff --git a/tests/run/implicit-specifity.scala b/tests/run/implicit-specifity.scala index eb338bcea4cd..4ed9e3d59b04 100644 --- a/tests/run/implicit-specifity.scala +++ b/tests/run/implicit-specifity.scala @@ -2,20 +2,20 @@ case class Show[T](val i: Int) object Show { def apply[T](implicit st: Show[T]): Int = st.i - given showInt : Show[Int] = new Show[Int](0) - given fallback[T] : Show[T] = new Show[T](1) + given showInt as Show[Int] = new Show[Int](0) + given fallback[T] as Show[T] = new Show[T](1) } class Generic object Generic { - given gen : Generic = new Generic - given showGen[T]: Generic => Show[T] = new Show[T](2) + given gen as Generic = new Generic + given showGen[T] with Generic as Show[T] = new Show[T](2) } class Generic2 object Generic2 { opaque type HiPriority = AnyRef - given showGen[T] : (Show[T] & HiPriority) = new Show[T](2).asInstanceOf + given showGen[T] as (Show[T] & HiPriority) = new Show[T](2).asInstanceOf } class SubGen extends Generic @@ -25,13 +25,13 @@ object SubGen { object Contextual { trait Context - given ctx: Context + given ctx as Context - given showGen[T]: Generic => Show[T] = new Show[T](2) + given showGen[T] with Generic as Show[T] = new Show[T](2) - given showGen[T]: Generic, Context => Show[T] = new Show[T](3) + given showGen[T] with (Generic, Context) as Show[T] = new Show[T](3) - given showGen[T]: SubGen => Show[T] = new Show[T](4) + given showGen[T] with SubGen as Show[T] = new Show[T](4) } object Test extends App { diff --git a/tests/run/implicitFunctionXXL.scala b/tests/run/implicitFunctionXXL.scala index 83774390a644..38ce4e0d141d 100644 --- a/tests/run/implicitFunctionXXL.scala +++ b/tests/run/implicitFunctionXXL.scala @@ -5,7 +5,7 @@ object Test { implicit val intWorld: Int = 42 implicit val strWorld: String = "Hello " - val i1 = ((given x1: Int, + val i1 = ( ( x1: Int, x2: String, x3: Int, x4: Int, @@ -30,7 +30,7 @@ object Test { x23: Int, x24: Int, x25: Int, - x26: Int) => x2 + x1) + x26: Int) ?=> x2 + x1) println(i1) } diff --git a/tests/run/implicitFuns.scala b/tests/run/implicitFuns.scala index f3f005dac532..d10374b00eb1 100644 --- a/tests/run/implicitFuns.scala +++ b/tests/run/implicitFuns.scala @@ -3,44 +3,44 @@ object Test { implicit val world: String = "world!" - val i1 = ((given s: String) => s.length > 2) - val i2 = {(given s: String) => s.length > 2} + val i1 = ((s: String) ?=> s.length > 2) + val i2 = {(s: String) ?=> s.length > 2} assert(i1) assert(i2) - val x: (given String) => Boolean = { (given s: String) => s.length > 2 } + val x: String ?=> Boolean = { (s: String) ?=> s.length > 2 } - val xx: (given String, Int) => Int = (given x: String, y: Int) => x.length + y + val xx: (String, Int) ?=> Int = (x: String, y: Int) ?=> x.length + y - val y: String => Boolean = x(given _) + val y: String => Boolean = x.with(_) object nested { implicit val empty: String = "" assert(!x) } - val yy: (String, Int) => Any = xx(given _, _) + val yy: (String, Int) => Any = xx.with(_, _) - val z1: (given String) => Boolean = implicitly[String].length >= 2 + val z1: String ?=> Boolean = implicitly[String].length >= 2 assert(z1) - type StringlyBool = (given String) => Boolean + type StringlyBool = String ?=> Boolean val z2: StringlyBool = implicitly[String].length >= 2 assert(z2) - type Stringly[T] = (given String) => T + type Stringly[T] = String ?=> T val z3: Stringly[Boolean] = implicitly[String].length >= 2 assert(z3) - type GenericImplicit[X] = (given X) => Boolean + type GenericImplicit[X] = X ?=> Boolean val z4: GenericImplicit[String] = implicitly[String].length >= 2 assert(z4) - val b = x(given "hello") + val b = x.with("hello") val b1: Boolean = b @@ -48,7 +48,7 @@ object Test { val bi1: Boolean = bi - val c = xx(given "hh", 22) + val c = xx.with("hh", 22) val c1: Int = c @@ -76,16 +76,16 @@ object Contextual { val Source = new Key[String] val Options = new Key[List[String]] - type Ctx[T] = (given Context) => T + type Ctx[T] = Context ?=> T def ctx: Ctx[Context] = implicitly[Context] def compile(s: String): Ctx[Boolean] = - runOn(new java.io.File(s))(given ctx.withBinding(Source, s)) >= 0 + runOn(new java.io.File(s)).with(ctx.withBinding(Source, s)) >= 0 def runOn(f: java.io.File): Ctx[Int] = { val options = List("-verbose", "-explaintypes") - process(f).apply(given ctx.withBinding(Options, options)) + process(f).apply.with(ctx.withBinding(Options, options)) } def process(f: java.io.File): Ctx[Int] = @@ -151,7 +151,7 @@ object TransactionalExplicit { } object Transactional { - type Transactional[T] = (given Transaction) => T + type Transactional[T] = Transaction ?=> T def transaction[T](op: Transactional[T]) = { implicit val trans: Transaction = new Transaction @@ -216,7 +216,7 @@ object TransactionalExpansion { } object TransactionalAbstracted { - type Transactional[T] = (given Transaction) => T + type Transactional[T] = Transaction ?=> T trait TransOps { def thisTransaction: Transactional[Transaction] diff --git a/tests/run/implicitFuns2.scala b/tests/run/implicitFuns2.scala index 1c2bae93887f..4945eb3e6f73 100644 --- a/tests/run/implicitFuns2.scala +++ b/tests/run/implicitFuns2.scala @@ -2,27 +2,27 @@ class A class B trait Foo { - def foo: (given A) => (given B) => Int + def foo: A ?=> B ?=> Int } class Foo1 extends Foo { - def foo: (given A) => (given B) => Int = 1 + def foo: A ?=> B ?=> Int = 1 } class Foo2 extends Foo1 { - override def foo: (given A) => (given B) => Int = 2 + override def foo: A ?=> B ?=> Int = 2 } trait Foo3 extends Foo { - override def foo: (given A) => (given B) => Int = 3 + override def foo: A ?=> B ?=> Int = 3 } class Bar[T] { - def bar: (given A) => T = null.asInstanceOf[T] + def bar: A ?=> T = null.asInstanceOf[T] } -class Bar1 extends Bar[(given B) => Int] { - override def bar: (given A) => (given B) => Int = 1 +class Bar1 extends Bar[B ?=> Int] { + override def bar: A ?=> B ?=> Int = 1 } object Test { diff --git a/tests/run/implicitShortcut/Base_1.scala b/tests/run/implicitShortcut/Base_1.scala index 05d60d40a7dd..5e52a00e119d 100644 --- a/tests/run/implicitShortcut/Base_1.scala +++ b/tests/run/implicitShortcut/Base_1.scala @@ -3,6 +3,6 @@ package implicitShortcut class C abstract class Base[T] { - def foo(x: T): (given C) => T = x + def foo(x: T): C ?=> T = x } \ No newline at end of file diff --git a/tests/run/implicitShortcut/Derived_2.scala b/tests/run/implicitShortcut/Derived_2.scala index 1893e52536e8..d0f394d1e56c 100644 --- a/tests/run/implicitShortcut/Derived_2.scala +++ b/tests/run/implicitShortcut/Derived_2.scala @@ -1,5 +1,5 @@ package implicitShortcut class Derived extends Base[Int] { - override def foo(x: Int): (given C) => Int = 42 + override def foo(x: Int): C ?=> Int = 42 } \ No newline at end of file diff --git a/tests/run/implied-divergence.scala b/tests/run/implied-divergence.scala index d5a4de3bf3b8..d07ce132bf4e 100644 --- a/tests/run/implied-divergence.scala +++ b/tests/run/implied-divergence.scala @@ -6,7 +6,7 @@ given e : E(null) object Test extends App { - given f: (e: E) => E(e) + given f with (e: E) as E(e) assert(summon[E].toString == "E(E(null))") diff --git a/tests/run/implied-for.scala b/tests/run/implied-for.scala index faf8ed18a346..5f2c23408e3c 100644 --- a/tests/run/implied-for.scala +++ b/tests/run/implied-for.scala @@ -6,10 +6,10 @@ object A { class C extends T class D[T] - given b : B - given c : C - given t : T - given d : D[Int] + given b as B + given c as C + given t as T + given d as D[Int] } object Test extends App { @@ -29,11 +29,11 @@ class ExecutionContext class Monoid[T] object Instances { - given intOrd : Ordering[Int] + given intOrd as Ordering[Int] - given listOrd[T]: Ordering[T] => Ordering[List[T]] - given ec : ExecutionContext - given im : Monoid[Int] + given listOrd[T] with Ordering[T] as Ordering[List[T]] + given ec as ExecutionContext + given im as Monoid[Int] } object Test2 { diff --git a/tests/run/implied-priority.scala b/tests/run/implied-priority.scala index 1ebf409cd423..ee9043edaf5a 100644 --- a/tests/run/implied-priority.scala +++ b/tests/run/implied-priority.scala @@ -11,15 +11,15 @@ class Arg[T] // An argument that we use as a given for some given instances bel * Traditional scheme: prioritize with location in class hierarchy */ class LowPriorityImplicits { - given t1[T] : E[T]("low") + given t1[T] as E[T]("low") } object NormalImplicits extends LowPriorityImplicits { - given t2[T]: Arg[T] => E[T]("norm") + given t2[T] with Arg[T] as E[T]("norm") } def test1 = { - import NormalImplicits.given + import NormalImplicits.{given _} assert(summon[E[String]].str == "low") // No Arg available, so only t1 applies { given Arg[String] @@ -38,12 +38,12 @@ object Priority { } object Impl2 { - given t1[T]: Priority.Low => E[T]("low") - given t2[T]: Priority.High => Arg[T] => E[T]("norm") + given t1[T] with Priority.Low as E[T]("low") + given t2[T] with Priority.High with Arg[T] as E[T]("norm") } def test2 = { - import Impl2.given + import Impl2.{given _} assert(summon[E[String]].str == "low") // No Arg available, so only t1 applies { given Arg[String] @@ -60,12 +60,12 @@ def test2 = { * an alternative without implicit arguments would override all of them. */ object Impl2a { - given t3[T] : E[T]("hi") + given t3[T] as E[T]("hi") } def test2a = { - import Impl2.given - import Impl2a.given + import Impl2.{given _} + import Impl2a.{given _} given Arg[String] assert(summon[E[String]].str == "hi") @@ -75,21 +75,21 @@ def test2a = { * result type of the given instance, e.g. like this: */ object Impl3 { - given t1[T] : E[T]("low") + given t1[T] as E[T]("low") } object Override { trait HighestPriority // A marker trait to indicate a higher priority - given over[T] : E[T]("hi"), HighestPriority + given over[T] as E[T]("hi"), HighestPriority } def test3 = { - import Impl3.given + import Impl3.{given _} assert(summon[E[String]].str == "low") // only t1 is available - { import Override.given - import Impl3.given + { import Override.{given _} + import Impl3.{given _} assert(summon[E[String]].str == "hi") // `over` takes priority since its result type is a subtype of t1's. } } @@ -101,17 +101,17 @@ def test3 = { * with a default argument. */ object Impl4 { - given t1 : E[String]("string") + given t1 as E[String]("string") - given t2[T]: Arg[T] => E[T]("generic") + given t2[T] with Arg[T] as E[T]("generic") } object fallback4 { - def withFallback[T](given ev: E[T] = new E[T]("fallback")): E[T] = ev + def withFallback[T] with (ev: E[T] = new E[T]("fallback") ): E[T] = ev } def test4 = { - import Impl4.given + import Impl4.{given _} import fallback4._ assert(withFallback[String].str == "string") // t1 is applicable assert(withFallback[Int].str == "fallback") // No applicable instances, pick the default @@ -134,12 +134,12 @@ object HigherPriority { } object fallback5 { - given [T]: (ev: E[T] = new E[T]("fallback")) => (E[T] & HigherPriority.Type) = HigherPriority.inject(ev) + given [T] with (ev: E[T] = new E[T]("fallback") ) as (E[T] & HigherPriority.Type) = HigherPriority.inject(ev) } def test5 = { - import Impl4.given - import fallback5.given + import Impl4.{given _} + import fallback5.{given _} // All inferred terms go through the given instance in fallback5. // They differ in what implicit argument is synthesized for that instance. diff --git a/tests/run/implied-specifity-2.scala b/tests/run/implied-specifity-2.scala index d1ce49932975..855f2617c5d3 100644 --- a/tests/run/implied-specifity-2.scala +++ b/tests/run/implied-specifity-2.scala @@ -1,32 +1,32 @@ class Low object Low { - given low : Low + given low as Low } class Medium extends Low object Medium { - given medium : Medium + given medium as Medium } class High extends Medium object High { - given high : High + given high as High } class Foo[T](val i: Int) object Foo { - def apply[T](given fooT: Foo[T]): Int = fooT.i + def apply[T] with (fooT: Foo[T]) : Int = fooT.i - given foo[T](given Low) : Foo[T](0) - given foobar[T](given Low) : Foo[Bar[T]](1) - given foobarbaz(given Low) : Foo[Bar[Baz]](2) + given foo[T] with Low as Foo[T](0) + given foobar[T] with Low as Foo[Bar[T]](1) + given foobarbaz with Low as Foo[Bar[Baz]](2) } class Bar[T] object Bar { - given foobar[T]: Medium => Foo[Bar[T]](3) - given foobarbaz: Medium => Foo[Bar[Baz]](4) + given foobar[T] with Medium as Foo[Bar[T]](3) + given foobarbaz with Medium as Foo[Bar[Baz]](4) } class Baz object Baz { - given baz: High => Foo[Bar[Baz]](5) + given baz with High as Foo[Bar[Baz]](5) } class Arg @@ -35,24 +35,24 @@ given Arg class Bam(val str: String) -given lo: Low => Bam("lo") +given lo with Low : Bam("lo") -given hi: High => Arg => Bam("hi") +given hi with High with Arg : Bam("hi") class Bam2(val str: String) -given lo2(given Low) : Bam2("lo") +given lo2 with Low : Bam2("lo") -given mid2(given High)(given Arg) : Bam2("mid") +given mid2 with High with Arg : Bam2("mid") given hi2 : Bam2("hi") class Arg2 class Red(val str: String) -given normal(given Arg2) : Red("normal") +given normal with Arg2 : Red("normal") -given reduced(given ev: Arg2 | Low) : Red("reduced") +given reduced with (ev: Arg2 | Low) : Red("reduced") object Test extends App { assert(Foo[Int] == 0) diff --git a/tests/run/instances-anonymous.scala b/tests/run/instances-anonymous.scala index 986e81980d90..4385df46e51a 100644 --- a/tests/run/instances-anonymous.scala +++ b/tests/run/instances-anonymous.scala @@ -69,7 +69,7 @@ object Test extends App { val minimum = Int.MinValue } - given [T: Ord] : Ord[List[T]] { + given [T: Ord] as Ord[List[T]] { def (xs: List[T]).compareTo(ys: List[T]): Int = (xs, ys).match { case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -108,7 +108,7 @@ object Test extends App { List(x) } - given [Ctx] : Monad[[X] =>> Ctx => X] { + given [Ctx] as Monad[[X] =>> Ctx => X] { def [A, B](r: Ctx => A) flatMap (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 cb6c562a35c3..471b603d3ce9 100644 --- a/tests/run/instances.scala +++ b/tests/run/instances.scala @@ -32,7 +32,7 @@ object Test extends App { def flattened = xs.foldLeft[List[T]](Nil)(_ ++ _) // A right associative op. Note: can't use given extension for this! - given prepend: AnyRef { + given prepend as AnyRef { def [T](x: T) :: (xs: Seq[T]) = x +: xs } @@ -49,7 +49,7 @@ object Test extends App { trait Monoid[T] extends SemiGroup[T]: def unit: T - given StringMonoid : Monoid[String]: + given StringMonoid as Monoid[String]: def (x: String).combine(y: String): String = x.concat(y) def unit: String = "" @@ -71,7 +71,7 @@ object Test extends App { if (x < y) -1 else if (x > y) +1 else 0 val minimum = Int.MinValue - given listOrd[T: Ord]: Ord[List[T]]: + given listOrd[T: Ord] as Ord[List[T]]: def (xs: List[T]).compareTo(ys: List[T]): Int = (xs, ys).match case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -102,13 +102,13 @@ object Test extends App { def pure[A](x: A): F[A] end Monad - given listMonad: Monad[List]: + given listMonad as Monad[List]: def [A, B](xs: List[A]) flatMap (f: A => List[B]): List[B] = xs.flatMap(f) def pure[A](x: A): List[A] = List(x) - given readerMonad[Ctx]: Monad[[X] =>> Ctx => X]: + given readerMonad[Ctx] as Monad[[X] =>> Ctx => X]: def [A, B](r: Ctx => A) flatMap (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 77d53989692d..55406bacff95 100644 --- a/tests/run/overloading-specifity.scala +++ b/tests/run/overloading-specifity.scala @@ -11,7 +11,7 @@ object Generic { object Test extends App { trait Context - given ctx: Context + given ctx as Context object b { def foo[T](implicit gen: Generic): Show[T] = new Show[T](1) diff --git a/tests/run/poly-kinded-derives.scala b/tests/run/poly-kinded-derives.scala index f2eba46a02e3..c5efcbb0ddb4 100644 --- a/tests/run/poly-kinded-derives.scala +++ b/tests/run/poly-kinded-derives.scala @@ -5,11 +5,11 @@ object Test extends App { trait Show[T] object Show { given Show[Int] {} - given [T]: (st: Show[T]) => Show[Tuple1[T]] - given t2[T, U]: (st: Show[T], su: Show[U]) => Show[(T, U)] - given t3 [T, U, V]: (Show[T], Show[U], Show[V]) => Show[(T, U, V)] + given [T] with (st: Show[T]) as Show[Tuple1[T]] + given t2[T, U] with (st: Show[T], su: Show[U]) as Show[(T, U)] + given t3 [T, U, V] with (st: Show[T], su: Show[U], sv: Show[V]) as Show[(T, U, V)] - def derived[T](given m: Mirror.Of[T], r: Show[m.MirroredElemTypes]): Show[T] = new Show[T] {} + def derived[T] with (m: Mirror.Of[T], r: Show[m.MirroredElemTypes]) : Show[T] = new Show[T] {} } case class Mono(i: Int) derives Show @@ -22,12 +22,12 @@ object Test extends App { { trait Functor[F[_]] object Functor { - given [C] : Functor[[T] =>> C] {} + given [C] as Functor[[T] =>> C] {} given Functor[[T] =>> Tuple1[T]] {} - given t2 [T] : Functor[[U] =>> (T, U)] {} - given t3 [T, U] : Functor[[V] =>> (T, U, V)] {} + given t2 [T] as Functor[[U] =>> (T, U)] {} + given t3 [T, U] as Functor[[V] =>> (T, U, V)] {} - def derived[F[_]](given m: Mirror { type MirroredType = F ; type MirroredElemTypes[_] }, r: Functor[m.MirroredElemTypes]): Functor[F] = new Functor[F] {} + def derived[F[_]] with (m: Mirror { type MirroredType = F ; type MirroredElemTypes[_] }, r: Functor[m.MirroredElemTypes]) : Functor[F] = new Functor[F] {} } case class Mono(i: Int) derives Functor @@ -40,10 +40,10 @@ object Test extends App { { trait FunctorK[F[_[_]]] object FunctorK { - given [C] : FunctorK[[F[_]] =>> C] {} - given [T] : FunctorK[[F[_]] =>> Tuple1[F[T]]] + given [C] as FunctorK[[F[_]] =>> C] {} + given [T] as FunctorK[[F[_]] =>> Tuple1[F[T]]] - def derived[F[_[_]]](given m: Mirror { type MirroredType = F ; type MirroredElemTypes[_[_]] }, r: FunctorK[m.MirroredElemTypes]): FunctorK[F] = new FunctorK[F] {} + def derived[F[_[_]]] with (m: Mirror { type MirroredType = F ; type MirroredElemTypes[_[_]] }, r: FunctorK[m.MirroredElemTypes]) : FunctorK[F] = new FunctorK[F] {} } case class Mono(i: Int) derives FunctorK @@ -56,12 +56,12 @@ object Test extends App { { trait Bifunctor[F[_, _]] object Bifunctor { - given [C] : Bifunctor[[T, U] =>> C] {} + given [C] as Bifunctor[[T, U] =>> C] {} given Bifunctor[[T, U] =>> Tuple1[U]] {} - given t2 : Bifunctor[[T, U] =>> (T, U)] {} - given t3 [T] : Bifunctor[[U, V] =>> (T, U, V)] {} + given t2 as Bifunctor[[T, U] =>> (T, U)] {} + given t3 [T] as Bifunctor[[U, V] =>> (T, U, V)] {} - def derived[F[_, _]](given m: Mirror { type MirroredType = F ; type MirroredElemTypes[_, _] }, r: Bifunctor[m.MirroredElemTypes]): Bifunctor[F] = ??? + def derived[F[_, _]] with (m: Mirror { type MirroredType = F ; type MirroredElemTypes[_, _] }, r: Bifunctor[m.MirroredElemTypes]) : Bifunctor[F] = ??? } case class Mono(i: Int) derives Bifunctor diff --git a/tests/run/polymorphic-functions.scala b/tests/run/polymorphic-functions.scala index 5221f7a24ca6..1667460ddbb8 100644 --- a/tests/run/polymorphic-functions.scala +++ b/tests/run/polymorphic-functions.scala @@ -88,7 +88,7 @@ object Test extends App { new Show[Int] { def show(t: Int): String = t.toString } - val s = [T] => (t: T) => (given st: Show[T]) => st.show(t) + val s = [T] => (t: T) => (st: Show[T]) ?=> st.show(t) assert(s(23) == "23") // Parens handling diff --git a/tests/run/returning.scala b/tests/run/returning.scala index 742d8276a59d..9b3f1f4c67a3 100644 --- a/tests/run/returning.scala +++ b/tests/run/returning.scala @@ -14,9 +14,9 @@ object NonLocalReturns { def throwReturn[T](result: T)(implicit returner: ReturnThrowable[T]): Nothing = returner.throwReturn(result) - def returning[T](op: (given ReturnThrowable[T]) => T): T = { + def returning[T](op: ReturnThrowable[T] ?=> T): T = { val returner = new ReturnThrowable[T] - try op(given returner) + try op.with(returner) catch { case ex: ReturnThrowable[_] => if (ex `eq` returner) ex.result.asInstanceOf[T] else throw ex diff --git a/tests/run/string-context-implicits-with-conversion.scala b/tests/run/string-context-implicits-with-conversion.scala index f72d96989c3a..ee4fd7c263d7 100644 --- a/tests/run/string-context-implicits-with-conversion.scala +++ b/tests/run/string-context-implicits-with-conversion.scala @@ -4,7 +4,7 @@ object Lib { opaque type Showed = String - given [T]: (show: Show[T]) => Conversion[T, Showed] = x => show(x) + given [T] with (show: Show[T]) as Conversion[T, Showed] = x => show(x) trait Show[T] { def apply(x: T): String diff --git a/tests/run/tagless.scala b/tests/run/tagless.scala index 3c82ae3e16ce..e04953f7f39b 100644 --- a/tests/run/tagless.scala +++ b/tests/run/tagless.scala @@ -24,19 +24,19 @@ object Test extends App { } // An example tree - def tf0[T](given e: Exp[T]): T = + def tf0[T] with (e: Exp[T]) : T = e.add(e.lit(8), e.neg(e.add(e.lit(1), e.lit(2)))) // Typeclass-style Exp syntax object ExpSyntax { - def lit[T](i: Int) (given e: Exp[T]): T = e.lit(i) - def neg[T](t: T) (given e: Exp[T]): T = e.neg(t) - def add[T](l: T, r: T)(given e: Exp[T]): T = e.add(l, r) + def lit[T](i: Int) with (e: Exp[T]) : T = e.lit(i) + def neg[T](t: T) with (e: Exp[T]) : T = e.neg(t) + def add[T](l: T, r: T) with (e: Exp[T]) : T = e.add(l, r) } import ExpSyntax._ // It's safe to always have these in scope // Another tree - def tf1[T](given Exp[T]): T = + def tf1[T] with Exp[T] : T = add(lit(8), neg(add(lit(1), lit(2)))) // Base operations as typeclasses @@ -60,7 +60,7 @@ object Test extends App { def mul(l: T, r: T): T } object MultSyntax { - def mul[T](l: T, r: T)(given e: Mult[T]): T = e.mul(l, r) + def mul[T](l: T, r: T) with (e: Mult[T]) : T = e.mul(l, r) } import MultSyntax._ @@ -106,7 +106,7 @@ object Test extends App { object CanThrow { private class Exc(msg: String) extends Exception(msg) - def _throw(msg: String)(given CanThrow): Nothing = throw new Exc(msg) + def _throw(msg: String) with CanThrow : Nothing = throw new Exc(msg) def _try[T](op: Maybe[T])(handler: String => T): T = { given CanThrow try op @@ -117,7 +117,7 @@ object Test extends App { } import CanThrow._ - type Maybe[T] = (given CanThrow) => T + type Maybe[T] = CanThrow ?=> T def show[T](op: Maybe[T]): Unit = println(_try(op.toString)(identity)) @@ -138,7 +138,7 @@ object Test extends App { show(readInt("2")) show(readInt("X")) - def fromTree[T](t: Tree)(given Exp[T]): Maybe[T] = t match { + def fromTree[T](t: Tree) with Exp[T] : Maybe[T] = t match { case Node("Lit", Leaf(n)) => lit(readInt(n)) case Node("Neg", t) => neg(fromTree(t)) case Node("Add", l , r) => add(fromTree(l), fromTree(r)) @@ -150,18 +150,18 @@ object Test extends App { show(fromTree[Tree](tf1Tree)) trait Wrapped { - def value[T](given Exp[T]): T + def value[T] with Exp[T] : T } given Exp[Wrapped] { def lit(i: Int) = new Wrapped { - def value[T](given e: Exp[T]): T = e.lit(i) + def value[T] with (e: Exp[T]) : T = e.lit(i) } def neg(t: Wrapped) = new Wrapped { - def value[T](given e: Exp[T]): T = e.neg(t.value) + def value[T] with (e: Exp[T]) : T = e.neg(t.value) } def add(l: Wrapped, r: Wrapped) = new Wrapped { - def value[T](given e: Exp[T]): T = e.add(l.value, r.value) + def value[T] with (e: Exp[T]) : T = e.add(l.value, r.value) } } @@ -170,7 +170,7 @@ object Test extends App { s"${t.value[Int]}\n${t.value[String]}" } - def fromTreeExt[T](recur: => Tree => Maybe[T])(given Exp[T]): Tree => Maybe[T] = { + def fromTreeExt[T](recur: => Tree => Maybe[T]) with Exp[T] : Tree => Maybe[T] = { case Node("Lit", Leaf(n)) => lit(readInt(n)) case Node("Neg", t) => neg(recur(t)) case Node("Add", l , r) => add(recur(l), recur(r)) @@ -181,7 +181,7 @@ object Test extends App { def fromTree2[T: Exp](t: Tree): Maybe[T] = fix(fromTreeExt[T])(t) - def fromTreeExt2[T](recur: => Tree => Maybe[T])(given Exp[T], Mult[T]): Tree => Maybe[T] = { + def fromTreeExt2[T](recur: => Tree => Maybe[T]) with (Exp[T], Mult[T]) : Tree => Maybe[T] = { case Node("Mult", l , r) => mul(recur(l), recur(r)) case t => fromTreeExt(recur)(t) } @@ -196,7 +196,7 @@ object Test extends App { // Added operation: negation pushdown enum NCtx { case Pos, Neg } - given [T]: (e: Exp[T]) => Exp[NCtx => T] { + given [T] with (e: Exp[T]) as Exp[NCtx => 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) - given [T](given e: Mult[T]) : Mult[NCtx => T] { + given [T] with (e: Mult[T]) as Mult[NCtx => T] { import NCtx._ def mul(l: NCtx => T, r: NCtx => T): NCtx => T = { case Pos => e.mul(l(Pos), r(Pos)) @@ -230,21 +230,21 @@ object Test extends App { import IExp._ // Going from type class encoding to ADT encoding - given initialize : Exp[IExp] { + given initialize as Exp[IExp] { def lit(i: Int): IExp = Lit(i) def neg(t: IExp): IExp = Neg(t) def add(l: IExp, r: IExp): IExp = Add(l, r) } // Going from ADT encoding to type class encoding - def finalize[T](i: IExp)(given e: Exp[T]): T = i match { + def finalize[T](i: IExp) with (e: Exp[T]) : T = i match { case Lit(l) => e.lit(l) case Neg(n) => e.neg(finalize[T](n)) case Add(l, r) => e.add(finalize[T](l), finalize[T](r)) } // Abstracting over multiple typeclasses - type Ring[T] = (given Exp[T]) => (given Mult[T]) => T + type Ring[T] = Exp[T] ?=> Mult[T] ?=> T def tfm1a[T]: Ring[T] = add(lit(7), neg(mul(lit(1), lit(2)))) def tfm2a[T]: Ring[T] = mul(lit(7), tf1) diff --git a/tests/run/tupled-function-andThen.scala b/tests/run/tupled-function-andThen.scala index 678ced420d9e..c7d81f25b0e3 100644 --- a/tests/run/tupled-function-andThen.scala +++ b/tests/run/tupled-function-andThen.scala @@ -32,7 +32,7 @@ object Test { * @tparam GArgs the tuple type with the same types as the function arguments of G and return type of F * @tparam R the return type of G */ - def [F, G, FArgs <: Tuple, GArgs <: Tuple, R](f: F) andThen (g: G)(given tf: TupledFunction[F, FArgs => GArgs], tg: TupledFunction[G, GArgs => R]): FArgs => R = { + def [F, G, FArgs <: Tuple, GArgs <: Tuple, R](f: F) andThen (g: G) with (tf: TupledFunction[F, FArgs => GArgs], tg: TupledFunction[G, GArgs => R]) : FArgs => R = { x => tg.tupled(g)(tf.tupled(f)(x)) } diff --git a/tests/run/tupled-function-apply.scala b/tests/run/tupled-function-apply.scala index 77798a49980d..69b876750739 100644 --- a/tests/run/tupled-function-apply.scala +++ b/tests/run/tupled-function-apply.scala @@ -113,6 +113,6 @@ object Test { * @tparam Args the tuple type with the same types as the function arguments of F * @tparam R the return type of F */ - def [F, Args <: Tuple, R](f: F) apply (args: Args)(given tf: TupledFunction[F, Args => R]): R = + def [F, Args <: Tuple, R](f: F) apply (args: Args) with (tf: TupledFunction[F, Args => R]) : R = tf.tupled(f)(args) } \ No newline at end of file diff --git a/tests/run/tupled-function-compose.scala b/tests/run/tupled-function-compose.scala index 890659f31495..b7ff1983289d 100644 --- a/tests/run/tupled-function-compose.scala +++ b/tests/run/tupled-function-compose.scala @@ -33,7 +33,7 @@ object Test { * @tparam GArgs the tuple type with the same types as the function arguments of G * @tparam R the return type of F */ - def [F, G, FArgs <: Tuple, GArgs <: Tuple, R](f: F) compose (g: G)(given tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]): GArgs => R = { + def [F, G, FArgs <: Tuple, GArgs <: Tuple, R](f: F) compose (g: G) with (tg: TupledFunction[G, GArgs => FArgs], tf: TupledFunction[F, FArgs => R]) : GArgs => R = { x => tf.tupled(f)(tg.tupled(g)(x)) } diff --git a/tests/run/tupled-function-extension-method.scala b/tests/run/tupled-function-extension-method.scala index f5c01f401844..48b29e85ded5 100644 --- a/tests/run/tupled-function-extension-method.scala +++ b/tests/run/tupled-function-extension-method.scala @@ -16,11 +16,11 @@ object Test { println(f3(1, 2, 3)) println(f25(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)) - val if1 = new Expr((given i: Int) => Tuple1(i)) - val if2 = new Expr((given i: Int, j: Int) => (i, i + j)) - val if3 = new Expr((given i: Int, j: Int, k: Int) => (i, i + j, i + j + k)) + val if1 = new Expr((i: Int) ?=> Tuple1(i)) + val if2 = new Expr((i: Int, j: Int) ?=> (i, i + j)) + val if3 = new Expr((i: Int, j: Int, k: Int) ?=> (i, i + j, i + j + k)) val if25 = new Expr( - (given x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int, x23: Int, x24: Int, x25: Int) => + (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int, x23: Int, x24: Int, x25: Int) ?=> (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25) ) @@ -36,12 +36,12 @@ object Test { // Specialized only for arity 0 and one as auto tupling will not provide the disired effect def [R](e: Expr[() => R]) apply (): R = e.x() def [Arg, R](e: Expr[Arg => R]) apply (arg: Arg): R = e.x(arg) - def [Arg, R](e: Expr[(given Arg) => R]) applyGiven(arg: Arg): R = e.x(given arg) + def [Arg, R](e: Expr[Arg ?=> R]) applyGiven(arg: Arg): R = e.x.with(arg) // Applied to all funtions of arity 2 or more (including more than 22 parameters) - def [F, Args <: Tuple, R](e: Expr[F]) apply (args: Args)(given tf: TupledFunction[F, Args => R]): R = + def [F, Args <: Tuple, R](e: Expr[F]) apply (args: Args) with (tf: TupledFunction[F, Args => R]) : R = tf.tupled(e.x)(args) - def [F, Args <: Tuple, R](e: Expr[F]) applyGiven (args: Args)(given tf: TupledFunction[F, (given Args) => R]): R = - tf.tupled(e.x)(given args) + def [F, Args <: Tuple, R](e: Expr[F]) applyGiven (args: Args) with (tf: TupledFunction[F, Args ?=> R]) : R = + tf.tupled(e.x).with(args) } \ No newline at end of file diff --git a/tests/run/tupled-function-tupled.scala b/tests/run/tupled-function-tupled.scala index a905d92d7df3..abd3ad829d00 100644 --- a/tests/run/tupled-function-tupled.scala +++ b/tests/run/tupled-function-tupled.scala @@ -24,5 +24,5 @@ object Test { * @tparam Args the tuple type with the same types as the function arguments of F * @tparam R the return type of F */ - def [F, Args <: Tuple, R](f: F) tupled (given tf: TupledFunction[F, Args => R]): Args => R = tf.tupled(f) + def [F, Args <: Tuple, R](f: F) tupled with (tf: TupledFunction[F, Args => R]) : Args => R = tf.tupled(f) } diff --git a/tests/run/tupled-function-untupled.scala b/tests/run/tupled-function-untupled.scala index c79cb9a91417..4473e6f671d0 100644 --- a/tests/run/tupled-function-untupled.scala +++ b/tests/run/tupled-function-untupled.scala @@ -104,5 +104,5 @@ object Test { * @tparam Args the tuple type with the same types as the function arguments of F * @tparam R the return type of F */ - def [F, Args <: Tuple, R](f: Args => R) untupled(given tf: TupledFunction[F, Args => R]): F = tf.untupled(f) + def [F, Args <: Tuple, R](f: Args => R) untupled with (tf: TupledFunction[F, Args => R]) : F = tf.untupled(f) } diff --git a/tests/run/typeclass-derivation-doc-example.scala b/tests/run/typeclass-derivation-doc-example.scala index 5794ef8a639d..2e03f3ab0317 100644 --- a/tests/run/typeclass-derivation-doc-example.scala +++ b/tests/run/typeclass-derivation-doc-example.scala @@ -40,7 +40,7 @@ object Eq { } } - inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { + inline given derived[T] with (m: Mirror.Of[T]) : Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] inline m match { case s: Mirror.SumOf[T] => eqSum(s, elemInstances) diff --git a/tests/semanticdb/expect/Enums.expect.scala b/tests/semanticdb/expect/Enums.expect.scala index 440a96d85f2d..68d775c982fe 100644 --- a/tests/semanticdb/expect/Enums.expect.scala +++ b/tests/semanticdb/expect/Enums.expect.scala @@ -47,9 +47,9 @@ object Enums/*<-_empty_::Enums.*/: case Refl/*<-_empty_::Enums.`<:<`.Refl#*/[C/*<-_empty_::Enums.`<:<`.Refl#[C]*/]() extends (C/*->_empty_::Enums.`<:<`.Refl#[C]*/ <:_empty_::Enums.`<:<`#*/ C/*->_empty_::Enums.`<:<`.Refl#[C]*/) object <:_empty_::Enums.`<:<`.given_T().[T]*/ <:_empty_::Enums.`<:<`#*/ T/*->_empty_::Enums.`<:<`.given_T().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/() + given [T] as /*<-_empty_::Enums.`<:<`.given_T().*//*<-_empty_::Enums.`<:<`.given_T().[T]*/(T/*->_empty_::Enums.`<:<`.given_T().[T]*/ <:_empty_::Enums.`<:<`#*/ T/*->_empty_::Enums.`<:<`.given_T().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/() - def [A, B]/*<-_empty_::Enums.unwrap().*//*<-_empty_::Enums.unwrap().[A]*//*<-_empty_::Enums.unwrap().[B]*/(opt/*<-_empty_::Enums.unwrap().(opt)*/: Option/*->scala::Option#*/[A/*->_empty_::Enums.unwrap().[A]*/]) unwrap(given ev/*<-_empty_::Enums.unwrap().(ev)*/: A/*->_empty_::Enums.unwrap().[A]*/ <:_empty_::Enums.`<:<`#*/ Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]): Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/] = ev/*->_empty_::Enums.unwrap().(ev)*/ match + def [A, B]/*<-_empty_::Enums.unwrap().*//*<-_empty_::Enums.unwrap().[A]*//*<-_empty_::Enums.unwrap().[B]*/(opt/*<-_empty_::Enums.unwrap().(opt)*/: Option/*->scala::Option#*/[A/*->_empty_::Enums.unwrap().[A]*/]) unwrap with (ev/*<-_empty_::Enums.unwrap().(ev)*/: A/*->_empty_::Enums.unwrap().[A]*/ <:_empty_::Enums.`<:<`#*/ Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]) : Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/] = ev/*->_empty_::Enums.unwrap().(ev)*/ match case Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.unapply().*/() => opt/*->_empty_::Enums.unwrap().(opt)*/.flatMap/*->scala::Option#flatMap().*/(identity/*->scala::Predef.identity().*//*->local0*/[Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]]) val some1/*<-_empty_::Enums.some1.*/ = /*->_empty_::Enums.unwrap().*/Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1))/*->_empty_::Enums.`<:<`.given_T().*/.unwrap diff --git a/tests/semanticdb/expect/Enums.scala b/tests/semanticdb/expect/Enums.scala index 94f4a56e3c1b..77e27c381a87 100644 --- a/tests/semanticdb/expect/Enums.scala +++ b/tests/semanticdb/expect/Enums.scala @@ -47,9 +47,9 @@ object Enums: case Refl[C]() extends (C <:< C) object <:< : - given [T]: (T <:< T) = Refl() + given [T] as (T <:< T) = Refl() - def [A, B](opt: Option[A]) unwrap(given ev: A <:< Option[B]): Option[B] = ev match + def [A, B](opt: Option[A]) unwrap with (ev: A <:< Option[B]) : Option[B] = ev match case Refl() => opt.flatMap(identity[Option[B]]) val some1 = Some(Some(1)).unwrap diff --git a/tests/semanticdb/expect/Givens.expect.scala b/tests/semanticdb/expect/Givens.expect.scala index 433e1fe1ec96..48340466ae98 100644 --- a/tests/semanticdb/expect/Givens.expect.scala +++ b/tests/semanticdb/expect/Givens.expect.scala @@ -24,4 +24,4 @@ object Givens/*<-a::b::Givens.*/ inline given int2String/*<-a::b::Givens.int2String().*/: Conversion/*->scala::Conversion#*/[Int/*->scala::Int#*/, String/*->scala::Predef.String#*/] = _.toString/*->scala::Any#toString().*/ - def foo/*<-a::b::Givens.foo().*/[A/*<-a::b::Givens.foo().[A]*/](given A/*<-a::b::Givens.foo().(A)*/: Monoid/*->a::b::Givens.Monoid#*/[A/*->a::b::Givens.foo().[A]*/]): A/*->a::b::Givens.foo().[A]*/ = A/*->a::b::Givens.foo().(A)*/.combine/*->a::b::Givens.Monoid#combine().*/(A/*->a::b::Givens.foo().(A)*/.empty/*->a::b::Givens.Monoid#empty().*/)(A/*->a::b::Givens.foo().(A)*/.empty/*->a::b::Givens.Monoid#empty().*/) + def foo/*<-a::b::Givens.foo().*/[A/*<-a::b::Givens.foo().[A]*/] with (A/*<-a::b::Givens.foo().(A)*/: Monoid/*->a::b::Givens.Monoid#*/[A/*->a::b::Givens.foo().[A]*/]) : A/*->a::b::Givens.foo().[A]*/ = A/*->a::b::Givens.foo().(A)*/.combine/*->a::b::Givens.Monoid#combine().*/(A/*->a::b::Givens.foo().(A)*/.empty/*->a::b::Givens.Monoid#empty().*/)(A/*->a::b::Givens.foo().(A)*/.empty/*->a::b::Givens.Monoid#empty().*/) diff --git a/tests/semanticdb/expect/Givens.scala b/tests/semanticdb/expect/Givens.scala index b5b5548a0b00..b30a5447dcdb 100644 --- a/tests/semanticdb/expect/Givens.scala +++ b/tests/semanticdb/expect/Givens.scala @@ -24,4 +24,4 @@ object Givens inline given int2String: Conversion[Int, String] = _.toString - def foo[A](given A: Monoid[A]): A = A.combine(A.empty)(A.empty) + def foo[A] with (A: Monoid[A]) : A = A.combine(A.empty)(A.empty) diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 7b59a7ccb38b..044a6fadcd6e 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -834,13 +834,13 @@ Occurrences: [46:34..46:35): C -> _empty_/Enums.`<:<`.Refl#[C] [46:35..46:35): -> _empty_/Enums.`<:<`#``(). [48:9..48:12): <:< <- _empty_/Enums.`<:<`. -[49:10..49:17): [T]: (T <- _empty_/Enums.`<:<`.given_T(). +[49:10..49:17): [T] as <- _empty_/Enums.`<:<`.given_T(). [49:11..49:12): T <- _empty_/Enums.`<:<`.given_T().[T] -[49:16..49:17): T -> _empty_/Enums.`<:<`.given_T().[T] -[49:18..49:21): <:< -> _empty_/Enums.`<:<`# -[49:22..49:23): T -> _empty_/Enums.`<:<`.given_T().[T] -[49:27..49:31): Refl -> _empty_/Enums.`<:<`.Refl. -[49:31..49:31): -> _empty_/Enums.`<:<`.Refl.apply(). +[49:18..49:19): T -> _empty_/Enums.`<:<`.given_T().[T] +[49:20..49:23): <:< -> _empty_/Enums.`<:<`# +[49:24..49:25): T -> _empty_/Enums.`<:<`.given_T().[T] +[49:29..49:33): Refl -> _empty_/Enums.`<:<`.Refl. +[49:33..49:33): -> _empty_/Enums.`<:<`.Refl.apply(). [51:6..51:12): [A, B] <- _empty_/Enums.unwrap(). [51:7..51:8): A <- _empty_/Enums.unwrap().[A] [51:10..51:11): B <- _empty_/Enums.unwrap().[B] @@ -852,9 +852,9 @@ Occurrences: [51:48..51:51): <:< -> _empty_/Enums.`<:<`# [51:52..51:58): Option -> scala/Option# [51:59..51:60): B -> _empty_/Enums.unwrap().[B] -[51:64..51:70): Option -> scala/Option# -[51:71..51:72): B -> _empty_/Enums.unwrap().[B] -[51:76..51:78): ev -> _empty_/Enums.unwrap().(ev) +[51:65..51:71): Option -> scala/Option# +[51:72..51:73): B -> _empty_/Enums.unwrap().[B] +[51:77..51:79): ev -> _empty_/Enums.unwrap().(ev) [52:9..52:13): Refl -> _empty_/Enums.`<:<`.Refl. [52:13..52:13): -> _empty_/Enums.`<:<`.Refl.unapply(). [52:19..52:22): opt -> _empty_/Enums.unwrap().(opt) @@ -1370,13 +1370,13 @@ Occurrences: [26:19..26:20): A <- a/b/Givens.foo().(A) [26:22..26:28): Monoid -> a/b/Givens.Monoid# [26:29..26:30): A -> a/b/Givens.foo().[A] -[26:34..26:35): A -> a/b/Givens.foo().[A] -[26:38..26:39): A -> a/b/Givens.foo().(A) -[26:40..26:47): combine -> a/b/Givens.Monoid#combine(). -[26:48..26:49): A -> a/b/Givens.foo().(A) -[26:50..26:55): empty -> a/b/Givens.Monoid#empty(). -[26:57..26:58): A -> a/b/Givens.foo().(A) -[26:59..26:64): empty -> a/b/Givens.Monoid#empty(). +[26:35..26:36): A -> a/b/Givens.foo().[A] +[26:39..26:40): A -> a/b/Givens.foo().(A) +[26:41..26:48): combine -> a/b/Givens.Monoid#combine(). +[26:49..26:50): A -> a/b/Givens.foo().(A) +[26:51..26:56): empty -> a/b/Givens.Monoid#empty(). +[26:58..26:59): A -> a/b/Givens.foo().(A) +[26:60..26:65): empty -> a/b/Givens.Monoid#empty(). expect/ImplicitConversion.scala -------------------------------