diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-23 14:14:24 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-23 17:42:13 +0200 |
commit | ee5721e864de6fff2d54b9fb5452123bcca82483 (patch) | |
tree | 4d40dfff5f13984badf035d090bfcd6fea235ab0 /src/reflect/scala | |
parent | 7b62eeea86c62f5e068c366065f8f4c2e6624eb7 (diff) | |
download | scala-ee5721e864de6fff2d54b9fb5452123bcca82483.tar.gz scala-ee5721e864de6fff2d54b9fb5452123bcca82483.tar.bz2 scala-ee5721e864de6fff2d54b9fb5452123bcca82483.zip |
SI-6111 accept single-subpattern unapply pattern
An extractor pattern `X(p)` should type check for any `X.unapply`/`X.unapplySeq`
that returns an `Option[_]` -- previously we were confused about the case where
it was an `Option[(T1, ... , Tn)]`. In this case, the expected type for the
pattern `p` is simply `(T1, ... , Tn)`.
While I was at it, tried to clean up unapplyTypeList and friends (by replacing them by extractorFormalTypes).
From the spec:
8.1.8 ExtractorPatterns
An extractor pattern x(p1, ..., pn) where n ≥ 0 is of the same syntactic form as a constructor pattern.
However, instead of a case class, the stable identifier x denotes an object which has a member method named unapply or unapplySeq that matches the pattern.
An unapply method in an object x matches the pattern x(p1, ..., pn) if it takes exactly one argument and one of the following applies:
n = 0 and unapply’s result type is Boolean.
n = 1 and unapply’s result type is Option[T], for some type T.
the (only) argument pattern p1 is typed in turn with expected type T
n > 1 and unapply’s result type is Option[(T1, ..., Tn)], for some types T1, ..., Tn.
the argument patterns p1, ..., pn are typed in turn with expected types T1, ..., Tn
Diffstat (limited to 'src/reflect/scala')
-rw-r--r-- | src/reflect/scala/reflect/internal/Definitions.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index d9b63529eb..90aa0b732c 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -397,6 +397,16 @@ trait Definitions extends api.StandardDefinitions { case _ => false } + def repeatedToSeq(tp: Type): Type = (tp baseType RepeatedParamClass) match { + case TypeRef(_, RepeatedParamClass, arg :: Nil) => seqType(arg) + case _ => tp + } + + def seqToRepeated(tp: Type): Type = (tp baseType SeqClass) match { + case TypeRef(_, SeqClass, arg :: Nil) => scalaRepeatedType(arg) + case _ => tp + } + def isPrimitiveArray(tp: Type) = tp match { case TypeRef(_, ArrayClass, arg :: Nil) => isPrimitiveValueClass(arg.typeSymbol) case _ => false |