Skip to content

Commit a00ccd3

Browse files
authored
Merge pull request #10565 from dotty-staging/drop-pattern-as
Drop `as` in patterns
2 parents 31751b9 + 2c2bc02 commit a00ccd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+86
-90
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
630630
}
631631
}
632632
compareTypeLambda
633-
case tp2 as OrType(tp21, tp22) =>
633+
case tp2 @ OrType(tp21, tp22) =>
634634
compareAtoms(tp1, tp2) match
635635
case Some(b) => return b
636636
case _ =>
@@ -970,7 +970,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
970970
* corresponding arguments are subtypes relative to their variance (see `isSubArgs`).
971971
*/
972972
def isMatchingApply(tp1: Type): Boolean = tp1 match {
973-
case tp1 as AppliedType(tycon1, args1) =>
973+
case tp1 @ AppliedType(tycon1, args1) =>
974974
// We intentionally do not automatically dealias `tycon1` or `tycon2` here.
975975
// `TypeApplications#appliedTo` already takes care of dealiasing type
976976
// constructors when this can be done without affecting type

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ object TypeOps:
150150
tp.derivedAlias(simplify(tp.alias, theMap))
151151
case AndType(l, r) if !ctx.mode.is(Mode.Type) =>
152152
simplify(l, theMap) & simplify(r, theMap)
153-
case tp as OrType(l, r)
153+
case tp @ OrType(l, r)
154154
if !ctx.mode.is(Mode.Type)
155155
&& (tp.isSoft || l.isBottomType || r.isBottomType) =>
156156
// Normalize A | Null and Null | A to A even if the union is hard (i.e.

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,10 +2608,7 @@ object Parsers {
26082608
/** Pattern2 ::= [id `as'] InfixPattern
26092609
*/
26102610
val pattern2: () => Tree = () => infixPattern() match {
2611-
case p @ Ident(name) if in.token == AT || in.isIdent(nme.as) =>
2612-
if in.token == AT && sourceVersion.isAtLeast(`3.1`) then
2613-
deprecationWarning(s"`@` bindings have been deprecated; use `as` instead", in.offset)
2614-
2611+
case p @ Ident(name) if in.token == AT =>
26152612
val offset = in.skipToken()
26162613
infixPattern() match {
26172614
case pt @ Ident(tpnme.WILDCARD_STAR) => // compatibility for Scala2 `x @ _*` syntax
@@ -2638,8 +2635,7 @@ object Parsers {
26382635
/** InfixPattern ::= SimplePattern {id [nl] SimplePattern}
26392636
*/
26402637
def infixPattern(): Tree =
2641-
infixOps(simplePattern(), in.canStartExprTokens, simplePattern,
2642-
isOperator = in.name != nme.raw.BAR && in.name != nme.as)
2638+
infixOps(simplePattern(), in.canStartExprTokens, simplePattern, isOperator = in.name != nme.raw.BAR)
26432639

26442640
/** SimplePattern ::= PatVar
26452641
* | Literal

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
214214
// of AndType and OrType to account for associativity
215215
case AndType(tp1, tp2) =>
216216
toTextInfixType(tpnme.raw.AMP, tp1, tp2) { toText(tpnme.raw.AMP) }
217-
case tp as OrType(tp1, tp2) =>
217+
case tp @ OrType(tp1, tp2) =>
218218
toTextInfixType(tpnme.raw.BAR, tp1, tp2) {
219219
if tp.isSoft && printDebug then toText(tpnme.ZOR) else toText(tpnme.raw.BAR)
220220
}

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
480480
else args.map(arg => erase(arg, inArray = false))
481481
tp.derivedAppliedType(erase(tycon, inArray), args2)
482482

483-
case tp as OrType(tp1, tp2) =>
483+
case tp @ OrType(tp1, tp2) =>
484484
OrType(erase(tp1, inArray), erase(tp2, inArray), tp.isSoft)
485485

486486
case AndType(tp1, tp2) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ trait Applications extends Compatibility {
600600
args match {
601601
case arg :: Nil if isVarArg(arg) =>
602602
addTyped(arg, formal)
603-
case (arg as Typed(Literal(Constant(null)), _)) :: Nil if ctx.isAfterTyper =>
603+
case (arg @ Typed(Literal(Constant(null)), _)) :: Nil if ctx.isAfterTyper =>
604604
addTyped(arg, formal)
605605
case _ =>
606606
val elemFormal = formal.widenExpr.argTypesLo.head

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ TypeCaseClause ::= ‘case’ InfixType ‘=>’ Type [nl]
269269
270270
Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats)
271271
Pattern1 ::= Pattern2 [‘:’ RefinedType] Bind(name, Typed(Ident(wildcard), tpe))
272-
Pattern2 ::= [id ‘as’] InfixPattern Bind(name, pat)
272+
Pattern2 ::= [id ‘@’] InfixPattern Bind(name, pat)
273273
InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat)
274274
SimplePattern ::= PatVar Ident(wildcard)
275275
| Literal Bind(name, Ident(wildcard))

docs/docs/reference/contextual/givens.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ Since `mkAnnotations` is `transparent`, the type of an application is the type o
9292

9393
## Pattern-Bound Given Instances
9494

95-
Given instances can also appear as pattern bound-variables. Example:
95+
Given instances can also appear in patterns. Example:
9696

9797
```scala
9898
for given Context <- applicationContexts do
9999

100100
pair match
101-
case (ctx as given Context, y) => ...
101+
case (ctx @ given Context, y) => ...
102102
```
103103
In the first fragment above, anonymous given instances for class `Context` are established by enumerating over `applicationContexts`. In the second fragment, a given `Context`
104104
instance named `ctx` is established by matching against the first half of the `pair` selector.

library/src/scala/quoted/ExprMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ trait ExprMap:
4747
tree
4848
case Super(qual, mix) =>
4949
tree
50-
case tree as Apply(fun, args) =>
50+
case tree @ Apply(fun, args) =>
5151
val MethodType(_, tpes, _) = fun.tpe.widen
5252
Apply.copy(tree)(transformTerm(fun, TypeRepr.of[Any])(owner), transformTerms(args, tpes)(owner))
5353
case TypeApply(fun, args) =>

tests/init/crash/fors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object Test extends App {
2626
var n = 0
2727
for (_ <- xs) n += 1; println(n)
2828
for ((x, y) <- xs zip ys) print(x + " "); println()
29-
for (p as (x, y) <- xs zip ys) print(p._1 + " "); println()
29+
for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println()
3030

3131
// iterators
3232
for (x <- it) print(x + " "); println()
@@ -53,7 +53,7 @@ object Test extends App {
5353
var n = 0
5454
for (_ <- xs) n += 1; println(n)
5555
for ((x, y) <- xs zip ys) print(x + " "); println()
56-
for (p as (x, y) <- xs zip ys) print(p._1 + " "); println()
56+
for (p @ (x, y) <- xs zip ys) print(p._1 + " "); println()
5757

5858
// iterators
5959
for (x <- it) print(x + " "); println()

0 commit comments

Comments
 (0)