Skip to content

Commit 12862de

Browse files
committed
Drop implicit matches
1 parent 1ecfdae commit 12862de

File tree

6 files changed

+6
-80
lines changed

6 files changed

+6
-80
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,6 @@ class Definitions {
342342
def NullType = NullClass.typeRef
343343
lazy val RuntimeNullModuleRef = ctx.requiredModuleRef("scala.runtime.Null")
344344

345-
lazy val ImplicitScrutineeTypeSym =
346-
newSymbol(ScalaPackageClass, tpnme.IMPLICITkw, EmptyFlags, TypeBounds.empty).entered
347-
def ImplicitScrutineeTypeRef: TypeRef = ImplicitScrutineeTypeSym.typeRef
348-
349345
lazy val ScalaPredefModuleRef = ctx.requiredModuleRef("scala.Predef")
350346
def ScalaPredefModule(implicit ctx: Context) = ScalaPredefModuleRef.symbol
351347

@@ -1263,7 +1259,7 @@ class Definitions {
12631259

12641260
/** Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
12651261
lazy val syntheticCoreMethods =
1266-
AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod, ImplicitScrutineeTypeSym)
1262+
AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod)
12671263

12681264
lazy val reservedScalaClassNames: Set[Name] = syntheticScalaClasses.map(_.name).toSet
12691265

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,7 @@ object Parsers {
11331133
val start = in.offset
11341134
if (in.token == IMPLICIT || in.token == ERASED) {
11351135
val imods = modifiers(funArgMods)
1136-
if (in.token == MATCH) implicitMatch(start, imods)
1137-
else implicitClosure(start, location, imods)
1136+
implicitClosure(start, location, imods)
11381137
} else {
11391138
val saved = placeholderParams
11401139
placeholderParams = Nil
@@ -1280,30 +1279,6 @@ object Parsers {
12801279
inBraces(Match(t, caseClauses(caseClause)))
12811280
}
12821281

1283-
/** `match' { ImplicitCaseClauses }
1284-
*/
1285-
def implicitMatch(start: Int, imods: Modifiers) = {
1286-
def markFirstIllegal(mods: List[Mod]) = mods match {
1287-
case mod :: _ => syntaxError(em"illegal modifier for implicit match", mod.pos)
1288-
case _ =>
1289-
}
1290-
imods.mods match {
1291-
case Mod.Implicit() :: mods => markFirstIllegal(mods)
1292-
case mods => markFirstIllegal(mods)
1293-
}
1294-
val result @ Match(t, cases) =
1295-
matchExpr(ImplicitScrutinee().withPos(implicitKwPos(start)), start)
1296-
for (CaseDef(pat, _, _) <- cases) {
1297-
def isImplicitPattern(pat: Tree) = pat match {
1298-
case Typed(pat1, _) => isVarPattern(pat1)
1299-
case pat => isVarPattern(pat)
1300-
}
1301-
if (!isImplicitPattern(pat))
1302-
syntaxError(em"not a legal pattern for an implicit match", pat.pos)
1303-
}
1304-
result
1305-
}
1306-
13071282
/** `match' { TypeCaseClauses }
13081283
*/
13091284
def matchType(bound: Tree, t: Tree) =
@@ -2636,8 +2611,6 @@ object Parsers {
26362611
var imods = modifiers(funArgMods)
26372612
if (isBindingIntro && !isIdent(nme.INLINEkw))
26382613
stats += implicitClosure(start, Location.InBlock, imods)
2639-
else if (in.token == MATCH)
2640-
stats += implicitMatch(start, imods)
26412614
else
26422615
stats +++= localDef(start, imods)
26432616
} else {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,7 @@ class Typer extends Namer
569569
def typedTpt = checkSimpleKinded(typedType(tree.tpt))
570570
def handlePattern: Tree = {
571571
val tpt1 = typedTpt
572-
if (!ctx.isAfterTyper && pt != defn.ImplicitScrutineeTypeRef)
573-
constrainPatternType(tpt1.tpe, pt)(ctx.addMode(Mode.GADTflexible))
572+
if (!ctx.isAfterTyper) constrainPatternType(tpt1.tpe, pt)(ctx.addMode(Mode.GADTflexible))
574573
// special case for an abstract type that comes with a class tag
575574
tryWithClassTag(ascription(tpt1, isWildcard = true), pt)
576575
}
@@ -975,10 +974,6 @@ class Typer extends Namer
975974
val (protoFormals, _) = decomposeProtoFunction(pt, 1)
976975
val unchecked = pt.isRef(defn.PartialFunctionClass)
977976
typed(desugar.makeCaseLambda(tree.cases, protoFormals.length, unchecked) withPos tree.pos, pt)
978-
case id @ untpd.ImplicitScrutinee() =>
979-
checkInInlineContext("implicit match", tree.pos)
980-
val sel1 = id.withType(defn.ImplicitScrutineeTypeRef)
981-
typedMatchFinish(tree, sel1, sel1.tpe, pt)
982977
case _ =>
983978
val sel1 = typedExpr(tree.selector)
984979
val selType = fullyDefinedType(sel1.tpe, "pattern selector", tree.pos).widen
@@ -1380,7 +1375,6 @@ class Typer extends Namer
13801375
if (body1.tpe.isInstanceOf[TermRef]) pt1
13811376
else body1.tpe.underlyingIfRepeated(isJava = false)
13821377
val sym = ctx.newPatternBoundSymbol(tree.name, symTp, tree.pos)
1383-
if (pt == defn.ImplicitScrutineeTypeRef) sym.setFlag(Implicit)
13841378
if (ctx.mode.is(Mode.InPatternAlternative))
13851379
ctx.error(i"Illegal variable ${sym.name} in pattern alternative", tree.pos)
13861380
assignType(cpy.Bind(tree)(tree.name, body1), sym)

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ i4803d
2020
i4803e
2121
i4803f
2222
i4947b
23-
implicitMatch.scala
2423
implicitShortcut
2524
lazy-implicit-lists.scala
2625
lazy-implicit-nums.scala

docs/docs/internals/syntax.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ BlockResult ::= [FunArgMods] FunParams ‘=>’ Block
163163
FunParams ::= Bindings
164164
| id
165165
| ‘_’
166-
Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl}
166+
Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl}
167167
Expr [[semi] ‘else’ Expr] If(Parens(cond), thenp, elsep?)
168-
| [‘inline’] ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] If(cond, thenp, elsep?)
168+
| ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] If(cond, thenp, elsep?)
169169
| ‘while’ ‘(’ Expr ‘)’ {nl} Expr WhileDo(Parens(cond), body)
170170
| ‘while’ Expr ‘do’ Expr WhileDo(cond, body)
171171
| ‘do’ Expr [semi] ‘while’ Expr DoWhile(expr, cond)
@@ -177,8 +177,7 @@ Expr1 ::= [‘inline’] ‘if’ ‘(’ Expr ‘)’ {nl}
177177
| [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr)
178178
| SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr)
179179
| PostfixExpr [Ascription]
180-
| [‘inline’] PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases) -- point on match
181-
| ‘implicit’ ‘match’ ‘{’ ImplicitCaseClauses ‘}’
180+
| PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases) -- point on match
182181
Ascription ::= ‘:’ InfixType Typed(expr, tp)
183182
| ‘:’ Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*)
184183
Catches ::= ‘catch’ Expr
@@ -227,8 +226,6 @@ Guard ::= ‘if’ PostfixExpr
227226
228227
CaseClauses ::= CaseClause { CaseClause } Match(EmptyTree, cases)
229228
CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT) CaseDef(pat, guard?, block) // block starts at =>
230-
ImplicitCaseClauses ::= ImplicitCaseClause { ImplicitCaseClause }
231-
ImplicitCaseClause ::= ‘case’ PatVar [‘:’ RefinedType] [Guard] ‘=>’ Block
232229
TypeCaseClauses ::= TypeCaseClause { TypeCaseClause }
233230
TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
234231

tests/neg/implicitMatch-syntax.scala

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)