diff options
author | Martin Odersky <odersky@gmail.com> | 2016-12-15 15:21:26 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-12-15 15:21:26 +0100 |
commit | b1553cb9c5894e2e91925a67afd2c986675e5c46 (patch) | |
tree | f9def6ae664f0df939a51b55c5283790b93a7c4d /compiler/src/dotty/tools/dotc/core/Definitions.scala | |
parent | 9bf58090c704a59d8735874c565200758bcea666 (diff) | |
download | dotty-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.scala | 10 |
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) |