aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core/Definitions.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-12-15 15:21:26 +0100
committerMartin Odersky <odersky@gmail.com>2016-12-15 15:21:26 +0100
commitb1553cb9c5894e2e91925a67afd2c986675e5c46 (patch)
treef9def6ae664f0df939a51b55c5283790b93a7c4d /compiler/src/dotty/tools/dotc/core/Definitions.scala
parent9bf58090c704a59d8735874c565200758bcea666 (diff)
downloaddotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.tar.gz
dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.tar.bz2
dotty-b1553cb9c5894e2e91925a67afd2c986675e5c46.zip
Implement new rules for name-based pattern matching
This implements the rules laid down in #1805.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/Definitions.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/core/Definitions.scala10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala
index 1a7c62b30..9759e39fc 100644
--- a/compiler/src/dotty/tools/dotc/core/Definitions.scala
+++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala
@@ -675,7 +675,7 @@ class Definitions {
private def isVarArityClass(cls: Symbol, prefix: Name) = {
val name = scalaClassName(cls)
- name.startsWith(prefix) &&
+ name.startsWith(prefix) &&
name.length > prefix.length &&
name.drop(prefix.length).forall(_.isDigit)
}
@@ -737,6 +737,14 @@ class Definitions {
def isProductSubType(tp: Type)(implicit ctx: Context) =
(tp derivesFrom ProductType.symbol) && tp.baseClasses.exists(isProductClass)
+ def productArity(tp: Type)(implicit ctx: Context) =
+ if (tp derivesFrom ProductType.symbol)
+ tp.baseClasses.find(isProductClass) match {
+ case Some(prod) => prod.typeParams.length
+ case None => -1
+ }
+ else -1
+
def isFunctionType(tp: Type)(implicit ctx: Context) =
isFunctionClass(tp.dealias.typeSymbol) && {
val arity = functionArity(tp)