Skip to content

Commit 6c6f3ce

Browse files
committed
Rename implicit match to implied match
1 parent 3cf3dd3 commit 6c6f3ce

33 files changed

+168
-117
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: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ object Parsers {
198198
!in.isSoftModifierInModifierPosition
199199

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

204204
def isDefIntro(allowedMods: BitSet): Boolean =
205205
in.token == AT ||
@@ -1265,7 +1265,7 @@ object Parsers {
12651265
* | SimpleExpr1 ArgumentExprs `=' Expr
12661266
* | Expr2
12671267
* | [‘inline’] Expr2 `match' `{' CaseClauses `}'
1268-
* | `implicit' `match' `{' ImplicitCaseClauses `}'
1268+
* | `implied' `match' `{' ImplicitCaseClauses `}'
12691269
* Bindings ::= `(' [Binding {`,' Binding}] `)'
12701270
* Binding ::= (id | `_') [`:' Type]
12711271
* Expr2 ::= PostfixExpr [Ascription]
@@ -1279,10 +1279,19 @@ object Parsers {
12791279

12801280
def expr(location: Location.Value): Tree = {
12811281
val start = in.offset
1282-
if (closureMods.contains(in.token)) {
1282+
if(in.token == IMPLIED) {
1283+
val span = in.offset
1284+
in.nextToken()
1285+
if (in.token == MATCH)
1286+
impliedMatch(start, EmptyModifiers)
1287+
else {
1288+
syntaxError(em"illegal modifier for implied match", span)
1289+
EmptyTree
1290+
}
1291+
}
1292+
else if (closureMods.contains(in.token)) {
12831293
val imods = modifiers(closureMods)
1284-
if (in.token == MATCH) implicitMatch(start, imods)
1285-
else implicitClosure(start, location, imods)
1294+
implicitClosure(start, location, imods)
12861295
} else {
12871296
val saved = placeholderParams
12881297
placeholderParams = Nil
@@ -1457,13 +1466,13 @@ object Parsers {
14571466

14581467
/** `match' { ImplicitCaseClauses }
14591468
*/
1460-
def implicitMatch(start: Int, imods: Modifiers) = {
1469+
def impliedMatch(start: Int, imods: Modifiers) = {
14611470
def markFirstIllegal(mods: List[Mod]) = mods match {
1462-
case mod :: _ => syntaxError(em"illegal modifier for implicit match", mod.span)
1471+
case mod :: _ => syntaxError(em"illegal modifier for implied match", mod.span)
14631472
case _ =>
14641473
}
14651474
imods.mods match {
1466-
case Mod.Implicit() :: mods => markFirstIllegal(mods)
1475+
case Mod.Implied() :: mods => markFirstIllegal(mods)
14671476
case mods => markFirstIllegal(mods)
14681477
}
14691478
val result @ Match(t, cases) =
@@ -1474,7 +1483,7 @@ object Parsers {
14741483
case pat => isVarPattern(pat)
14751484
}
14761485
if (!isImplicitPattern(pat))
1477-
syntaxError(em"not a legal pattern for an implicit match", pat.span)
1486+
syntaxError(em"not a legal pattern for an implied match", pat.span)
14781487
}
14791488
result
14801489
}
@@ -1999,6 +2008,7 @@ object Parsers {
19992008
case ABSTRACT => Mod.Abstract()
20002009
case FINAL => Mod.Final()
20012010
case IMPLICIT => Mod.Implicit()
2011+
case IMPLIED => Mod.Implied()
20022012
case GIVEN => Mod.Given()
20032013
case ERASED => Mod.Erased()
20042014
case LAZY => Mod.Lazy()
@@ -2668,7 +2678,7 @@ object Parsers {
26682678
case ENUM =>
26692679
enumDef(start, posMods(start, mods | Enum))
26702680
case IMPLIED =>
2671-
instanceDef(start, mods, atSpan(in.skipToken()) { Mod.Instance() })
2681+
instanceDef(start, mods, atSpan(in.skipToken()) { Mod.Implied() })
26722682
case _ =>
26732683
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition())
26742684
EmptyTree
@@ -3084,11 +3094,11 @@ object Parsers {
30843094
else if (isDefIntro(localModifierTokens))
30853095
if (closureMods.contains(in.token)) {
30863096
val start = in.offset
3087-
var imods = modifiers(closureMods)
3097+
var imods = modifiers(closureMods + IMPLIED)
30883098
if (isBindingIntro)
30893099
stats += implicitClosure(start, Location.InBlock, imods)
30903100
else if (in.token == MATCH)
3091-
stats += implicitMatch(start, imods)
3101+
stats += impliedMatch(start, imods)
30923102
else
30933103
stats +++= localDef(start, imods)
30943104
} 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
@@ -1021,7 +1021,7 @@ class Typer extends Namer
10211021
tree.selector match {
10221022
case EmptyTree =>
10231023
if (tree.isInline) {
1024-
checkInInlineContext("implicit match", tree.posd)
1024+
checkInInlineContext("implied match", tree.posd)
10251025
val cases1 = tree.cases.mapconserve {
10261026
case cdef @ CaseDef(pat @ Typed(Ident(nme.WILDCARD), _), _, _) =>
10271027
// case _ : T --> case evidence$n : T
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package dotty
2+
3+
object DottyPredef {
4+
5+
@forceInline final def assert(assertion: => Boolean, message: => Any): Unit = {
6+
if (!assertion)
7+
assertFail(message)
8+
}
9+
10+
@forceInline final def assert(assertion: => Boolean): Unit = {
11+
if (!assertion)
12+
assertFail()
13+
}
14+
15+
def assertFail(): Unit = throw new java.lang.AssertionError("assertion failed")
16+
def assertFail(message: => Any): Unit = throw new java.lang.AssertionError("assertion failed: " + message)
17+
18+
@forceInline final def implicitly[T](implicit ev: T): T = ev
19+
20+
@forceInline def locally[T](body: => T): T = body
21+
22+
/**
23+
* Retrieve the single value of a type with a unique inhabitant.
24+
*
25+
* @example {{{
26+
* object Foo
27+
* val foo = valueOf[Foo.type]
28+
* // foo is Foo.type = Foo
29+
*
30+
* val bar = valueOf[23]
31+
* // bar is 23.type = 23
32+
* }}}
33+
* @group utilities
34+
*/
35+
inline def valueOf[T]: T = implied match {
36+
case ev: ValueOf[T] => ev.value
37+
}
38+
39+
inline def the[T] given (x: T): x.type = x
40+
41+
}

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
@@ -591,27 +591,27 @@ trait TreeOps extends Core {
591591
}
592592

593593
object IsImplicitMatch {
594-
/** Matches any ImplicitMatch and returns it */
595-
def unapply(tree: Tree)(implicit ctx: Context): Option[ImplicitMatch] = kernel.matchImplicitMatch(tree)
594+
/** Matches any ImpliedMatch and returns it */
595+
def unapply(tree: Tree)(implicit ctx: Context): Option[ImpliedMatch] = kernel.matchImplicitMatch(tree)
596596
}
597597

598598
/** Scala implicit `match` term */
599-
object ImplicitMatch {
599+
object ImpliedMatch {
600600

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

605-
def copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch =
605+
def copy(original: Tree)(cases: List[CaseDef])(implicit ctx: Context): ImpliedMatch =
606606
kernel.ImplicitMatch_copy(original)(cases)
607607

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

612612
}
613613

614-
implicit class ImplicitMatchAPI(self: ImplicitMatch) {
614+
implicit class ImplicitMatchAPI(self: ImpliedMatch) {
615615
def cases(implicit ctx: Context): List[CaseDef] = kernel.ImplicitMatch_cases(self)
616616
}
617617

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

0 commit comments

Comments
 (0)