Skip to content

Commit edc16a1

Browse files
authored
Merge pull request #6614 from dotty-staging/rename-implicitmatch
Rename implicit match to implied match
2 parents 78cd1db + 8ccde0c commit edc16a1

31 files changed

+155
-112
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
167167

168168
case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline)
169169

170-
case class Instance()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implied)
170+
case class Implied()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Implied)
171171
}
172172

173173
/** Modifiers and annotations for definitions

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ object Parsers {
199199
!in.isSoftModifierInModifierPosition
200200

201201
def isExprIntro: Boolean =
202-
canStartExpressionTokens.contains(in.token) &&
203-
!in.isSoftModifierInModifierPosition
202+
if (in.token == IMPLIED) in.lookaheadIn(BitSet(MATCH))
203+
else (canStartExpressionTokens.contains(in.token) && !in.isSoftModifierInModifierPosition)
204204

205205
def isDefIntro(allowedMods: BitSet, excludedSoftModifiers: Set[TermName] = Set.empty): Boolean =
206206
in.token == AT ||
@@ -1266,7 +1266,7 @@ object Parsers {
12661266
* | SimpleExpr1 ArgumentExprs `=' Expr
12671267
* | Expr2
12681268
* | [‘inline’] Expr2 `match' `{' CaseClauses `}'
1269-
* | `implicit' `match' `{' ImplicitCaseClauses `}'
1269+
* | `implied' `match' `{' ImplicitCaseClauses `}'
12701270
* Bindings ::= `(' [Binding {`,' Binding}] `)'
12711271
* Binding ::= (id | `_') [`:' Type]
12721272
* Expr2 ::= PostfixExpr [Ascription]
@@ -1282,9 +1282,19 @@ object Parsers {
12821282
val start = in.offset
12831283
if (closureMods.contains(in.token)) {
12841284
val imods = modifiers(closureMods)
1285-
if (in.token == MATCH) implicitMatch(start, imods)
1285+
if (in.token == MATCH) impliedMatch(start, imods)
12861286
else implicitClosure(start, location, imods)
1287-
} else {
1287+
}
1288+
else if(in.token == IMPLIED) {
1289+
in.nextToken()
1290+
if (in.token == MATCH)
1291+
impliedMatch(start, EmptyModifiers)
1292+
else {
1293+
syntaxError("`match` expected")
1294+
EmptyTree
1295+
}
1296+
}
1297+
else {
12881298
val saved = placeholderParams
12891299
placeholderParams = Nil
12901300

@@ -1458,13 +1468,13 @@ object Parsers {
14581468

14591469
/** `match' { ImplicitCaseClauses }
14601470
*/
1461-
def implicitMatch(start: Int, imods: Modifiers) = {
1471+
def impliedMatch(start: Int, imods: Modifiers) = {
14621472
def markFirstIllegal(mods: List[Mod]) = mods match {
1463-
case mod :: _ => syntaxError(em"illegal modifier for implicit match", mod.span)
1473+
case mod :: _ => syntaxError(em"illegal modifier for implied match", mod.span)
14641474
case _ =>
14651475
}
14661476
imods.mods match {
1467-
case Mod.Implicit() :: mods => markFirstIllegal(mods)
1477+
case (Mod.Implicit() | Mod.Implied()) :: mods => markFirstIllegal(mods)
14681478
case mods => markFirstIllegal(mods)
14691479
}
14701480
val result @ Match(t, cases) =
@@ -1475,7 +1485,7 @@ object Parsers {
14751485
case pat => isVarPattern(pat)
14761486
}
14771487
if (!isImplicitPattern(pat))
1478-
syntaxError(em"not a legal pattern for an implicit match", pat.span)
1488+
syntaxError(em"not a legal pattern for an implied match", pat.span)
14791489
}
14801490
result
14811491
}
@@ -2687,7 +2697,7 @@ object Parsers {
26872697
case ENUM =>
26882698
enumDef(start, posMods(start, mods | Enum))
26892699
case IMPLIED =>
2690-
instanceDef(start, mods, atSpan(in.skipToken()) { Mod.Instance() })
2700+
instanceDef(start, mods, atSpan(in.skipToken()) { Mod.Implied() })
26912701
case _ =>
26922702
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition())
26932703
EmptyTree
@@ -3107,7 +3117,7 @@ object Parsers {
31073117
if (isBindingIntro)
31083118
stats += implicitClosure(start, Location.InBlock, imods)
31093119
else if (in.token == MATCH)
3110-
stats += implicitMatch(start, imods)
3120+
stats += impliedMatch(start, imods)
31113121
else
31123122
stats +++= localDef(start, imods)
31133123
} else {

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object Tokens extends TokensCommon {
216216
USCORE, NULL, THIS, SUPER, TRUE, FALSE, RETURN, QUOTEID, XMLSTART)
217217

218218
final val canStartExpressionTokens: TokenSet = atomicExprTokens | BitSet(
219-
LBRACE, LPAREN, QUOTE, IF, DO, WHILE, FOR, NEW, TRY, THROW)
219+
LBRACE, LPAREN, QUOTE, IF, DO, WHILE, FOR, NEW, TRY, THROW, IMPLIED)
220220

221221
final val canStartTypeTokens: TokenSet = literalTokens | identifierTokens | BitSet(
222222
THIS, SUPER, USCORE, LPAREN, AT)

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
550550
def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match =
551551
tpd.cpy.Match(original)(selector, cases)
552552

553-
type ImplicitMatch = tpd.Match
553+
type ImpliedMatch = tpd.Match
554554

555555
def matchImplicitMatch(x: Term)(implicit ctx: Context): Option[Match] = x match {
556556
case x: tpd.Match if x.selector.isEmpty => Some(x)
@@ -559,10 +559,10 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
559559

560560
def ImplicitMatch_cases(self: Match)(implicit ctx: Context): List[CaseDef] = self.cases
561561

562-
def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch =
562+
def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch =
563563
withDefaultPos(ctx => tpd.Match(tpd.EmptyTree, cases)(ctx))
564564

565-
def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch =
565+
def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch =
566566
tpd.cpy.Match(original)(tpd.EmptyTree, cases)
567567

568568
type Try = tpd.Try

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
720720
/** Reduce an inline match
721721
* @param mtch the match tree
722722
* @param scrutinee the scrutinee expression, assumed to be pure, or
723-
* EmptyTree for an implicit match
723+
* EmptyTree for an implied match
724724
* @param scrutType its fully defined type, or
725-
* ImplicitScrutineeTypeRef for an implicit match
725+
* ImplicitScrutineeTypeRef for an implied match
726726
* @param typer The current inline typer
727727
* @return optionally, if match can be reduced to a matching case: A pair of
728728
* 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) {
10361036
def patStr(cdef: untpd.CaseDef) = i"case ${cdef.pat}${guardStr(cdef.guard)}"
10371037
val msg =
10381038
if (tree.selector.isEmpty)
1039-
em"""cannot reduce implicit match with
1039+
em"""cannot reduce implied match with
10401040
| patterns : ${tree.cases.map(patStr).mkString("\n ")}"""
10411041
else
10421042
em"""cannot reduce inline match with

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ class Typer extends Namer
10291029
tree.selector match {
10301030
case EmptyTree =>
10311031
if (tree.isInline) {
1032-
checkInInlineContext("implicit match", tree.posd)
1032+
checkInInlineContext("implied match", tree.posd)
10331033
val cases1 = tree.cases.mapconserve {
10341034
case cdef @ CaseDef(pat @ Typed(Ident(nme.WILDCARD), _), _, _) =>
10351035
// case _ : T --> case evidence$n : T

library/src/scala/tasty/reflect/Core.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package scala.tasty.reflect
2929
* | +- Lambda
3030
* | +- If
3131
* | +- Match
32-
* | +- ImplicitMatch
32+
* | +- ImpliedMatch
3333
* | +- Try
3434
* | +- Return
3535
* | +- Repeated
@@ -209,8 +209,8 @@ trait Core {
209209
/** Tree representing a pattern match `x match { ... }` in the source code */
210210
type Match = kernel.Match
211211

212-
/** Tree representing a pattern match `implicit match { ... }` in the source code */
213-
type ImplicitMatch = kernel.ImplicitMatch
212+
/** Tree representing a pattern match `implied match { ... }` in the source code */
213+
type ImpliedMatch = kernel.ImpliedMatch
214214

215215
/** Tree representing a try catch `try x catch { ... } finally { ... }` in the source code */
216216
type Try = kernel.Try

library/src/scala/tasty/reflect/Kernel.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package scala.tasty.reflect
2828
* | +- Lambda
2929
* | +- If
3030
* | +- Match
31-
* | +- ImplicitMatch
31+
* | +- ImpliedMatch
3232
* | +- Try
3333
* | +- Return
3434
* | +- Repeated
@@ -476,15 +476,15 @@ trait Kernel {
476476
def Match_apply(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match
477477
def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef])(implicit ctx: Context): Match
478478

479-
/** Tree representing a pattern match `implicit match { ... }` in the source code */
480-
type ImplicitMatch <: Term
479+
/** Tree representing a pattern match `implied match { ... }` in the source code */
480+
type ImpliedMatch <: Term
481481

482-
def matchImplicitMatch(tree: Tree)(implicit ctx: Context): Option[ImplicitMatch]
482+
def matchImplicitMatch(tree: Tree)(implicit ctx: Context): Option[ImpliedMatch]
483483

484-
def ImplicitMatch_cases(self: ImplicitMatch)(implicit ctx: Context): List[CaseDef]
484+
def ImplicitMatch_cases(self: ImpliedMatch)(implicit ctx: Context): List[CaseDef]
485485

486-
def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch
487-
def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch
486+
def ImplicitMatch_apply(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch
487+
def ImplicitMatch_copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch
488488

489489
/** Tree representing a tyr catch `try x catch { ... } finally { ... }` in the source code */
490490
type Try <: Term

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ trait Printers
186186
this += "Lambda(" += meth += ", " += tpt += ")"
187187
case Match(selector, cases) =>
188188
this += "Match(" += selector += ", " ++= cases += ")"
189-
case ImplicitMatch(cases) =>
190-
this += "ImplicitMatch(" ++= cases += ")"
189+
case ImpliedMatch(cases) =>
190+
this += "ImpliedMatch(" ++= cases += ")"
191191
case Return(expr) =>
192192
this += "Return(" += expr += ")"
193193
case While(cond, body) =>
@@ -909,8 +909,8 @@ trait Printers
909909
this += highlightKeyword(" match", color)
910910
inBlock(printCases(cases, lineBreak()))
911911

912-
case ImplicitMatch(cases) =>
913-
this += highlightKeyword("implicit match", color)
912+
case ImpliedMatch(cases) =>
913+
this += highlightKeyword("implied match", color)
914914
inBlock(printCases(cases, lineBreak()))
915915

916916
case Try(body, cases, finallyOpt) =>

library/src/scala/tasty/reflect/TreeOps.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,27 +628,27 @@ trait TreeOps extends Core {
628628
}
629629

630630
object IsImplicitMatch {
631-
/** Matches any ImplicitMatch and returns it */
632-
def unapply(tree: Tree)(implicit ctx: Context): Option[ImplicitMatch] = kernel.matchImplicitMatch(tree)
631+
/** Matches any ImpliedMatch and returns it */
632+
def unapply(tree: Tree)(implicit ctx: Context): Option[ImpliedMatch] = kernel.matchImplicitMatch(tree)
633633
}
634634

635635
/** Scala implicit `match` term */
636-
object ImplicitMatch {
636+
object ImpliedMatch {
637637

638-
/** Creates a pattern match `implicit match { <cases: List[CaseDef]> }` */
639-
def apply(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch =
638+
/** Creates a pattern match `implied match { <cases: List[CaseDef]> }` */
639+
def apply(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch =
640640
kernel.ImplicitMatch_apply(cases)
641641

642-
def copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch =
642+
def copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch =
643643
kernel.ImplicitMatch_copy(original)(cases)
644644

645-
/** Matches a pattern match `implicit match { <cases: List[CaseDef]> }` */
645+
/** Matches a pattern match `implied match { <cases: List[CaseDef]> }` */
646646
def unapply(tree: Tree)(implicit ctx: Context): Option[List[CaseDef]] =
647647
kernel.matchImplicitMatch(tree).map(_.cases)
648648

649649
}
650650

651-
implicit class ImplicitMatchAPI(self: ImplicitMatch) {
651+
implicit class ImplicitMatchAPI(self: ImpliedMatch) {
652652
def cases(implicit ctx: Context): List[CaseDef] = kernel.ImplicitMatch_cases(self)
653653
}
654654

tests/invalid/neg/implicitMatch-ambiguous.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Test {
44
implicit val a1: A = new A
55
implicit val a2: A = new A
66

7-
inline def f: Any = implicit match {
7+
inline def f: Any = implied match {
88
case _: A => ??? // error: ambiguous implicits
99
}
1010

tests/invalid/run/typelevel.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ object Test extends App {
153153
case S[type N] => toInt[N] + 1
154154
}
155155
156-
inline def toInt1[T]: Nat = implicit match {
156+
inline def toInt1[T]: Nat = implied match {
157157
case C[type T, type U], T =:= U =>
158158
case T <:< S[type N] => toInt[N] + 1
159159
}

tests/neg/implicit-match-ambiguous-bind.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object `implicit-match-ambiguous-bind` {
22
case class Box[T](value: T)
33
implicit val ibox: Box[Int] = Box(0)
44
implicit val sbox: Box[String] = Box("")
5-
inline def unbox = implicit match {
5+
inline def unbox = implied match {
66
case b: Box[t] => b.value // error
77
}
88
val unboxed = unbox

tests/neg/implicitMatch-syntax.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ object Test {
22
import collection.immutable.TreeSet
33
import collection.immutable.HashSet
44

5-
inline def f1[T] = implicit implicit match { // error: repeated modifier // error: illegal modifier
6-
case ord: Ordered[T] => new TreeSet[T] // error: no implicit
5+
inline def f1[T] = implied implied match { // error: illegal modifier // error: ';' expected, but 'match' found // error: Declaration of method f1 not allowed here
6+
case ord: Ordered[T] => new TreeSet[T]
77
case _ => new HashSet[T]
88

99
}
1010

11-
inline def f2[T] = implicit erased match { // error: illegal modifier
12-
case ord: Ordered[T] => new TreeSet[T] // error: no implicit
11+
inline def f2[T] = implied erased match { // error: illegal modifier // error: illegal modifier // error: Declaration of method f1 not allowed here
12+
case ord: Ordered[T] => new TreeSet[T]
1313
case _ => new HashSet[T]
1414
}
1515

16-
inline def f3[T] = erased implicit match { // error: illegal modifier
17-
case ord: Ordered[T] => new TreeSet[T] // error: no implicit
16+
inline def f3[T] = erased implied match { // error: illegal modifier
17+
case ord: Ordered[T] => new TreeSet[T]
1818
case _ => new HashSet[T]
1919
}
2020

21-
inline def f4() = implicit match {
21+
inline def f4() = implied match {
2222
case Nil => ??? // error: not a legal pattern
2323
case x :: xs => ??? // error: not a legal pattern
2424
}
2525

26-
inline def f5[T] = locally { implicit match { // Ok
26+
inline def f5[T] = locally { implied match { // Ok
2727
case _ => new HashSet[T]
2828
}}
2929

30-
def f6[T] = implicit match { // error: implicit match cannot be used here
30+
def f6[T] = implied match { // error: implied match cannot be used here
3131
case _ => new HashSet[T]
3232
}
3333
}

tests/neg/typeclass-derivation2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ object Show {
213213
import scala.compiletime.{erasedValue, error}
214214
import TypeLevel._
215215

216-
inline def tryShow[T](x: T): String = implicit match {
216+
inline def tryShow[T](x: T): String = implied match {
217217
case s: Show[T] => s.show(x)
218218
}
219219

tests/pending/pos/implicit-match.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Implicit matches that bind parameters don't work yet.
1+
// implied matches that bind parameters don't work yet.
22
object `implicit-match` {
33
object invariant {
44
case class Box[T](value: T)
55
implicit val box: Box[Int] = Box(0)
6-
inline def unbox <: Any = implicit match {
6+
inline def unbox <: Any = implied match {
77
case b: Box[t] => b.value
88
}
99
val i: Int = unbox
@@ -14,7 +14,7 @@ object `implicit-match` {
1414
object covariant {
1515
case class Box[+T](value: T)
1616
implicit val box: Box[Int] = Box(0)
17-
inline def unbox <: Any = implicit match {
17+
inline def unbox <: Any = implied match {
1818
case b: Box[t] => b.value
1919
}
2020
val i: Int = unbox
@@ -25,7 +25,7 @@ object `implicit-match` {
2525
object contravariant {
2626
case class TrashCan[-T](trash: T => Unit)
2727
implicit val trashCan: TrashCan[Int] = TrashCan { i => ; }
28-
inline def trash <: Nothing => Unit = implicit match {
28+
inline def trash <: Nothing => Unit = implied match {
2929
case c: TrashCan[t] => c.trash
3030
}
3131
val t1: Int => Unit = trash

0 commit comments

Comments
 (0)