diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index b8885b6118b6..e6f3c1cd15f1 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -167,7 +167,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline) - case class Instance()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implied) + case class Implied()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implied) } /** Modifiers and annotations for definitions diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index fcb019bef9a5..ca6bb80166bb 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -198,8 +198,8 @@ object Parsers { !in.isSoftModifierInModifierPosition def isExprIntro: Boolean = - canStartExpressionTokens.contains(in.token) && - !in.isSoftModifierInModifierPosition + if (in.token == IMPLIED) in.lookaheadIn(BitSet(MATCH)) + else (canStartExpressionTokens.contains(in.token) && !in.isSoftModifierInModifierPosition) def isDefIntro(allowedMods: BitSet): Boolean = in.token == AT || @@ -1265,7 +1265,7 @@ object Parsers { * | SimpleExpr1 ArgumentExprs `=' Expr * | Expr2 * | [‘inline’] Expr2 `match' `{' CaseClauses `}' - * | `implicit' `match' `{' ImplicitCaseClauses `}' + * | `implied' `match' `{' ImplicitCaseClauses `}' * Bindings ::= `(' [Binding {`,' Binding}] `)' * Binding ::= (id | `_') [`:' Type] * Expr2 ::= PostfixExpr [Ascription] @@ -1281,9 +1281,19 @@ object Parsers { val start = in.offset if (closureMods.contains(in.token)) { val imods = modifiers(closureMods) - if (in.token == MATCH) implicitMatch(start, imods) + if (in.token == MATCH) impliedMatch(start, imods) else implicitClosure(start, location, imods) - } else { + } + else if(in.token == IMPLIED) { + in.nextToken() + if (in.token == MATCH) + impliedMatch(start, EmptyModifiers) + else { + syntaxError("`match` expected") + EmptyTree + } + } + else { val saved = placeholderParams placeholderParams = Nil @@ -1457,13 +1467,13 @@ object Parsers { /** `match' { ImplicitCaseClauses } */ - def implicitMatch(start: Int, imods: Modifiers) = { + def impliedMatch(start: Int, imods: Modifiers) = { def markFirstIllegal(mods: List[Mod]) = mods match { - case mod :: _ => syntaxError(em"illegal modifier for implicit match", mod.span) + case mod :: _ => syntaxError(em"illegal modifier for implied match", mod.span) case _ => } imods.mods match { - case Mod.Implicit() :: mods => markFirstIllegal(mods) + case (Mod.Implicit() | Mod.Implied()) :: mods => markFirstIllegal(mods) case mods => markFirstIllegal(mods) } val result @ Match(t, cases) = @@ -1474,7 +1484,7 @@ object Parsers { case pat => isVarPattern(pat) } if (!isImplicitPattern(pat)) - syntaxError(em"not a legal pattern for an implicit match", pat.span) + syntaxError(em"not a legal pattern for an implied match", pat.span) } result } @@ -2668,7 +2678,7 @@ object Parsers { case ENUM => enumDef(start, posMods(start, mods | Enum)) case IMPLIED => - instanceDef(start, mods, atSpan(in.skipToken()) { Mod.Instance() }) + instanceDef(start, mods, atSpan(in.skipToken()) { Mod.Implied() }) case _ => syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition()) EmptyTree @@ -3088,7 +3098,7 @@ object Parsers { if (isBindingIntro) stats += implicitClosure(start, Location.InBlock, imods) else if (in.token == MATCH) - stats += implicitMatch(start, imods) + stats += impliedMatch(start, imods) else stats +++= localDef(start, imods) } else { diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index 38785e436e79..08ae356c5759 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -216,7 +216,7 @@ object Tokens extends TokensCommon { USCORE, NULL, THIS, SUPER, TRUE, FALSE, RETURN, QUOTEID, XMLSTART) final val canStartExpressionTokens: TokenSet = atomicExprTokens | BitSet( - LBRACE, LPAREN, QUOTE, IF, DO, WHILE, FOR, NEW, TRY, THROW) + LBRACE, LPAREN, QUOTE, IF, DO, WHILE, FOR, NEW, TRY, THROW, IMPLIED) final val canStartTypeTokens: TokenSet = literalTokens | identifierTokens | BitSet( THIS, SUPER, USCORE, LPAREN, AT) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index b28c9c7a5480..1b5cfe9e8d95 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -550,7 +550,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match = tpd.cpy.Match(original)(selector, cases) - type ImplicitMatch = tpd.Match + type ImpliedMatch = tpd.Match def matchImplicitMatch(x: Term)(implicit ctx: Context): Option[Match] = x match { case x: tpd.Match if x.selector.isEmpty => Some(x) @@ -559,10 +559,10 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def ImplicitMatch_cases(self: Match)(implicit ctx: Context): List[CaseDef] = self.cases - def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch = + def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch = withDefaultPos(ctx => tpd.Match(tpd.EmptyTree, cases)(ctx)) - def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch = + def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch = tpd.cpy.Match(original)(tpd.EmptyTree, cases) type Try = tpd.Try diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 616a490a956c..d6e34fcd5a4c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -720,9 +720,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { /** Reduce an inline match * @param mtch the match tree * @param scrutinee the scrutinee expression, assumed to be pure, or - * EmptyTree for an implicit match + * EmptyTree for an implied match * @param scrutType its fully defined type, or - * ImplicitScrutineeTypeRef for an implicit match + * ImplicitScrutineeTypeRef for an implied match * @param typer The current inline typer * @return optionally, if match can be reduced to a matching case: A pair of * bindings for all pattern-bound variables and the RHS of the case. @@ -1036,7 +1036,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { def patStr(cdef: untpd.CaseDef) = i"case ${cdef.pat}${guardStr(cdef.guard)}" val msg = if (tree.selector.isEmpty) - em"""cannot reduce implicit match with + em"""cannot reduce implied match with | patterns : ${tree.cases.map(patStr).mkString("\n ")}""" else em"""cannot reduce inline match with diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index aa4a1cea0304..f50890516e7b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1021,7 +1021,7 @@ class Typer extends Namer tree.selector match { case EmptyTree => if (tree.isInline) { - checkInInlineContext("implicit match", tree.posd) + checkInInlineContext("implied match", tree.posd) val cases1 = tree.cases.mapconserve { case cdef @ CaseDef(pat @ Typed(Ident(nme.WILDCARD), _), _, _) => // case _ : T --> case evidence$n : T diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index 911d9647c551..689b9500653c 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -29,7 +29,7 @@ package scala.tasty.reflect * | +- Lambda * | +- If * | +- Match - * | +- ImplicitMatch + * | +- ImpliedMatch * | +- Try * | +- Return * | +- Repeated @@ -209,8 +209,8 @@ trait Core { /** Tree representing a pattern match `x match { ... }` in the source code */ type Match = kernel.Match - /** Tree representing a pattern match `implicit match { ... }` in the source code */ - type ImplicitMatch = kernel.ImplicitMatch + /** Tree representing a pattern match `implied match { ... }` in the source code */ + type ImpliedMatch = kernel.ImpliedMatch /** Tree representing a try catch `try x catch { ... } finally { ... }` in the source code */ type Try = kernel.Try diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 8d0d130f9abd..9a91663dc4af 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -28,7 +28,7 @@ package scala.tasty.reflect * | +- Lambda * | +- If * | +- Match - * | +- ImplicitMatch + * | +- ImpliedMatch * | +- Try * | +- Return * | +- Repeated @@ -476,15 +476,15 @@ trait Kernel { def Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match - /** Tree representing a pattern match `implicit match { ... }` in the source code */ - type ImplicitMatch <: Term + /** Tree representing a pattern match `implied match { ... }` in the source code */ + type ImpliedMatch <: Term - def matchImplicitMatch(tree: Tree)(implicit ctx: Context): Option[ImplicitMatch] + def matchImplicitMatch(tree: Tree)(implicit ctx: Context): Option[ImpliedMatch] - def ImplicitMatch_cases(self: ImplicitMatch)(implicit ctx: Context): List[CaseDef] + def ImplicitMatch_cases(self: ImpliedMatch)(implicit ctx: Context): List[CaseDef] - def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch - def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch + def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch + def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch /** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */ type Try <: Term diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index fae447c36c72..0d4fd82517b9 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -186,8 +186,8 @@ trait Printers this += "Lambda(" += meth += ", " += tpt += ")" case Match(selector, cases) => this += "Match(" += selector += ", " ++= cases += ")" - case ImplicitMatch(cases) => - this += "ImplicitMatch(" ++= cases += ")" + case ImpliedMatch(cases) => + this += "ImpliedMatch(" ++= cases += ")" case Return(expr) => this += "Return(" += expr += ")" case While(cond, body) => @@ -909,8 +909,8 @@ trait Printers this += highlightKeyword(" match", color) inBlock(printCases(cases, lineBreak())) - case ImplicitMatch(cases) => - this += highlightKeyword("implicit match", color) + case ImpliedMatch(cases) => + this += highlightKeyword("implied match", color) inBlock(printCases(cases, lineBreak())) case Try(body, cases, finallyOpt) => diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index e2c28c98d070..619f0d4b8a4e 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -591,27 +591,27 @@ trait TreeOps extends Core { } object IsImplicitMatch { - /** Matches any ImplicitMatch and returns it */ - def unapply(tree: Tree)(implicit ctx: Context): Option[ImplicitMatch] = kernel.matchImplicitMatch(tree) + /** Matches any ImpliedMatch and returns it */ + def unapply(tree: Tree)(implicit ctx: Context): Option[ImpliedMatch] = kernel.matchImplicitMatch(tree) } /** Scala implicit `match` term */ - object ImplicitMatch { + object ImpliedMatch { - /** Creates a pattern match `implicit match { }` */ - def apply(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch = + /** Creates a pattern match `implied match { }` */ + def apply(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch = kernel.ImplicitMatch_apply(cases) - def copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch = + def copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch = kernel.ImplicitMatch_copy(original)(cases) - /** Matches a pattern match `implicit match { }` */ + /** Matches a pattern match `implied match { }` */ def unapply(tree: Tree)(implicit ctx: Context): Option[List[CaseDef]] = kernel.matchImplicitMatch(tree).map(_.cases) } - implicit class ImplicitMatchAPI(self: ImplicitMatch) { + implicit class ImplicitMatchAPI(self: ImpliedMatch) { def cases(implicit ctx: Context): List[CaseDef] = kernel.ImplicitMatch_cases(self) } diff --git a/tests/invalid/neg/implicitMatch-ambiguous.scala b/tests/invalid/neg/implicitMatch-ambiguous.scala index 5369190517b0..d898b4025db9 100644 --- a/tests/invalid/neg/implicitMatch-ambiguous.scala +++ b/tests/invalid/neg/implicitMatch-ambiguous.scala @@ -4,7 +4,7 @@ object Test { implicit val a1: A = new A implicit val a2: A = new A - inline def f: Any = implicit match { + inline def f: Any = implied match { case _: A => ??? // error: ambiguous implicits } diff --git a/tests/invalid/run/typelevel.scala b/tests/invalid/run/typelevel.scala index a4bb6fc5b5db..1461dc1b3a38 100644 --- a/tests/invalid/run/typelevel.scala +++ b/tests/invalid/run/typelevel.scala @@ -153,7 +153,7 @@ object Test extends App { case S[type N] => toInt[N] + 1 } - inline def toInt1[T]: Nat = implicit match { + inline def toInt1[T]: Nat = implied match { case C[type T, type U], T =:= U => case T <:< S[type N] => toInt[N] + 1 } diff --git a/tests/neg/implicit-match-ambiguous-bind.scala b/tests/neg/implicit-match-ambiguous-bind.scala index 04cec2a79d5f..a54374f745d4 100644 --- a/tests/neg/implicit-match-ambiguous-bind.scala +++ b/tests/neg/implicit-match-ambiguous-bind.scala @@ -2,7 +2,7 @@ object `implicit-match-ambiguous-bind` { case class Box[T](value: T) implicit val ibox: Box[Int] = Box(0) implicit val sbox: Box[String] = Box("") - inline def unbox = implicit match { + inline def unbox = implied match { case b: Box[t] => b.value // error } val unboxed = unbox diff --git a/tests/neg/implicitMatch-syntax.scala b/tests/neg/implicitMatch-syntax.scala index 2df0357a01da..f6e565e018c1 100644 --- a/tests/neg/implicitMatch-syntax.scala +++ b/tests/neg/implicitMatch-syntax.scala @@ -2,32 +2,32 @@ object Test { import collection.immutable.TreeSet import collection.immutable.HashSet - inline def f1[T] = implicit implicit match { // error: repeated modifier // error: illegal modifier - case ord: Ordered[T] => new TreeSet[T] // error: no implicit + inline def f1[T] = implied implied match { // error: illegal modifier // error: ';' expected, but 'match' found // error: Declaration of method f1 not allowed here + case ord: Ordered[T] => new TreeSet[T] case _ => new HashSet[T] } - inline def f2[T] = implicit erased match { // error: illegal modifier - case ord: Ordered[T] => new TreeSet[T] // error: no implicit + inline def f2[T] = implied erased match { // error: illegal modifier // error: illegal modifier // error: Declaration of method f1 not allowed here + case ord: Ordered[T] => new TreeSet[T] case _ => new HashSet[T] } - inline def f3[T] = erased implicit match { // error: illegal modifier - case ord: Ordered[T] => new TreeSet[T] // error: no implicit + inline def f3[T] = erased implied match { // error: illegal modifier + case ord: Ordered[T] => new TreeSet[T] case _ => new HashSet[T] } - inline def f4() = implicit match { + inline def f4() = implied match { case Nil => ??? // error: not a legal pattern case x :: xs => ??? // error: not a legal pattern } - inline def f5[T] = locally { implicit match { // Ok + inline def f5[T] = locally { implied match { // Ok case _ => new HashSet[T] }} - def f6[T] = implicit match { // error: implicit match cannot be used here + def f6[T] = implied match { // error: implied match cannot be used here case _ => new HashSet[T] } } \ No newline at end of file diff --git a/tests/neg/typeclass-derivation2.scala b/tests/neg/typeclass-derivation2.scala index ddb6517fb869..010d96d9ad62 100644 --- a/tests/neg/typeclass-derivation2.scala +++ b/tests/neg/typeclass-derivation2.scala @@ -213,7 +213,7 @@ object Show { import scala.compiletime.{erasedValue, error} import TypeLevel._ - inline def tryShow[T](x: T): String = implicit match { + inline def tryShow[T](x: T): String = implied match { case s: Show[T] => s.show(x) } diff --git a/tests/pending/pos/implicit-match.scala b/tests/pending/pos/implicit-match.scala index d0e5b515b90a..b98b55b32187 100644 --- a/tests/pending/pos/implicit-match.scala +++ b/tests/pending/pos/implicit-match.scala @@ -1,9 +1,9 @@ -// Implicit matches that bind parameters don't work yet. +// implied matches that bind parameters don't work yet. object `implicit-match` { object invariant { case class Box[T](value: T) implicit val box: Box[Int] = Box(0) - inline def unbox <: Any = implicit match { + inline def unbox <: Any = implied match { case b: Box[t] => b.value } val i: Int = unbox @@ -14,7 +14,7 @@ object `implicit-match` { object covariant { case class Box[+T](value: T) implicit val box: Box[Int] = Box(0) - inline def unbox <: Any = implicit match { + inline def unbox <: Any = implied match { case b: Box[t] => b.value } val i: Int = unbox @@ -25,7 +25,7 @@ object `implicit-match` { object contravariant { case class TrashCan[-T](trash: T => Unit) implicit val trashCan: TrashCan[Int] = TrashCan { i => ; } - inline def trash <: Nothing => Unit = implicit match { + inline def trash <: Nothing => Unit = implied match { case c: TrashCan[t] => c.trash } val t1: Int => Unit = trash diff --git a/tests/pos-special/typeclass-scaling.scala b/tests/pos-special/typeclass-scaling.scala index 56a6a3aa146f..15e56e06601b 100644 --- a/tests/pos-special/typeclass-scaling.scala +++ b/tests/pos-special/typeclass-scaling.scala @@ -217,7 +217,7 @@ object typeclasses { import compiletime._ import scala.deriving._ - inline def tryEql[TT](x: TT, y: TT): Boolean = implicit match { + inline def tryEql[TT](x: TT, y: TT): Boolean = implied match { case eq: Eq[TT] => eq.eql(x, y) } @@ -237,7 +237,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => eqlElems[m.MirroredElemTypes](0)(x, y) } else eqlCases[alts1](n + 1)(x, y, ord) @@ -274,7 +274,7 @@ object typeclasses { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implicit match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -290,14 +290,14 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => pickleElems[m.MirroredElemTypes](0)(buf, x) } else pickleCases[alts1](n + 1)(buf, x, ord) case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implicit match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -324,7 +324,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt` & T] => unpickleCase[`alt` & T, m.MirroredElemTypes](buf, m) } diff --git a/tests/pos/i5938.scala b/tests/pos/i5938.scala index 9872543e686e..2774abf7414d 100644 --- a/tests/pos/i5938.scala +++ b/tests/pos/i5938.scala @@ -1,8 +1,8 @@ trait Link[T, A] -inline def link[T] = implicit match { +inline def link[T] = implied match { case _: Link[T, s] => - implicit match { + implied match { case stuff: s => stuff } } diff --git a/tests/pos/i6014-gadt.scala b/tests/pos/i6014-gadt.scala index 39d2222fb76c..8bbf3f629245 100644 --- a/tests/pos/i6014-gadt.scala +++ b/tests/pos/i6014-gadt.scala @@ -10,7 +10,7 @@ object Test1 { } object Test2 { - inline def summon[T] = implicit match { + inline def summon[T] = implied match { case t: T => t } @@ -25,7 +25,7 @@ object Test2 { } object Test3 { - inline def summon[T] = implicit match { + inline def summon[T] = implied match { case t: T => t } @@ -42,7 +42,7 @@ object Test3 { } object Test4 { - inline def summon[T] = implicit match { + inline def summon[T] = implied match { case t: T => t } diff --git a/tests/pos/implicit-match-and-inline-match.scala b/tests/pos/implicit-match-and-inline-match.scala index fb76d2f64338..3d930a44a281 100644 --- a/tests/pos/implicit-match-and-inline-match.scala +++ b/tests/pos/implicit-match-and-inline-match.scala @@ -5,7 +5,7 @@ object `implicit-match-and-inline-match` { implicit val ibox: Box[Int] = Box(0) object a { - inline def isTheBoxInScopeAnInt = implicit match { + inline def isTheBoxInScopeAnInt = implied match { case _: Box[t] => inline erasedValue[t] match { case _: Int => true } @@ -14,7 +14,7 @@ object `implicit-match-and-inline-match` { } object b { - inline def isTheBoxInScopeAnInt = implicit match { + inline def isTheBoxInScopeAnInt = implied match { case _: Box[t] => inline 0 match { case _: t => true } diff --git a/tests/pos/implicit-match-nested.scala b/tests/pos/implicit-match-nested.scala index f49ba65fe834..0365c54d3704 100644 --- a/tests/pos/implicit-match-nested.scala +++ b/tests/pos/implicit-match-nested.scala @@ -6,8 +6,8 @@ object `implicit-match-nested` { implicit val b1: B[Int] = B[Int]() implicit val b2: B[String] = B[String]() - inline def locateB <: B[_] = implicit match { - case _: A[t] => implicit match { + inline def locateB <: B[_] = implied match { + case _: A[t] => implied match { case b: B[`t`] => b } } diff --git a/tests/pos/inline-separate/A_1.scala b/tests/pos/inline-separate/A_1.scala index 97844e430516..67a163f5cb0a 100644 --- a/tests/pos/inline-separate/A_1.scala +++ b/tests/pos/inline-separate/A_1.scala @@ -1,5 +1,5 @@ object A { - inline def summon[T] = implicit match { + inline def summon[T] = implied match { case t: T => t } } diff --git a/tests/run/companion-loading.scala b/tests/run/companion-loading.scala index f9744c90a6d4..3a8dca013a30 100644 --- a/tests/run/companion-loading.scala +++ b/tests/run/companion-loading.scala @@ -19,9 +19,9 @@ implicit object FooAssoc extends Assoc[Foo] { def foo(t: Foo): Int = t.i } -inline def link[T] = implicit match { +inline def link[T] = implied match { case _: Link[T, s] => - implicit match { + implied match { case stuff: s => stuff } } diff --git a/tests/run/impliedMatch.scala b/tests/run/impliedMatch.scala new file mode 100644 index 000000000000..671caad2f671 --- /dev/null +++ b/tests/run/impliedMatch.scala @@ -0,0 +1,33 @@ +object Test extends App { + import collection.immutable.TreeSet + import collection.immutable.HashSet + + inline def f1[T]() = implied match { + case ord: Ordering[T] => new TreeSet[T] + case _ => new HashSet[T] + } + + inline def f2[T]() = implied match { + case _: Ordering[T] => new TreeSet[T] + case _ => new HashSet[T] + } + + class A + class B + implicit val b: B = new B + + inline def g = implied match { + case _: A => println("A") + case _: B => println("B") + } + + implicitly[Ordering[String]] + + println(f1[String]().getClass) + println(f1[AnyRef]().getClass) + println(f2[String]().getClass) + println(f2[AnyRef]().getClass) + implicitly[B] + g + +} \ No newline at end of file diff --git a/tests/run/typeclass-derivation1.scala b/tests/run/typeclass-derivation1.scala index 06c6a4fad698..3aebb39a43c1 100644 --- a/tests/run/typeclass-derivation1.scala +++ b/tests/run/typeclass-derivation1.scala @@ -38,7 +38,7 @@ object Deriving { } object Eq { - inline def tryEq[T](x: T, y: T) = implicit match { + inline def tryEq[T](x: T, y: T) = implied match { case eq: Eq[T] => eq.equals(x, y) } diff --git a/tests/run/typeclass-derivation2.scala b/tests/run/typeclass-derivation2.scala index f8812b461d48..c593d21600a9 100644 --- a/tests/run/typeclass-derivation2.scala +++ b/tests/run/typeclass-derivation2.scala @@ -227,7 +227,7 @@ object Eq { import scala.compiletime.{erasedValue, error} import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implicit match { + inline def tryEql[T](x: T, y: T) = implied match { case eq: Eq[T] => eq.eql(x, y) } @@ -288,7 +288,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implicit match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -321,7 +321,7 @@ object Pickler { case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implicit match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -382,7 +382,7 @@ object Show { import scala.compiletime.{erasedValue, error} import TypeLevel._ - inline def tryShow[T](x: T): String = implicit match { + inline def tryShow[T](x: T): String = implied match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2a.scala b/tests/run/typeclass-derivation2a.scala index b7221bc2038a..d53092aab1bb 100644 --- a/tests/run/typeclass-derivation2a.scala +++ b/tests/run/typeclass-derivation2a.scala @@ -222,7 +222,7 @@ object Eq { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implicit match { + inline def tryEql[T](x: T, y: T) = implied match { case eq: Eq[T] => eq.eql(x, y) } @@ -275,7 +275,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implicit match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -295,7 +295,7 @@ object Pickler { case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implicit match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -360,7 +360,7 @@ object Show { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryShow[T](x: T): String = implicit match { + inline def tryShow[T](x: T): String = implied match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2b.scala b/tests/run/typeclass-derivation2b.scala index c6ab04686574..70fa42d93a27 100644 --- a/tests/run/typeclass-derivation2b.scala +++ b/tests/run/typeclass-derivation2b.scala @@ -94,7 +94,7 @@ object Eq { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implicit match { + inline def tryEql[T](x: T, y: T) = implied match { case eq: Eq[T] => eq.eql(x, y) } @@ -233,7 +233,7 @@ object Eq { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryEql[T](x: T, y: T) = implicit match { + inline def tryEql[T](x: T, y: T) = implied match { case eq: Eq[T] => eq.eql(x, y) } @@ -286,7 +286,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implicit match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -306,7 +306,7 @@ object Pickler { case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implicit match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -371,7 +371,7 @@ object Show { import scala.compiletime.erasedValue import TypeLevel._ - inline def tryShow[T](x: T): String = implicit match { + inline def tryShow[T](x: T): String = implied match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2c.scala b/tests/run/typeclass-derivation2c.scala index aa0b5a5f8ece..c5f3172a9ee6 100644 --- a/tests/run/typeclass-derivation2c.scala +++ b/tests/run/typeclass-derivation2c.scala @@ -54,7 +54,7 @@ object Deriving { type CaseLabel <: String /** The represented value */ - inline def singletonValue = implicit match { + inline def singletonValue = implied match { case ev: ValueOf[T] => ev.value } } @@ -212,7 +212,7 @@ trait Eq[T] { object Eq { import scala.compiletime.erasedValue - inline def tryEql[T](x: T, y: T) = implicit match { + inline def tryEql[T](x: T, y: T) = implied match { case eq: Eq[T] => eq.eql(x, y) } @@ -267,7 +267,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implicit match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -292,7 +292,7 @@ object Pickler { } else pickleCases[T](g, n + 1)(buf, x, ord) - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implicit match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -357,7 +357,7 @@ trait Show[T] { object Show { import scala.compiletime.{erasedValue, constValue} - inline def tryShow[T](x: T): String = implicit match { + inline def tryShow[T](x: T): String = implied match { case s: Show[T] => s.show(x) } diff --git a/tests/run/typeclass-derivation2d.scala b/tests/run/typeclass-derivation2d.scala index 4fb7132e0857..f22fb8d6c315 100644 --- a/tests/run/typeclass-derivation2d.scala +++ b/tests/run/typeclass-derivation2d.scala @@ -199,7 +199,7 @@ trait Eq[T] { object Eq { import scala.compiletime.erasedValue - inline def tryEql[T](x: T, y: T) = implicit match { + inline def tryEql[T](x: T, y: T) = implied match { case eq: Eq[T] => eq.eql(x, y) } @@ -219,7 +219,7 @@ object Eq { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => eqlElems[m.ElemTypes](0)(x, y) } else eqlCases[alts1](n + 1)(x, y, ord) @@ -255,7 +255,7 @@ object Pickler { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implicit match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -271,14 +271,14 @@ object Pickler { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => pickleElems[m.ElemTypes](0)(buf, x) } else pickleCases[alts1](n + 1)(buf, x, ord) case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implicit match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -305,7 +305,7 @@ object Pickler { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt` & T] => unpickleCase[`alt` & T, m.ElemTypes](buf, m) } @@ -348,7 +348,7 @@ trait Show[T] { object Show { import scala.compiletime.{erasedValue, constValue} - inline def tryShow[T](x: T): String = implicit match { + inline def tryShow[T](x: T): String = implied match { case s: Show[T] => s.show(x) } @@ -377,7 +377,7 @@ object Show { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => showCase(x, m) } diff --git a/tests/run/typeclass-derivation3.scala b/tests/run/typeclass-derivation3.scala index f9f0b2e6da22..1e53d4470649 100644 --- a/tests/run/typeclass-derivation3.scala +++ b/tests/run/typeclass-derivation3.scala @@ -32,7 +32,7 @@ object typeclasses { import compiletime._ import scala.deriving._ - inline def tryEql[TT](x: TT, y: TT): Boolean = implicit match { + inline def tryEql[TT](x: TT, y: TT): Boolean = implied match { case eq: Eq[TT] => eq.eql(x, y) } @@ -52,7 +52,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => eqlElems[m.MirroredElemTypes](0)(x, y) } else eqlCases[alts1](n + 1)(x, y, ord) @@ -89,7 +89,7 @@ object typeclasses { def nextInt(buf: mutable.ListBuffer[Int]): Int = try buf.head finally buf.trimStart(1) - inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implicit match { + inline def tryPickle[T](buf: mutable.ListBuffer[Int], x: T): Unit = implied match { case pkl: Pickler[T] => pkl.pickle(buf, x) } @@ -105,14 +105,14 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => pickleElems[m.MirroredElemTypes](0)(buf, x) } else pickleCases[alts1](n + 1)(buf, x, ord) case _: Unit => } - inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implicit match { + inline def tryUnpickle[T](buf: mutable.ListBuffer[Int]): T = implied match { case pkl: Pickler[T] => pkl.unpickle(buf) } @@ -139,7 +139,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt` & T] => unpickleCase[`alt` & T, m.MirroredElemTypes](buf, m) } @@ -183,7 +183,7 @@ object typeclasses { import compiletime._ import deriving._ - inline def tryShow[T](x: T): String = implicit match { + inline def tryShow[T](x: T): String = implied match { case s: Show[T] => s.show(x) } @@ -212,7 +212,7 @@ object typeclasses { inline erasedValue[Alts] match { case _: (alt *: alts1) => if (ord == n) - implicit match { + implied match { case m: Mirror.ProductOf[`alt`] => showCase(x, m) }