diff --git a/community-build/community-projects/effpi b/community-build/community-projects/effpi index e6539da2215e..26c04f514441 160000 --- a/community-build/community-projects/effpi +++ b/community-build/community-projects/effpi @@ -1 +1 @@ -Subproject commit e6539da2215eefc2e2787ad5e2018878e1063b4c +Subproject commit 26c04f514441a86c003a735fa6c8992be3d151ed diff --git a/community-build/community-projects/intent b/community-build/community-projects/intent index a8cf6273989d..a633d402fc99 160000 --- a/community-build/community-projects/intent +++ b/community-build/community-projects/intent @@ -1 +1 @@ -Subproject commit a8cf6273989db4990f0f50d7a33f42e3e72496bd +Subproject commit a633d402fc99a843715be831257c774d3b3e3f06 diff --git a/community-build/community-projects/shapeless b/community-build/community-projects/shapeless index 63c5e0a4c57e..5e2cb09252b4 160000 --- a/community-build/community-projects/shapeless +++ b/community-build/community-projects/shapeless @@ -1 +1 @@ -Subproject commit 63c5e0a4c57efbaf17699144b627db1639800e90 +Subproject commit 5e2cb09252b48f177775a92a4eb5bef10a1e5523 diff --git a/community-build/community-projects/sourcecode b/community-build/community-projects/sourcecode index 2c0ae1b34aad..9355583297d3 160000 --- a/community-build/community-projects/sourcecode +++ b/community-build/community-projects/sourcecode @@ -1 +1 @@ -Subproject commit 2c0ae1b34aada9ef1e4e37b507df1cd7005fe067 +Subproject commit 9355583297d3f25f8dda8707d9c86eadd897119b diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index 9fa499c1f0e6..0f6c2b1ca37a 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit 9fa499c1f0e6ef8ee7fbdb916fc245f754bb27ed +Subproject commit 0f6c2b1ca37af7cc87bc49f2f5107aafc66f4add diff --git a/community-build/community-projects/xml-interpolator b/community-build/community-projects/xml-interpolator index 48ce1920e0e4..5fbcc74d8016 160000 --- a/community-build/community-projects/xml-interpolator +++ b/community-build/community-projects/xml-interpolator @@ -1 +1 @@ -Subproject commit 48ce1920e0e4b8849f35defe8e73a4fb0a7ecebf +Subproject commit 5fbcc74d8016e4914bb9f4c8776c7d7f17317c65 diff --git a/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala b/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala index 76d85e3cb864..4e44557e1163 100644 --- a/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala +++ b/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala @@ -47,7 +47,7 @@ sealed trait CommunityProject: /** Is this project running in the test or update mode in the * context of the given suite? @see `run` for more details. */ - final def isUpdateMode(given suite: CommunityBuildTest) = + final def isUpdateMode(using suite: CommunityBuildTest) = suite.isInstanceOf[CommunityBuildUpdate] /** Depending on the mode of operation, either @@ -60,7 +60,7 @@ sealed trait CommunityProject: * and avoid network overhead. See https://github.com/lampepfl/dotty-drone * for more infrastructural details. */ - final def run()(given suite: CommunityBuildTest) = + final def run()(using suite: CommunityBuildTest) = val runCmd = if isUpdateMode then updateCommand else testCommand if !isUpdateMode then dependencies.foreach(_.publish()) suite.test(project, binaryName, runCommandsArgs :+ runCmd) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 3c76ad61bf0e..f21abcb53d1b 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -22,7 +22,7 @@ object Flags { type Flag = opaques.Flag - given extension (x: FlagSet) with + extension on (x: FlagSet) { def bits: Long = opaques.toBits(x) @@ -150,7 +150,7 @@ object Flags { /** The string representation of the given flag set */ def flagsString: String = x.flagStrings("").mkString(" ") - end given + } def termFlagSet(x: Long) = FlagSet(TERMS | x) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index ea19e3e49167..31f4fb12872a 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -917,7 +917,7 @@ object Parsers { def followingIsParamOrGivenType() = val lookahead = in.LookaheadScanner() lookahead.nextToken() - if startParamOrGivenTypeTokens.contains(lookahead.token) + if startParamTokens.contains(lookahead.token) || lookahead.isIdent(nme.using) then true else if lookahead.token == IDENTIFIER then @@ -1450,8 +1450,6 @@ object Parsers { case MATCH => matchType(t) case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t case _ => - if (imods.isOneOf(GivenOrImplicit) && !t.isInstanceOf[FunctionWithMods]) - syntaxError(ImplicitTypesCanOnlyBeFunctionTypes(), implicitKwPos(start)) if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods]) syntaxError(ErasedTypesCanOnlyBeFunctionTypes(), implicitKwPos(start)) t @@ -2299,7 +2297,7 @@ object Parsers { def parArgumentExprs(): (List[Tree], Boolean) = inParens { if in.token == RPAREN then (Nil, false) - else if in.token == GIVEN || isIdent(nme.using) then + else if isIdent(nme.using) then in.nextToken() (commaSeparated(argumentExpr), true) else @@ -2786,7 +2784,7 @@ object Parsers { normalize(loop(start)) } - val funTypeArgMods: BitSet = BitSet(GIVEN, ERASED) + val funTypeArgMods: BitSet = BitSet(ERASED) /** Wrap annotation or constructor in New(...). */ def wrapNew(tpt: Tree): Select = Select(New(tpt), nme.CONSTRUCTOR) @@ -2912,7 +2910,7 @@ object Parsers { def paramMods() = if in.token == IMPLICIT then addParamMod(() => Mod.Implicit()) else - if in.token == GIVEN || isIdent(nme.using) then addParamMod(() => Mod.Given()) + if isIdent(nme.using) then addParamMod(() => Mod.Given()) if in.token == ERASED then addParamMod(() => Mod.Erased()) def param(): ValDef = { @@ -3508,70 +3506,54 @@ object Parsers { var mods1 = addMod(mods, instanceMod) val hasGivenSig = followingIsGivenSig() val nameStart = in.offset - val (name, isOldExtension) = - if isIdent && hasGivenSig then - (ident(), in.token == COLON && in.lookaheadIn(nme.extension)) - else - (EmptyTermName, isIdent(nme.extension)) + val name = if isIdent && hasGivenSig then ident() else EmptyTermName val gdef = in.endMarkerScope(if name.isEmpty then GIVEN else name) { - if isOldExtension then - if (in.token == COLON) in.nextToken() - assert(ident() == nme.extension) - val tparams = typeParamClauseOpt(ParamOwner.Def) - val extParams = paramClause(0, prefix = true) - val givenParamss = paramClauses(givenOnly = true) - possibleTemplateStart() - val templ = templateBodyOpt( - makeConstructor(tparams, extParams :: givenParamss), Nil, Nil) - templ.body.foreach(checkExtensionMethod(tparams, _)) - ModuleDef(name, templ) - else - val hasLabel = !name.isEmpty && in.token == COLON || isIdent(nme.as) - if hasLabel then in.nextToken() - val tparams = typeParamClauseOpt(ParamOwner.Def) - val paramsStart = in.offset - val vparamss = - if 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 preceded by `using`", vparam.span))) - 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") + val hasLabel = !name.isEmpty && in.token == COLON || isIdent(nme.as) + if hasLabel then in.nextToken() + val tparams = typeParamClauseOpt(ParamOwner.Def) + val paramsStart = in.offset + val vparamss = + if 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 preceded by `using`", vparam.span))) + 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, toplevelTyp()) :: Nil + else + if !hasLabel && !(name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then + 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 - if !hasLabel && !(name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then - 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 - constrApps(commaOK = true, templateCanFollow = true) + constrApps(commaOK = true, templateCanFollow = true) - if in.token == EQUALS && parents.length == 1 && parents.head.isType then - in.nextToken() - mods1 |= Final - DefDef(name, tparams, vparamss, parents.head, subExpr()) - else - parents match - case (_: TypeBoundsTree) :: _ => syntaxError("`=` expected") - case _ => - possibleTemplateStart() - val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal)) - val vparamss1 = vparamss.map(_.map(vparam => - vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal))) - val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil) - if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ) - else TypeDef(name.toTypeName, templ) - } + if in.token == EQUALS && parents.length == 1 && parents.head.isType then + in.nextToken() + mods1 |= Final + DefDef(name, tparams, vparamss, parents.head, subExpr()) + else + parents match + case (_: TypeBoundsTree) :: _ => syntaxError("`=` expected") + case _ => + possibleTemplateStart() + val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal)) + val vparamss1 = vparamss.map(_.map(vparam => + vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal))) + val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil) + if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ) + else TypeDef(name.toTypeName, templ) + } finalizeDef(gdef, mods1, start) } diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index 8b86aa078796..adc99bf5f8be 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -257,7 +257,7 @@ object Tokens extends TokensCommon { AT, CASE) final val canEndStatTokens: TokenSet = atomicExprTokens | BitSet( - TYPE, GIVEN, RPAREN, RBRACE, RBRACKET, OUTDENT) + TYPE, GIVEN, RPAREN, RBRACE, RBRACKET, OUTDENT) // TODO: remove GIVEN once old import syntax is dropped /** Tokens that stop a lookahead scan search for a `<-`, `then`, or `do`. * Used for disambiguating between old and new syntax. @@ -280,12 +280,6 @@ object Tokens extends TokensCommon { */ final val startParamTokens: BitSet = modifierTokens | BitSet(VAL, VAR, AT) - /** Faced with the choice of a type `(...)` or a parameter or given type list - * in `(...)`, the following tokens after the opening `(` determine it's - * a parameter or given type list. - */ - final val startParamOrGivenTypeTokens: BitSet = startParamTokens | BitSet(GIVEN, ERASED) - final val scala3keywords = BitSet(ENUM, ERASED, GIVEN) final val softModifierNames = Set(nme.inline, nme.opaque, nme.open) diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 3680501fe9f6..8e94e20219d1 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -188,7 +188,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case tp: MethodType => changePrec(GlobalPrec) { "(" - ~ keywordText("given ").provided(tp.isContextualMethod) + ~ keywordText("using ").provided(tp.isContextualMethod) ~ keywordText("erased ").provided(tp.isErasedMethod) ~ keywordText("implicit ").provided(tp.isImplicitMethod && !tp.isContextualMethod) ~ paramsText(tp) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala index c5e5f2168c16..b35d041d7c47 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala @@ -150,7 +150,7 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] { UnknownNamedEnclosingClassOrObjectID, IllegalCyclicTypeReferenceID, MissingTypeParameterInTypeAppID, - ImplicitTypesCanOnlyBeFunctionTypesID, + UNUSED_ImplicitTypesCanOnlyBeFunctionTypesID, ErasedTypesCanOnlyBeFunctionTypesID, CaseClassMissingNonImplicitParamListID, EnumerationsShouldNotBeEmptyID, diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index db962705d9a8..de17b90943cf 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -2376,17 +2376,10 @@ object messages { """.stripMargin } - case class IllegalCyclicTypeReference(sym: Symbol, where: String, lastChecked: Type)(implicit val ctx: Context) - extends Message(IllegalCyclicTypeReferenceID) { - val kind: String = "Cyclic" - val msg: String = i"illegal cyclic type reference: ${where} ${hl(lastChecked.show)} of $sym refers back to the type itself" - val explanation: String = "" - } - - case class ImplicitTypesCanOnlyBeFunctionTypes()(implicit val ctx: Context) // TODO remove when (given ...) => is removed - extends Message(ImplicitTypesCanOnlyBeFunctionTypesID) { - val kind: String = "Syntax" - val msg: String = "Types with given keyword can only be function types `(given ...) => ...`" + case class IllegalCyclicTypeReference(sym: Symbol, where: String, lastChecked: Type)(implicit val ctx: Context) + extends Message(IllegalCyclicTypeReferenceID) { + val kind: String = "Cyclic" + val msg: String = i"illegal cyclic type reference: ${where} ${hl(lastChecked.show)} of $sym refers back to the type itself" val explanation: String = "" } diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 7d07fd155ee3..80c434f88118 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -17,8 +17,8 @@ import java.nio.file.Paths import PartialFunction.condOpt -import ast.untpd.given -import NameOps.given +import ast.untpd.{given _} +import NameOps.{given _} import scala.annotation.{ threadUnsafe => tu, tailrec } @@ -28,8 +28,8 @@ import scala.annotation.{ threadUnsafe => tu, tailrec } * TODO: Also extract type information */ class ExtractSemanticDB extends Phase with - import Scala3.{_, given} - import Symbols.given + import Scala3.{_, given _} + import Symbols.{given _} override val phaseName: String = ExtractSemanticDB.name @@ -509,10 +509,9 @@ class ExtractSemanticDB extends Phase with else limit Span(start max limit, end) - private given extension (span: Span) with + private extension on (span: Span): def hasLength: Boolean = span.start != span.end def zeroLength: Boolean = span.start == span.end - end given /**Consume head while not an import statement. * Returns the rest of the list after the first import, or else the empty list diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 80fd763abe9e..6bcfb8b97878 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -863,7 +863,7 @@ trait Applications extends Compatibility { new ApplyToTyped(tree, fun1, funRef, proto.typedArgs(), pt) else new ApplyToUntyped(tree, fun1, funRef, proto, pt)( - given fun1.nullableInArgContext(using argCtx(tree))) + using fun1.nullableInArgContext(using argCtx(tree))) convertNewGenericArray( postProcessByNameArgs(funRef, app.result).computeNullable()) case _ => diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index a28c0a04b709..8f027962c3a3 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -184,7 +184,7 @@ trait ImportSuggestions with try timer.schedule(task, testOneImplicitTimeOut) typedImplicit(candidate, expectedType, argument, span)( - given ctx.fresh.setExploreTyperState()).isSuccess + using ctx.fresh.setExploreTyperState()).isSuccess finally if task.cancel() then // timer task has not run yet assert(!ctx.run.isCancelled) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 85eb64491377..838e5918846f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1232,8 +1232,8 @@ class Typer extends Namer val pat1 = typedPattern(tree.pat, wideSelType)(gadtCtx) caseRest(pat1)( - given Nullables.caseContext(sel, pat1)( - given gadtCtx.fresh.setNewScope)) + using Nullables.caseContext(sel, pat1)( + using gadtCtx.fresh.setNewScope)) } def typedLabeled(tree: untpd.Labeled)(implicit ctx: Context): Labeled = { @@ -2345,7 +2345,7 @@ class Typer extends Namer // in preceding statements (unless the DefTree is completed ahead of time, // then it is impossible). sym.info = Completer(completer.original)( - given completer.creationContext.withNotNullInfos(ctx.notNullInfos)) + using completer.creationContext.withNotNullInfos(ctx.notNullInfos)) true case _ => // If it has been completed, then it must be because there is a forward reference diff --git a/compiler/test-resources/repl/defs b/compiler/test-resources/repl/defs index 7e9570b3ec30..1c2e9daeb637 100644 --- a/compiler/test-resources/repl/defs +++ b/compiler/test-resources/repl/defs @@ -10,5 +10,5 @@ scala> def id(x: 4): 4 = x def id(x: 4): 4 scala> id(4) val res0: Int = 4 -scala> def f(given Int) = 1 -def f(given x$1: Int): Int +scala> def f(using Int) = 1 +def f(using x$1: Int): Int diff --git a/compiler/test-resources/repl/erased-implicit b/compiler/test-resources/repl/erased-implicit index ffaba6595a79..5b1ec654c2aa 100644 --- a/compiler/test-resources/repl/erased-implicit +++ b/compiler/test-resources/repl/erased-implicit @@ -1,2 +1,2 @@ -scala> def f(given erased a: Int): Int = ??? -def f(given erased a: Int): Int +scala> def f(using erased a: Int): Int = ??? +def f(using erased a: Int): Int diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index a61ee673b546..ebf967ce9b96 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -1685,23 +1685,10 @@ class ErrorMessagesTests extends ErrorMessagesTest { assertEquals("List[X]", lastChecked.show) } - @Test def implicitTypesCanOnlyBeFunctionTypesSuccess() = - checkMessagesAfter(RefChecks.name) ("def foo(f: (given Int) => Int): Int = 1") - .expectNoErrors - @Test def erasedTypesCanOnlyBeFunctionTypesSuccess() = checkMessagesAfter(FrontEnd.name) ("def foo(f: (erased Int) => Int): Int = 1") .expectNoErrors - @Test def implicitTypesCanOnlyBeFunctionTypesFailed() = - checkMessagesAfter(FrontEnd.name) ("def foo(f: (given Int)): Int = 1") - .expect { (ictx, messages) => - implicit val ctx: Context = ictx - assertMessageCount(1, messages) - val ImplicitTypesCanOnlyBeFunctionTypes() :: Nil = messages - assertEquals("Types with given keyword can only be function types `(given ...) => ...`", messages.head.msg) - } - @Test def erasedTypesCanOnlyBeFunctionTypesFailed() = checkMessagesAfter(FrontEnd.name) ("def foo(f: (erased Int)): Int = 1") .expect { (ictx, messages) => @@ -1726,11 +1713,11 @@ class ErrorMessagesTests extends ErrorMessagesTest { } @Test def caseClassMissingNonImplicitParamListSuccessful = - checkMessagesAfter(FrontEnd.name) ("case class Test()(given foo: String)") + checkMessagesAfter(FrontEnd.name) ("case class Test()(using foo: String)") .expectNoErrors @Test def caseClassMissingNonImplicitParamListFailed = - checkMessagesAfter(FrontEnd.name) ("case class Test(given foo: String)") + checkMessagesAfter(FrontEnd.name) ("case class Test(using foo: String)") .expect { (ictx, messages) => implicit val ctx: Context = ictx diff --git a/docs/docs/reference/changed-features/numeric-literals.md b/docs/docs/reference/changed-features/numeric-literals.md index ab67018861b3..4239cc21db01 100644 --- a/docs/docs/reference/changed-features/numeric-literals.md +++ b/docs/docs/reference/changed-features/numeric-literals.md @@ -201,7 +201,7 @@ no code that can be executed at runtime. That's why we define an intermediary cl method in the `FromDigits` given instance. That method is defined in terms of a macro implementation method `fromDigitsImpl`. Here is its definition: ```scala - private def fromDigitsImpl(digits: Expr[String])(given ctx: QuoteContext): Expr[BigFloat] = + private def fromDigitsImpl(digits: Expr[String])(using ctx: QuoteContext): Expr[BigFloat] = digits match { case Const(ds) => try { diff --git a/docs/docs/reference/contextual/derivation-macro.md b/docs/docs/reference/contextual/derivation-macro.md index 9fdb08730e7c..d5bf586ffe46 100644 --- a/docs/docs/reference/contextual/derivation-macro.md +++ b/docs/docs/reference/contextual/derivation-macro.md @@ -25,7 +25,7 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that produces a quoted instance for `Eq[T]`. Here is a possible signature, ```scala -given derived[T: Type](given qctx: QuoteContext): Expr[Eq[T]] +given derived[T: Type](using qctx: QuoteContext): Expr[Eq[T]] ``` and for comparison reasons we give the same signature we had with `inline`: @@ -41,10 +41,10 @@ from the signature. The body of the `derived` method is shown below: ```scala -given derived[T: Type](given qctx: QuoteContext): Expr[Eq[T]] = { +given derived[T: Type](using qctx: QuoteContext): Expr[Eq[T]] = { import qctx.tasty.{_, given} - val ev: Expr[Mirror.Of[T]] = summonExpr(given '[Mirror.Of[T]]).get + val ev: Expr[Mirror.Of[T]] = summonExpr(using '[Mirror.Of[T]]).get ev match { case '{ $m: Mirror.ProductOf[T] { type MirroredElemTypes = $elementTypes }} => @@ -91,10 +91,10 @@ The implementation of `summonAll` as a macro can be show below assuming that we have the given instances for our primitive types: ```scala - def summonAll[T](t: Type[T])(given qctx: QuoteContext): List[Expr[Eq[_]]] = t match { + def summonAll[T](t: Type[T])(using qctx: QuoteContext): List[Expr[Eq[_]]] = t match { case '[String *: $tpes] => '{ summon[Eq[String]] } :: summonAll(tpes) case '[Int *: $tpes] => '{ summon[Eq[Int]] } :: summonAll(tpes) - case '[$tpe *: $tpes] => derived(given tpe, qctx) :: summonAll(tpes) + case '[$tpe *: $tpes] => derived(using tpe, qctx) :: summonAll(tpes) case '[Unit] => Nil } ``` @@ -120,7 +120,7 @@ Alternatively and what is shown below is that we can call the `eqv` method directly. The `eqGen` can trigger the derivation. ```scala -inline def [T](x: =>T) === (y: =>T)(given eq: Eq[T]): Boolean = eq.eqv(x, y) +inline def [T](x: =>T) === (y: =>T)(using eq: Eq[T]): Boolean = eq.eqv(x, y) implicit inline def eqGen[T]: Eq[T] = ${ Eq.derived[T] } ``` @@ -168,17 +168,17 @@ object Eq { def eqv(x: T, y: T): Boolean = body(x, y) } - def summonAll[T](t: Type[T])(given qctx: QuoteContext): List[Expr[Eq[_]]] = t match { + def summonAll[T](t: Type[T])(using qctx: QuoteContext): List[Expr[Eq[_]]] = t match { case '[String *: $tpes] => '{ summon[Eq[String]] } :: summonAll(tpes) case '[Int *: $tpes] => '{ summon[Eq[Int]] } :: summonAll(tpes) - case '[$tpe *: $tpes] => derived(given tpe, qctx) :: summonAll(tpes) + case '[$tpe *: $tpes] => derived(using tpe, qctx) :: summonAll(tpes) case '[Unit] => Nil } - given derived[T: Type](given qctx: QuoteContext): Expr[Eq[T]] = { + given derived[T: Type](using qctx: QuoteContext): Expr[Eq[T]] = { import qctx.tasty.{_, given} - val ev: Expr[Mirror.Of[T]] = summonExpr(given '[Mirror.Of[T]]).get + val ev: Expr[Mirror.Of[T]] = summonExpr(using '[Mirror.Of[T]]).get ev match { case '{ $m: Mirror.ProductOf[T] { type MirroredElemTypes = $elementTypes }} => @@ -216,7 +216,7 @@ object Eq { } object Macro3 { - inline def [T](x: =>T) === (y: =>T)(given eq: Eq[T]): Boolean = eq.eqv(x, y) + inline def [T](x: =>T) === (y: =>T)(using eq: Eq[T]): Boolean = eq.eqv(x, y) implicit inline def eqGen[T]: Eq[T] = ${ Eq.derived[T] } } diff --git a/docs/docs/reference/metaprogramming/macros.md b/docs/docs/reference/metaprogramming/macros.md index b16dd4d62dfc..9f84bcecd7a6 100644 --- a/docs/docs/reference/metaprogramming/macros.md +++ b/docs/docs/reference/metaprogramming/macros.md @@ -713,7 +713,7 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using val argShowedExprs = argExprs.map { case '{ $arg: $tp } => val showTp = '[Show[$tp]] - summonExpr(given showTp)) match { + summonExpr(using showTp)) match { case Some(showExpr) => '{ $showExpr.show($arg) } case None => qctx.error(s"could not find implicit for ${showTp.show}", arg); '{???} } diff --git a/docs/docs/reference/other-new-features/quoted-pattern-spec.md b/docs/docs/reference/other-new-features/quoted-pattern-spec.md index 07712dad0ce6..a9fffdc35732 100644 --- a/docs/docs/reference/other-new-features/quoted-pattern-spec.md +++ b/docs/docs/reference/other-new-features/quoted-pattern-spec.md @@ -47,14 +47,14 @@ def notMatched = None def matched = Some(()) // aka Some(Tuple0()) def matched[T](x: T) = Some(Tuple1(x)) def (x: Matching) && (y: Matching) = if (x == None || y == None) None else Some(x.get ++ y.get) -def fold[T](m: Mattching*)(given Env): Matching = m.fold(matched)(_ && _) +def fold[T](m: Mattching*)(using Env): Matching = m.fold(matched)(_ && _) // `a =#= b` stands for `a` matches `b` -def (scrutinee: Tree) =#= pattern: Tree)(given Env): Matching // described by cases in the tables below +def (scrutinee: Tree) =#= pattern: Tree)(using Env): Matching // described by cases in the tables below -def envWith(equiv: (Symbol, Symbol)*)(given Env): Env // Adds to the current environment the fact that s1 from the scrutinee is equivalent to s2 in the pattern +def envWith(equiv: (Symbol, Symbol)*)(using Env): Env // Adds to the current environment the fact that s1 from the scrutinee is equivalent to s2 in the pattern -def equivalent(s1: Symbol, s2: Symbol)(given Env): Env +def equivalent(s1: Symbol, s2: Symbol)(using Env): Env ``` The implementation of `=#=` diff --git a/language-server/test/dotty/tools/languageserver/util/CodeTester.scala b/language-server/test/dotty/tools/languageserver/util/CodeTester.scala index 821eb86686b7..6dc18dfa5d29 100644 --- a/language-server/test/dotty/tools/languageserver/util/CodeTester.scala +++ b/language-server/test/dotty/tools/languageserver/util/CodeTester.scala @@ -237,7 +237,7 @@ class CodeTester(projects: List[Project]) { private def doAction(action: Action): this.type = { try { - action.execute()(given testServer, testServer.client, positions) + action.execute()(using testServer, testServer.client, positions) } catch { case ex: AssertionError => val sourcesStr = @@ -252,7 +252,7 @@ class CodeTester(projects: List[Project]) { | |$sourcesStr | - |while executing action: ${action.show(given positions)} + |while executing action: ${action.show(using positions)} | """.stripMargin val assertionError = new AssertionError(msg + ex.getMessage) diff --git a/language-server/test/dotty/tools/languageserver/util/PositionContext.scala b/language-server/test/dotty/tools/languageserver/util/PositionContext.scala index 257ebc5a4dd1..d99e0aa3a408 100644 --- a/language-server/test/dotty/tools/languageserver/util/PositionContext.scala +++ b/language-server/test/dotty/tools/languageserver/util/PositionContext.scala @@ -24,5 +24,5 @@ class PositionContext(positionMap: Map[CodeMarker, (TestFile, Int, Int)]) { } object PositionContext { - type PosCtx[T] = (given PositionContext) => T + type PosCtx[T] = PositionContext ?=> T } diff --git a/language-server/test/dotty/tools/languageserver/util/actions/Action.scala b/language-server/test/dotty/tools/languageserver/util/actions/Action.scala index 20c853907e82..cbf33eb60d16 100644 --- a/language-server/test/dotty/tools/languageserver/util/actions/Action.scala +++ b/language-server/test/dotty/tools/languageserver/util/actions/Action.scala @@ -11,7 +11,7 @@ import PositionContext._ * definition, etc.) */ trait Action { - type Exec[T] = (given TestServer, TestClient, PositionContext) => T + type Exec[T] = (TestServer, TestClient, PositionContext) ?=> T /** Execute the action. */ def execute(): Exec[Unit] diff --git a/sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello/Hello.scala b/sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello/Hello.scala index 49e8287e93eb..c9f2f7f5157a 100644 --- a/sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello/Hello.scala +++ b/sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello/Hello.scala @@ -41,7 +41,7 @@ object Main { code } - def powerCode(n: Int, x: Expr[Double])(given QuoteContext): Expr[Double] = + def powerCode(n: Int, x: Expr[Double])(using QuoteContext): Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n < 0) throw new Exception("Negative powers not implemented. Left as a small exercise. Dont be shy, try it out.") diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/Macro.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/Macro.scala index 1540b3faabee..abc5619f4808 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/Macro.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/Macro.scala @@ -4,7 +4,7 @@ object Macro { inline def f(): Unit = ${ macroImplementation } - def macroImplementation(given QuoteContext): Expr[Unit] = { + def macroImplementation(using QuoteContext): Expr[Unit] = { '{ println("Implementation in Macro") } } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala index cd91962130da..3942d3a1bd4d 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroCompileError.scala @@ -4,7 +4,7 @@ object Macro { inline def f(): Unit = ${ macroImplementation } - def macroImplementation(given qctx: QuoteContext): Expr[Unit] = { + def macroImplementation(using qctx: QuoteContext): Expr[Unit] = { import qctx.tasty._ error("some error", rootPosition) '{ println("Implementation in MacroCompileError") } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroRuntimeError.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroRuntimeError.scala index 23a4e6665154..69aef00d8ee0 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroRuntimeError.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-1/changes/MacroRuntimeError.scala @@ -4,7 +4,7 @@ object Macro { inline def f(): Unit = ${ macroImplementation } - def macroImplementation(given qctx: QuoteContext): Expr[Unit] = { + def macroImplementation(using qctx: QuoteContext): Expr[Unit] = { '{ ??? } } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/Macro.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/Macro.scala index 138a629f8761..1e8ffe26af6b 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/Macro.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/Macro.scala @@ -4,7 +4,7 @@ object Macro { inline def f(): Unit = ${ macroImplementation } - def macroImplementation(given QuoteContext): Expr[Unit] = + def macroImplementation(using QuoteContext): Expr[Unit] = MacroRuntime.impl() diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntime.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntime.scala index 011ac9885f86..049626fa3810 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntime.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntime.scala @@ -2,7 +2,7 @@ import scala.quoted._ object MacroRuntime { - def impl()(given QuoteContext): Expr[Unit] = { + def impl()(using QuoteContext): Expr[Unit] = { '{ println("Implementation in Macro") } } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala index d06584e0023e..1af0eddfbd9e 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeCompileError.scala @@ -2,7 +2,7 @@ import scala.quoted._ object MacroRuntime { - def impl()(given qctx: QuoteContext): Expr[Unit] = { + def impl()(using qctx: QuoteContext): Expr[Unit] = { import qctx.tasty._ error("some error", rootPosition) '{ println("Implementation in MacroCompileError") } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeRuntimeError.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeRuntimeError.scala index dcda4e276c3f..41e823c63cda 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeRuntimeError.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-2/changes/MacroRuntimeRuntimeError.scala @@ -2,7 +2,7 @@ import scala.quoted._ object MacroRuntime { - def impl()(given qctx: QuoteContext): Expr[Unit] = { + def impl()(using qctx: QuoteContext): Expr[Unit] = { '{ ??? } } diff --git a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-3/Macros.scala b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-3/Macros.scala index e40323fff85a..a586bb70b5ca 100644 --- a/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-3/Macros.scala +++ b/sbt-dotty/sbt-test/source-dependencies/macro-expansion-dependencies-3/Macros.scala @@ -4,7 +4,7 @@ object Macros { inline def foo: A = ${ fooImpl } - def fooImpl(given qctx: QuoteContext): Expr[A] = { + def fooImpl(using qctx: QuoteContext): Expr[A] = { new B().f '{ new A; } } diff --git a/staging/src/scala/quoted/staging/staging.scala b/staging/src/scala/quoted/staging/staging.scala index c73aee205029..10f8f40db999 100644 --- a/staging/src/scala/quoted/staging/staging.scala +++ b/staging/src/scala/quoted/staging/staging.scala @@ -7,7 +7,7 @@ package object staging { * * Usage: * ``` - * val e: T = run { // (given qctx: QuoteContext) => + * val e: T = run { // (using qctx: QuoteContext) => * expr * } * ``` @@ -16,7 +16,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 run[T](expr: (given QuoteContext) => Expr[T])(given toolbox: Toolbox): T = toolbox.run(expr(given _)) + def run[T](expr: QuoteContext ?=> Expr[T])(using toolbox: Toolbox): T = toolbox.run(expr(using _)) /** Provide a new quote context within the scope of the argument that is only valid within the scope the argument. * Return the result of the argument. @@ -32,14 +32,14 @@ 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: QuoteContext ?=> T)(given toolbox: Toolbox): T = { + def withQuoteContext[T](thunk: QuoteContext ?=> T)(using toolbox: Toolbox): T = { val noResult = new Object var result: T = noResult.asInstanceOf[T] - def dummyRun(given QuoteContext): Expr[Unit] = { + def dummyRun(using QuoteContext): Expr[Unit] = { result = thunk Expr.unitExpr } - toolbox.run(dummyRun(given _)) + toolbox.run(dummyRun(using _)) assert(result != noResult) // toolbox.run should have thrown an exception result } diff --git a/staging/test-resources/repl-staging/i6007 b/staging/test-resources/repl-staging/i6007 index e5c8dc587edd..e8efbbcf9d9c 100644 --- a/staging/test-resources/repl-staging/i6007 +++ b/staging/test-resources/repl-staging/i6007 @@ -2,8 +2,8 @@ scala> import scala.quoted._ scala> import scala.quoted.staging._ scala> implicit def toolbox: Toolbox = Toolbox.make(getClass.getClassLoader) def toolbox: quoted.staging.Toolbox -scala> def v(given QuoteContext) = '{ (if true then Some(1) else None).map(v => v+1) } -def v(given x$1: quoted.QuoteContext): quoted.Expr[Option[Int]] +scala> def v(using QuoteContext) = '{ (if true then Some(1) else None).map(v => v+1) } +def v(using x$1: quoted.QuoteContext): quoted.Expr[Option[Int]] scala> scala.quoted.staging.withQuoteContext(v.show) val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1))) scala> scala.quoted.staging.run(v) diff --git a/tasty/src/dotty/tools/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala index 805cb939fb95..439be1400cd0 100644 --- a/tasty/src/dotty/tools/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -163,8 +163,8 @@ Standard-Section: "ASTs" TopLevelStat* POLYtype Length result_Type NamesTypes -- A polymorphic method type `[NamesTypes]result`, used in refinements METHODtype Length result_Type NamesTypes -- A method type `(NamesTypes)result`, needed for refinements ERASEDMETHODtype Length result_Type NamesTypes -- A method type `erased (NamesTypes)result`, needed for refinements - GIVENMETHODtype Length result_Type NamesTypes -- A method type `(given NamesTypes)result`, needed for refinements - ERASEDGIVENMETHODtype Length result_Type NamesTypes -- A method type `given(erased NamesTypes)result`, needed for refinements + GIVENMETHODtype Length result_Type NamesTypes -- A method type `(using NamesTypes)result`, needed for refinements + ERASEDGIVENMETHODtype Length result_Type NamesTypes -- A method type `(using erased NamesTypes)result`, needed for refinements IMPLICITMETHODtype Length result_Type NamesTypes -- A method type `(implicit NamesTypes)result`, needed for refinements // TODO: remove ERASEDIMPLICITMETHODtype TYPELAMBDAtype Length result_Type NamesTypes -- A type lambda `[NamesTypes] => result` diff --git a/tastydoc/src/dotty/tastydoc/TastyExtractor.scala b/tastydoc/src/dotty/tastydoc/TastyExtractor.scala index 546e674cc000..065b498debaf 100644 --- a/tastydoc/src/dotty/tastydoc/TastyExtractor.scala +++ b/tastydoc/src/dotty/tastydoc/TastyExtractor.scala @@ -58,7 +58,7 @@ trait TastyExtractor extends TastyTypeConverter with CommentParser with CommentC } } - def extractClassMembers(reflect: Reflection)(body: List[reflect.Statement], symbol: reflect.Symbol, parentRepresentation: Some[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) : List[Representation with Modifiers] = { + def extractClassMembers(reflect: Reflection)(body: List[reflect.Statement], symbol: reflect.Symbol, parentRepresentation: Some[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) : List[Representation with Modifiers] = { import reflect.{given, _} /** Filter fields which shouldn't be displayed in the doc diff --git a/tastydoc/src/dotty/tastydoc/TastydocInspector.scala b/tastydoc/src/dotty/tastydoc/TastydocInspector.scala index 610e67c5f1c1..31ec97264ce3 100644 --- a/tastydoc/src/dotty/tastydoc/TastydocInspector.scala +++ b/tastydoc/src/dotty/tastydoc/TastydocInspector.scala @@ -14,6 +14,6 @@ class TastydocInspector(mutablePackagesMap: scala.collection.mutable.HashMap[Str protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = { import reflect._ - representations.convertToRepresentation(reflect)(root, None)(given mutablePackagesMap) + representations.convertToRepresentation(reflect)(root, None)(using mutablePackagesMap) } } diff --git a/tastydoc/src/dotty/tastydoc/representations.scala b/tastydoc/src/dotty/tastydoc/representations.scala index 52dc40de0445..54bb9cd37f34 100644 --- a/tastydoc/src/dotty/tastydoc/representations.scala +++ b/tastydoc/src/dotty/tastydoc/representations.scala @@ -62,7 +62,7 @@ object representations extends TastyExtractor { /** This contains all the PackageRepresentation representing a single package */ - class EmulatedPackageRepresentation(val name: String, val path: List[String])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members { + class EmulatedPackageRepresentation(val name: String, val path: List[String])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members { override val parentRepresentation = None override val annotations = Nil override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = None @@ -82,7 +82,7 @@ object representations extends TastyExtractor { } } - class PackageRepresentation(reflect: Reflection, internal: reflect.PackageClause, override val parentRepresentation: Option[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members { + class PackageRepresentation(reflect: Reflection, internal: reflect.PackageClause, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members { import reflect.{given, _} override val (name, path) = extractPackageNameAndPath(internal.pid.show) @@ -92,7 +92,7 @@ object representations extends TastyExtractor { override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(reflect)(internal.symbol.comment, this)(packages, userDocSyntax) } - class ImportRepresentation(reflect: Reflection, internal: reflect.Import, override val parentRepresentation: Option[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation { + class ImportRepresentation(reflect: Reflection, internal: reflect.Import, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation { import reflect.{given, _} override val name = if (internal.selectors.size > 1){ @@ -106,7 +106,7 @@ object representations extends TastyExtractor { override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(reflect)(internal.symbol.comment, this)(packages, userDocSyntax) } - class ClassRepresentation(reflect: Reflection, internal: reflect.ClassDef, override val parentRepresentation: Option[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members with Parents with Modifiers with Companion with Constructors with TypeParams { + class ClassRepresentation(reflect: Reflection, internal: reflect.ClassDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Members with Parents with Modifiers with Companion with Constructors with TypeParams { import reflect.{given, _} override val path = extractPath(reflect)(internal.symbol) @@ -142,7 +142,7 @@ object representations extends TastyExtractor { override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(reflect)(internal.symbol.comment, this)(packages, userDocSyntax) } - class DefRepresentation(reflect: Reflection, internal: reflect.DefDef, override val parentRepresentation: Option[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams with MultipleParamList with ReturnValue { + class DefRepresentation(reflect: Reflection, internal: reflect.DefDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams with MultipleParamList with ReturnValue { import reflect.{given, _} override val name = internal.name @@ -161,7 +161,7 @@ object representations extends TastyExtractor { override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(reflect)(internal.symbol.comment, this)(packages, userDocSyntax) } - class ValRepresentation(reflect: Reflection, internal: reflect.ValDef, override val parentRepresentation: Option[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with ReturnValue { + class ValRepresentation(reflect: Reflection, internal: reflect.ValDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with ReturnValue { import reflect.{given, _} override val name = internal.name @@ -174,7 +174,7 @@ object representations extends TastyExtractor { override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(reflect)(internal.symbol.comment, this)(packages, userDocSyntax) } - class TypeRepresentation(reflect: Reflection, internal: reflect.TypeDef, override val parentRepresentation: Option[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams { + class TypeRepresentation(reflect: Reflection, internal: reflect.TypeDef, override val parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]) extends Representation with Modifiers with TypeParams { import reflect.{given, _} override val name = internal.name @@ -191,7 +191,7 @@ object representations extends TastyExtractor { override def comments(packages: Map[String, EmulatedPackageRepresentation], userDocSyntax: String) = extractComments(reflect)(internal.symbol.comment, this)(packages, userDocSyntax) } - def convertToRepresentation(reflect: Reflection)(tree: reflect.Tree, parentRepresentation: Option[Representation])(given mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]): Representation = { + def convertToRepresentation(reflect: Reflection)(tree: reflect.Tree, parentRepresentation: Option[Representation])(using mutablePackagesMap: scala.collection.mutable.HashMap[String, EmulatedPackageRepresentation]): Representation = { import reflect.{given, _} tree match { 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 545da384ed84..867388d6ba13 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 @@ -4,7 +4,7 @@ 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])(using QuoteContext): Expr[Int] = { given Toolbox = Toolbox.make(getClass.getClassLoader) val y: Int = run(i) y diff --git a/tests/neg-macros/i7142h/Macro_1.scala b/tests/neg-macros/i7142h/Macro_1.scala index f33e6410a94a..03a5d7af1594 100644 --- a/tests/neg-macros/i7142h/Macro_1.scala +++ b/tests/neg-macros/i7142h/Macro_1.scala @@ -3,7 +3,7 @@ import scala.quoted._ var saved = Option.empty[Expr[Int]] -def oops(given QuoteContext) = { +def oops(using QuoteContext) = { if (saved.isEmpty) '{ (x: Int) => ${ saved = Some('{x}); 'x } } else saved.get } diff --git a/tests/neg/i8150.scala b/tests/neg/i8150.scala index d286201acf81..2f0505c6265a 100644 --- a/tests/neg/i8150.scala +++ b/tests/neg/i8150.scala @@ -1,3 +1,3 @@ trait A trait B -type T = {given(given a: A) as B} // error: refinement cannot be `given` \ No newline at end of file +type T = {given(using a: A) as B} // error: refinement cannot be `given` \ No newline at end of file diff --git a/tests/pos/i7851.scala b/tests/pos/i7851.scala index 92bc34ed184f..695bc839ec8e 100644 --- a/tests/pos/i7851.scala +++ b/tests/pos/i7851.scala @@ -16,7 +16,7 @@ given [H: Wrappable, T <: Tuple, WrappedT0 <: Tuple](using Wrapper.Aux[T, Wrappe def wrappedFunction[F, FArgs <: Tuple, WrapperFArgs <: Tuple, R: Wrappable]( function: F -)(input: FArgs)(given +)(input: FArgs)(using tf: TupledFunction[F, WrapperFArgs => Wrapped[R]], vs: Wrapper.Aux[FArgs, WrapperFArgs] ): (R, R => Option[FArgs]) = { diff --git a/tests/pos/i8198.scala b/tests/pos/i8198.scala index 0fa8ec704325..03fbd31a07e0 100644 --- a/tests/pos/i8198.scala +++ b/tests/pos/i8198.scala @@ -5,6 +5,6 @@ trait Eq[A] { case class Id[T](id: T) -given idEq[A](given eqA: Eq[A]): Eq[Id[A]] = new { +given idEq[A](using eqA: Eq[A]): Eq[Id[A]] = new { def (i1: Id[A]) === (i2: Id[A]) = !(i1.id /== i2.id) }