diff options
author | Paul Phillips <paulp@improving.org> | 2009-11-19 20:31:46 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-11-19 20:31:46 +0000 |
commit | 04a99160c27257565438b58e814c885283521358 (patch) | |
tree | 55696ed37c7172f2938fe4f212949cee28dc1728 /src/compiler/scala/tools/nsc/typechecker | |
parent | 1e1c87c234826279a58c97bc5124f2e76ab58dce (diff) | |
download | scala-04a99160c27257565438b58e814c885283521358.tar.gz scala-04a99160c27257565438b58e814c885283521358.tar.bz2 scala-04a99160c27257565438b58e814c885283521358.zip |
Deprecation patrol exercises the new capabiliti...
Deprecation patrol exercises the new capabilities in Tuple2.zipped among
other exciting no-ops.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker')
6 files changed, 31 insertions, 32 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala index 7d75994ef3..375dd5a4a5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -20,12 +20,13 @@ trait EtaExpansion { self: Analyzer => import global._ object etaExpansion { + private def isMatch(vparam: ValDef, arg: Tree) = arg match { + case Ident(name) => vparam.name == name + case _ => false + } + def unapply(tree: Tree): Option[(List[ValDef], Tree, List[Tree])] = tree match { - case Function(vparams, Apply(fn, args)) - if (List.forall2(vparams, args) { - case (vparam, Ident(name)) => vparam.name == name - case _ => false - }) => + case Function(vparams, Apply(fn, args)) if (vparams, args).zipped forall isMatch => Some((vparams, fn, args)) case _ => None diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 69407ef0f1..a4b164edfe 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -404,7 +404,7 @@ trait Infer { val l = args.length - 1 l == formals.length && sym == FunctionClass(l) && - List.forall2(args, formals) (isPlausiblySubType) && + ((args, formals).zipped forall isPlausiblySubType) && isPlausiblySubType(tp.resultApprox, args.last) } case _ => @@ -458,7 +458,7 @@ trait Infer { def isCoercible(tp: Type, pt: Type): Boolean = false def isCompatibleArgs(tps: List[Type], pts: List[Type]): Boolean = - List.map2(tps, pts)((tp, pt) => isCompatibleArg(tp, pt)) forall (x => x) + (tps, pts).zipped forall isCompatibleArg /* -- Type instantiation------------------------------------------------ */ @@ -562,7 +562,7 @@ trait Infer { } val tvars = tparams map freshVar if (isConservativelyCompatible(restpe.instantiateTypeParams(tparams, tvars), pt)) - List.map2(tparams, tvars) ((tparam, tvar) => + (tparams, tvars).zipped map ((tparam, tvar) => instantiateToBound(tvar, varianceInTypes(formals)(tparam))) else tvars map (tvar => WildcardType) @@ -582,7 +582,7 @@ trait Infer { @inline def notCovariantIn(tparam: Symbol, restpe: Type) = (varianceInType(restpe)(tparam) & COVARIANT) == 0 // tparam occurred non-covariantly (in invariant or contravariant position) - List.map2(tparams, targs) {(tparam, targ) => + (tparams, targs).zipped map { (tparam, targ) => if (targ.typeSymbol == NothingClass && (restpe == WildcardType || notCovariantIn(tparam, restpe))) { uninstantiated += tparam tparam.tpeHK //@M tparam.tpe was wrong: we only want the type constructor, @@ -659,7 +659,7 @@ trait Infer { if (!isFullyDefined(tvar)) tvar.constr.inst = NoType // Then define remaining type variables from argument types. - List.map2(argtpes, formals) {(argtpe, formal) => + (argtpes, formals).zipped map { (argtpe, formal) => //@M isCompatible has side-effect: isSubtype0 will register subtype checks in the tvar's bounds if (!isCompatibleArg(argtpe.deconst.instantiateTypeParams(tparams, tvars), formal.instantiateTypeParams(tparams, tvars))) { @@ -1032,8 +1032,8 @@ trait Infer { (tparams map (_.defString)).mkString("[", ",", "]")) if (settings.explaintypes.value) { val bounds = tparams map (tp => tp.info.instantiateTypeParams(tparams, targs).bounds) - List.map2(targs, bounds)((targ, bound) => explainTypes(bound.lo, targ)) - List.map2(targs, bounds)((targ, bound) => explainTypes(targ, bound.hi)) + (targs, bounds).zipped foreach ((targ, bound) => explainTypes(bound.lo, targ)) + (targs, bounds).zipped foreach ((targ, bound) => explainTypes(targ, bound.hi)) () } } diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index 773b2cf561..d36d68163f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -223,7 +223,7 @@ trait NamesDefaults { self: Analyzer => */ def argValDefs(args: List[Tree], paramTypes: List[Type], blockTyper: Typer): List[ValDef] = { val context = blockTyper.context - val symPs = List.map2(args, paramTypes)((arg, tpe) => { + val symPs = (args, paramTypes).zipped map ((arg, tpe) => { val byName = tpe.typeSymbol == ByNameParamClass val s = context.owner.newValue(arg.pos, unit.fresh.newName(arg.pos, "x$")) val valType = if (byName) functionType(List(), arg.tpe) @@ -231,7 +231,7 @@ trait NamesDefaults { self: Analyzer => s.setInfo(valType) (context.scope.enter(s), byName) }) - List.map2(symPs, args)((symP, arg) => { + (symPs, args).zipped map ((symP, arg) => { val (sym, byName) = symP // resetAttrs required for #2290. given a block { val x = 1; x }, when wrapping into a function // () => { val x = 1; x }, the owner of symbol x must change (to the apply method of the function). @@ -270,7 +270,7 @@ trait NamesDefaults { self: Analyzer => reorderArgsInv(formals, argPos), blockTyper) // refArgs: definition-site order again - val refArgs = List.map2(reorderArgs(valDefs, argPos), formals)((vDef, tpe) => { + val refArgs = (reorderArgs(valDefs, argPos), formals).zipped map ((vDef, tpe) => { val ref = gen.mkAttributedRef(vDef.symbol) atPos(vDef.pos.focus) { // for by-name parameters, the local value is a nullary function returning the argument diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 3b49d22f0e..916ed69b67 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -888,8 +888,8 @@ abstract class RefChecks extends InfoTransform { unit.error(pos, ex.getMessage()); if (settings.explaintypes.value) { val bounds = tparams map (tp => tp.info.instantiateTypeParams(tparams, argtps).bounds) - List.map2(argtps, bounds)((targ, bound) => explainTypes(bound.lo, targ)) - List.map2(argtps, bounds)((targ, bound) => explainTypes(targ, bound.hi)) + (argtps, bounds).zipped map ((targ, bound) => explainTypes(bound.lo, targ)) + (argtps, bounds).zipped map ((targ, bound) => explainTypes(targ, bound.hi)) () } } @@ -899,9 +899,7 @@ abstract class RefChecks extends InfoTransform { val clazz = pat.tpe.typeSymbol; clazz == seltpe.typeSymbol && clazz.isClass && (clazz hasFlag CASE) && - List.forall2( - args, - clazz.primaryConstructor.tpe.asSeenFrom(seltpe, clazz).paramTypes)(isIrrefutable) + ((args, clazz.primaryConstructor.tpe.asSeenFrom(seltpe, clazz).paramTypes).zipped forall isIrrefutable) case Typed(pat, tpt) => seltpe <:< tpt.tpe case Ident(nme.WILDCARD) => diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index b80a782e36..fe2b1fd7ca 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -54,11 +54,11 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT } */ private def transformArgs(args: List[Tree], formals: List[Type]) = - List.map2(args, formals){ (arg, formal) => + ((args, formals).zipped map { (arg, formal) => if (formal.typeSymbol == definitions.ByNameParamClass) withInvalidOwner { checkPackedConforms(transform(arg), formal.typeArgs.head) } else transform(arg) - } ::: + }) ::: (args drop formals.length map transform) private def checkPackedConforms(tree: Tree, pt: Type): Tree = { @@ -290,7 +290,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT val obj = protAcc.paramss.head.head // receiver protAcc.paramss.tail.zip(allParamTypes(sym.tpe)).foldLeft(Select(Ident(obj), sym): Tree) ( (fun, pvparams) => { - Apply(fun, (List.map2(pvparams._1, pvparams._2) { (v, origTpe) => makeArg(v, obj, origTpe) } )) + Apply(fun, (pvparams._1, pvparams._2).zipped map (makeArg(_, obj, _))) }) }) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1ddc3b9116..a6d4230969 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1141,7 +1141,7 @@ trait Typers { self: Analyzer => if (!supertparams.isEmpty) error(supertpt.pos, "missing type arguments") } - List.map2(cstats1, treeInfo.preSuperFields(templ.body)) { + (cstats1, treeInfo.preSuperFields(templ.body)).zipped map { (ldef, gdef) => gdef.tpt.tpe = ldef.symbol.tpe } case _ => @@ -1573,7 +1573,7 @@ trait Typers { self: Analyzer => if (!superClazz.hasFlag(JAVA)) { val superParamAccessors = superClazz.constrParamAccessors if (superParamAccessors.length == superArgs.length) { - List.map2(superParamAccessors, superArgs) { (superAcc, superArg) => + (superParamAccessors, superArgs).zipped map { (superAcc, superArg) => superArg match { case Ident(name) => if (vparamss.exists(_.exists(_.symbol == superArg.symbol))) { @@ -1924,7 +1924,7 @@ trait Typers { self: Analyzer => if (fun.vparams.length != argpts.length) errorTree(fun, "wrong number of parameters; expected = " + argpts.length) else { - val vparamSyms = List.map2(fun.vparams, argpts) { (vparam, argpt) => + val vparamSyms = (fun.vparams, argpts).zipped map { (vparam, argpt) => if (vparam.tpt.isEmpty) { vparam.tpt.tpe = if (isFullyDefined(argpt)) argpt @@ -2101,13 +2101,13 @@ trait Typers { self: Analyzer => val losym = tparam.info.bounds.lo.typeSymbol losym != NothingClass && losym != NullClass } - List.exists2(formals, args) { + (formals, args).zipped exists { case (formal, Function(vparams, _)) => (vparams exists (_.tpt.isEmpty)) && vparams.length <= MaxFunctionArity && (formal baseType FunctionClass(vparams.length) match { case TypeRef(_, _, formalargs) => - List.exists2(formalargs, vparams) ((formalarg, vparam) => + (formalargs, vparams).zipped.exists ((formalarg, vparam) => vparam.tpt.isEmpty && (tparams exists (formalarg contains))) && (tparams forall isLowerBounded) case _ => @@ -2336,7 +2336,7 @@ trait Typers { self: Analyzer => } else { assert((mode & PATTERNmode) == 0); // this case cannot arise for patterns val lenientTargs = protoTypeArgs(tparams, formals, mt.resultApprox, pt) - val strictTargs = List.map2(lenientTargs, tparams)((targ, tparam) => + val strictTargs = (lenientTargs, tparams).zipped map ((targ, tparam) => if (targ == WildcardType) tparam.tpe else targ) //@M TODO: should probably be .tpeHK def typedArgToPoly(arg: Tree, formal: Type): Tree = { val lenientPt = formal.instantiateTypeParams(tparams, lenientTargs) @@ -2348,7 +2348,7 @@ trait Typers { self: Analyzer => } arg1 } - val args1 = List.map2(args, formals)(typedArgToPoly) + val args1 = (args, formals).zipped map typedArgToPoly if (args1 exists (_.tpe.isError)) setError(tree) else { if (settings.debug.value) log("infer method inst "+fun+", tparams = "+tparams+", args = "+args1.map(_.tpe)+", pt = "+pt+", lobounds = "+tparams.map(_.tpe.bounds.lo)+", parambounds = "+tparams.map(_.info));//debug @@ -3609,7 +3609,7 @@ trait Typers { self: Analyzer => // @M! added the latter condition appliedType(tpt1.tpe, argtypes) else tpt1.tpe.instantiateTypeParams(tparams, argtypes) - List.map2(args, tparams) { (arg, tparam) => arg match { + (args, tparams).zipped map { (arg, tparam) => arg match { // note: can't use args1 in selector, because Bind's got replaced case Bind(_, _) => if (arg.symbol.isAbstractType) @@ -3693,7 +3693,7 @@ trait Typers { self: Analyzer => case UnApply(fun, args) => val fun1 = typed(fun) val tpes = formalTypes(unapplyTypeList(fun.symbol, fun1.tpe), args.length) - val args1 = List.map2(args, tpes)(typedPattern(_, _)) + val args1 = (args, tpes).zipped map (typedPattern(_, _)) treeCopy.UnApply(tree, fun1, args1) setType pt case ArrayValue(elemtpt, elems) => |