Skip to content

Commit

Permalink
Eliminated some dead/redundant code based on review.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulp committed Dec 31, 2013
1 parent 1696145 commit e0a3702
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 51 deletions.
Expand Up @@ -112,9 +112,6 @@ trait MatchTranslation {
private def extractorStep(): TranslationStep = { private def extractorStep(): TranslationStep = {
def paramType = extractor.aligner.wholeType def paramType = extractor.aligner.wholeType
import extractor.treeMaker import extractor.treeMaker
// if (!extractor.isTyped)
// ErrorUtils.issueNormalTypeError(tree, "Could not typecheck extractor call: "+ extractor)(context)

// chain a type-testing extractor before the actual extractor call // chain a type-testing extractor before the actual extractor call
// it tests the type, checks the outer pointer and casts to the expected type // it tests the type, checks the outer pointer and casts to the expected type
// TODO: the outer check is mandated by the spec for case classes, but we do it for user-defined unapplies as well [SPEC] // TODO: the outer check is mandated by the spec for case classes, but we do it for user-defined unapplies as well [SPEC]
Expand Down
38 changes: 5 additions & 33 deletions src/reflect/scala/reflect/internal/Definitions.scala
Expand Up @@ -819,46 +819,18 @@ trait Definitions extends api.StandardDefinitions {
// FYI the long clunky name is because it's really hard to put "get" into the // FYI the long clunky name is because it's really hard to put "get" into the
// name of a method without it sounding like the method "get"s something, whereas // name of a method without it sounding like the method "get"s something, whereas
// this method is about a type member which just happens to be named get. // this method is about a type member which just happens to be named get.
def typeOfMemberNamedGet(tp: Type) = resultOfMatchingMethod(tp, nme.get)() def typeOfMemberNamedGet(tp: Type) = resultOfMatchingMethod(tp, nme.get)()
def typeOfMemberNamedHead(tp: Type) = resultOfMatchingMethod(tp, nme.head)() def typeOfMemberNamedHead(tp: Type) = resultOfMatchingMethod(tp, nme.head)()
def typeOfMemberNamedApply(tp: Type) = resultOfMatchingMethod(tp, nme.apply)(IntTpe) def typeOfMemberNamedApply(tp: Type) = resultOfMatchingMethod(tp, nme.apply)(IntTpe)
def typeOfMemberNamedDrop(tp: Type) = resultOfMatchingMethod(tp, nme.drop)(IntTpe) def typeOfMemberNamedDrop(tp: Type) = resultOfMatchingMethod(tp, nme.drop)(IntTpe)
def typeOfMemberNamedGetOrSelf(tp: Type) = typeOfMemberNamedGet(tp) orElse tp def typesOfSelectors(tp: Type) = getterMemberTypes(tp, productSelectors(tp))
def typesOfSelectors(tp: Type) = getterMemberTypes(tp, productSelectors(tp))
def typesOfCaseAccessors(tp: Type) = getterMemberTypes(tp, tp.typeSymbol.caseFieldAccessors)


// Can't only check for _1 thanks to pos/t796. // Can't only check for _1 thanks to pos/t796.
def hasSelectors(tp: Type) = ( def hasSelectors(tp: Type) = (
(tp.members containsName nme._1) (tp.members containsName nme._1)
&& (tp.members containsName nme._2) && (tp.members containsName nme._2)
) )


/** If this is a case class, the case field accessors (which may be an empty list.)
* Otherwise, if there are any product selectors, that list.
* Otherwise, a list containing only the type itself.
*/
def typesOfSelectorsOrSelf(tp: Type): List[Type] = (
if (tp.typeSymbol.isCase)
typesOfCaseAccessors(tp)
else typesOfSelectors(tp) match {
case Nil => tp :: Nil
case tps => tps
}
)

/** If the given type has one or more product selectors, the type of the last one.
* Otherwise, the type itself.
*/
def typeOfLastSelectorOrSelf(tp: Type) = typesOfSelectorsOrSelf(tp).last

def elementTypeOfLastSelectorOrSelf(tp: Type) = {
val last = typeOfLastSelectorOrSelf(tp)
( typeOfMemberNamedHead(last)
orElse typeOfMemberNamedApply(last)
orElse elementType(ArrayClass, last)
)
}

/** Returns the method symbols for members _1, _2, ..., _N /** Returns the method symbols for members _1, _2, ..., _N
* which exist in the given type. * which exist in the given type.
*/ */
Expand Down
17 changes: 2 additions & 15 deletions src/reflect/scala/reflect/internal/TreeInfo.scala
Expand Up @@ -611,22 +611,9 @@ abstract class TreeInfo {
*/ */
def effectivePatternArity(args: List[Tree]): Int = flattenedPatternArgs(args).length def effectivePatternArity(args: List[Tree]): Int = flattenedPatternArgs(args).length


/** Not enough to check the symbol because we need this information
* early to type the trees. ParserTuple checks for the syntactic form
* as generated by the parser.
*/
def flattenedPatternArgs(args: List[Tree]): List[Tree] = args map unbind match { def flattenedPatternArgs(args: List[Tree]): List[Tree] = args map unbind match {
case Apply(fun, xs) :: Nil if isTupleSymbol(fun.symbol) => xs case build.SyntacticTuple(xs) :: Nil => xs
case ParserTuple(xs) :: Nil => xs case xs => xs
case xs => xs
}

object ParserTuple {
private val TupleName = """^Tuple(\d+)$""".r
def unapply(t: Tree): Option[List[Tree]] = t match {
case Apply(Select(Ident(nme.scala_), TermName(TupleName(n))), args) if n.toInt == args.length => Some((args))
case _ => None
}
} }


// used in the symbols for labeldefs and valdefs emitted by the pattern matcher // used in the symbols for labeldefs and valdefs emitted by the pattern matcher
Expand Down

0 comments on commit e0a3702

Please sign in to comment.