Skip to content

Commit b591563

Browse files
Remove NameBasedPattern, use scala.Product instead
1 parent 6c56acd commit b591563

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
@@ -508,7 +508,6 @@ class Definitions {
508508
def DynamicClass(implicit ctx: Context) = DynamicType.symbol.asClass
509509
lazy val OptionType: TypeRef = ctx.requiredClassRef("scala.Option")
510510
def OptionClass(implicit ctx: Context) = OptionType.symbol.asClass
511-
lazy val NameBasedPatternType: TypeRef = ctx.requiredClassRef("scala.NameBasedPattern")
512511
lazy val ProductType: TypeRef = ctx.requiredClassRef("scala.Product")
513512
def ProductClass(implicit ctx: Context) = ProductType.symbol.asClass
514513
lazy val Product_canEqualR = ProductClass.requiredMethodRef(nme.canEqual_)
@@ -794,15 +793,8 @@ class Definitions {
794793
TupleType(elems.size).appliedTo(elems)
795794
}
796795

797-
/** Is this type eligible for name based pattern matching?
798-
*
799-
* That means either extending `scala.ProductN` OR `NameBasedPattern`.
800-
* In the long term, we can remove the first condition by having
801-
* `scala.ProductN` inherit `NameBasedPattern`.
802-
*/
803796
def isNameBasedPatternSubType(tp: Type)(implicit ctx: Context) =
804-
(tp.derivesFrom(ProductType.symbol) && tp.baseClasses.exists(isProductClass)) ||
805-
tp.derivesFrom(NameBasedPatternType.symbol)
797+
tp.derivesFrom(ProductType.symbol)
806798

807799
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN? */
808800
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
@@ -184,7 +184,6 @@ object StdNames {
184184
final val Function: N = "Function"
185185
final val ImplicitFunction: N = "ImplicitFunction"
186186
final val Mirror: N = "Mirror"
187-
final val NameBasedPattern: N = "NameBasedPattern"
188187
final val Nothing: N = "Nothing"
189188
final val Null: N = "Null"
190189
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)