Skip to content

Commit 01a9bf2

Browse files
Remove NameBasedPattern, use scala.Product instead
1 parent d50ac10 commit 01a9bf2

File tree

5 files changed

+6
-19
lines changed

5 files changed

+6
-19
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ object desugar {
414414
if (arity > Definitions.MaxTupleArity) scalaDot(nme.Product.toTypeName)
415415
else productConstr(arity)
416416

417-
// Case classes and case objects get NameBasedPattern and Product/ProductN parents
417+
// Case classes and case objects get Product/ProductN parents
418418
val parents1: List[Tree] =
419419
if (mods.is(Case))
420-
parents :+ product :+ scalaDot(nme.NameBasedPattern.toTypeName)
420+
parents :+ product
421421
else parents
422422

423423
// The thicket which is the desugared version of the companion object

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ class Definitions {
513513
def DynamicClass(implicit ctx: Context) = DynamicType.symbol.asClass
514514
lazy val OptionType: TypeRef = ctx.requiredClassRef("scala.Option")
515515
def OptionClass(implicit ctx: Context) = OptionType.symbol.asClass
516-
lazy val NameBasedPatternType: TypeRef = ctx.requiredClassRef("scala.NameBasedPattern")
517516
lazy val ProductType: TypeRef = ctx.requiredClassRef("scala.Product")
518517
def ProductClass(implicit ctx: Context) = ProductType.symbol.asClass
519518
lazy val Product_canEqualR = ProductClass.requiredMethodRef(nme.canEqual_)
@@ -841,15 +840,8 @@ class Definitions {
841840
TupleType(elems.size).appliedTo(elems)
842841
}
843842

844-
/** Is this type eligible for name based pattern matching?
845-
*
846-
* That means either extending `scala.ProductN` OR `NameBasedPattern`.
847-
* In the long term, we can remove the first condition by having
848-
* `scala.ProductN` inherit `NameBasedPattern`.
849-
*/
850843
def isNameBasedPatternSubType(tp: Type)(implicit ctx: Context) =
851-
(tp.derivesFrom(ProductType.symbol) && tp.baseClasses.exists(isProductClass)) ||
852-
tp.derivesFrom(NameBasedPatternType.symbol)
844+
tp.derivesFrom(ProductType.symbol)
853845

854846
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN? */
855847
def isFunctionType(tp: Type)(implicit ctx: Context) = {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ object StdNames {
186186
final val Function: N = "Function"
187187
final val ImplicitFunction: N = "ImplicitFunction"
188188
final val Mirror: N = "Mirror"
189-
final val NameBasedPattern: N = "NameBasedPattern"
190189
final val Nothing: N = "Nothing"
191190
final val Null: N = "Null"
192191
final val Object: N = "Object"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ object Applications {
5151
* type for a pattern with `numArgs` subpatterns.
5252
*
5353
* This is the case if:
54-
* - `tp` is a subtype of the Product<numArgs> class or `NameBasedPattern` trait
54+
* - `tp` is a subtype of the Product trait
5555
* - `tp` has members `_1` to `_N` where `N == numArgs`
5656
*/
57-
def isNameBasedMatch(tp: Type, numArgs: Int)(implicit ctx: Context) =
58-
0 <= numArgs && defn.isNameBasedPatternSubType(tp) &&
57+
def isProductMatch(tp: Type, numArgs: Int)(implicit ctx: Context) =
58+
numArgs > 0 && defn.isProductSubType(tp) &&
5959
productSelectorTypes(tp).size == numArgs
6060

6161
/** Does `tp` fit the "get match" conditions as an unapply result type?

library/src/scala/NameBasedPattern.scala

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

0 commit comments

Comments
 (0)