Skip to content

Rename implicit match to implied match #6614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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]
Expand All @@ -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

Expand Down Expand Up @@ -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) =
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions library/src/scala/tasty/reflect/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ package scala.tasty.reflect
* | +- Lambda
* | +- If
* | +- Match
* | +- ImplicitMatch
* | +- ImpliedMatch
* | +- Try
* | +- Return
* | +- Repeated
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions library/src/scala/tasty/reflect/Kernel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package scala.tasty.reflect
* | +- Lambda
* | +- If
* | +- Match
* | +- ImplicitMatch
* | +- ImpliedMatch
* | +- Try
* | +- Return
* | +- Repeated
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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) =>
Expand Down
16 changes: 8 additions & 8 deletions library/src/scala/tasty/reflect/TreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 { <cases: List[CaseDef]> }` */
def apply(cases: List[CaseDef])(implicit ctx: Context): ImplicitMatch =
/** Creates a pattern match `implied match { <cases: List[CaseDef]> }` */
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 { <cases: List[CaseDef]> }` */
/** Matches a pattern match `implied match { <cases: List[CaseDef]> }` */
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)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/invalid/neg/implicitMatch-ambiguous.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tests/invalid/run/typelevel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/implicit-match-ambiguous-bind.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/neg/implicitMatch-syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
2 changes: 1 addition & 1 deletion tests/neg/typeclass-derivation2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions tests/pending/pos/implicit-match.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading