diff options
author | Paul Phillips <paulp@improving.org> | 2013-02-01 17:41:04 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-02-01 17:41:04 -0800 |
commit | 3dd9b3683b10edcf4f58ba1d98d4914c04614d87 (patch) | |
tree | 6be6c0f233b67595c306b37fde1cf3e08252efc8 /src/compiler/scala/tools/nsc/typechecker | |
parent | ccaa65a4969572631746d40d35bcd1fcfcaa51a9 (diff) | |
parent | b403234a27518f35acc360bfa0333b00fdc85175 (diff) | |
download | scala-3dd9b3683b10edcf4f58ba1d98d4914c04614d87.tar.gz scala-3dd9b3683b10edcf4f58ba1d98d4914c04614d87.tar.bz2 scala-3dd9b3683b10edcf4f58ba1d98d4914c04614d87.zip |
Merge commit 'b403234a27' into wip/fresh-merge2
Conflicts:
src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
test/files/neg/t6963.check
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala | 64 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 21 |
2 files changed, 52 insertions, 33 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index dd60b292bf..fa141e95e1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -265,26 +265,32 @@ trait NamesDefaults { self: Analyzer => * * For by-name parameters, create a value * x$n: () => T = () => arg + * + * For Ident(<unapply-selector>) arguments, no ValDef is created (SI-3353). */ - def argValDefs(args: List[Tree], paramTypes: List[Type], blockTyper: Typer): List[ValDef] = { + def argValDefs(args: List[Tree], paramTypes: List[Type], blockTyper: Typer): List[Option[ValDef]] = { val context = blockTyper.context - val symPs = map2(args, paramTypes)((arg, tpe) => { - val byName = isByNameParamType(tpe) - val repeated = isScalaRepeatedParamType(tpe) - val argTpe = ( - if (repeated) arg match { - case Typed(expr, Ident(tpnme.WILDCARD_STAR)) => expr.tpe - case _ => seqType(arg.tpe) - } - else arg.tpe - ).widen // have to widen or types inferred from literal defaults will be singletons - val s = context.owner.newValue(unit.freshTermName("x$"), arg.pos, newFlags = ARTIFACT) setInfo ( - if (byName) functionType(Nil, argTpe) else argTpe - ) - (context.scope.enter(s), byName, repeated) + val symPs = map2(args, paramTypes)((arg, tpe) => arg match { + case Ident(nme.SELECTOR_DUMMY) => + None // don't create a local ValDef if the argument is <unapply-selector> + case _ => + val byName = isByNameParamType(tpe) + val repeated = isScalaRepeatedParamType(tpe) + val argTpe = ( + if (repeated) arg match { + case Typed(expr, Ident(tpnme.WILDCARD_STAR)) => expr.tpe + case _ => seqType(arg.tpe) + } + else arg.tpe + ).widen // have to widen or types inferred from literal defaults will be singletons + val s = context.owner.newValue(unit.freshTermName("x$"), arg.pos, newFlags = ARTIFACT) setInfo ( + if (byName) functionType(Nil, argTpe) else argTpe + ) + Some((context.scope.enter(s), byName, repeated)) }) map2(symPs, args) { - case ((sym, byName, repeated), arg) => + case (None, _) => None + case (Some((sym, byName, repeated)), arg) => val body = if (byName) { val res = blockTyper.typed(Function(List(), arg)) @@ -300,7 +306,7 @@ trait NamesDefaults { self: Analyzer => blockTyper.typed(Apply(factory, List(resetLocalAttrs(arg)))) } else arg } - atPos(body.pos)(ValDef(sym, body).setType(NoType)) + Some(atPos(body.pos)(ValDef(sym, body).setType(NoType))) } } @@ -326,27 +332,29 @@ trait NamesDefaults { self: Analyzer => // ValDef's in the block), change the arguments to these local values. case Apply(expr, typedArgs) => // typedArgs: definition-site order - val formals = formalTypes(expr.tpe.paramTypes, typedArgs.length, false, false) + val formals = formalTypes(expr.tpe.paramTypes, typedArgs.length, removeByName = false, removeRepeated = false) // valDefs: call-site order val valDefs = argValDefs(reorderArgsInv(typedArgs, argPos), reorderArgsInv(formals, argPos), blockTyper) // refArgs: definition-site order again - val refArgs = map2(reorderArgs(valDefs, argPos), formals)((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 - tpe.typeSymbol match { - case ByNameParamClass => Apply(ref, Nil) - case RepeatedParamClass => Typed(ref, Ident(tpnme.WILDCARD_STAR)) - case _ => ref + val refArgs = map3(reorderArgs(valDefs, argPos), formals, typedArgs)((vDefOpt, tpe, origArg) => vDefOpt match { + case None => origArg + case Some(vDef) => + val ref = gen.mkAttributedRef(vDef.symbol) + atPos(vDef.pos.focus) { + // for by-name parameters, the local value is a nullary function returning the argument + tpe.typeSymbol match { + case ByNameParamClass => Apply(ref, Nil) + case RepeatedParamClass => Typed(ref, Ident(tpnme.WILDCARD_STAR)) + case _ => ref + } } - } }) // cannot call blockTyper.typedBlock here, because the method expr might be partially applied only val res = blockTyper.doTypedApply(tree, expr, refArgs, mode, pt) res.setPos(res.pos.makeTransparent) - val block = Block(stats ::: valDefs, res).setType(res.tpe).setPos(tree.pos.makeTransparent) + val block = Block(stats ::: valDefs.flatten, res).setType(res.tpe).setPos(tree.pos.makeTransparent) context.namedApplyBlockInfo = Some((block, NamedApplyInfo(qual, targs, vargss :+ refArgs, blockTyper))) block diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 285e1cb7af..7c60ce275a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -11,6 +11,9 @@ import scala.collection.{ mutable, immutable } import transform.InfoTransform import scala.collection.mutable.ListBuffer import scala.language.postfixOps +import scala.tools.nsc.settings.ScalaVersion +import scala.tools.nsc.settings.AnyScalaVersion +import scala.tools.nsc.settings.NoScalaVersion /** <p> * Post-attribution checking and transformation. @@ -1233,10 +1236,18 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans * indicating it has changed semantics between versions. */ private def checkMigration(sym: Symbol, pos: Position) = { - if (sym.hasMigrationAnnotation) - unit.warning(pos, "%s has changed semantics in version %s:\n%s".format( - sym.fullLocationString, sym.migrationVersion.get, sym.migrationMessage.get) - ) + if (sym.hasMigrationAnnotation) { + val changed = try + settings.Xmigration.value < ScalaVersion(sym.migrationVersion.get) + catch { + case e : NumberFormatException => + unit.warning(pos, s"${sym.fullLocationString} has an unparsable version number: ${e.getMessage()}") + // if we can't parse the format on the migration annotation just conservatively assume it changed + true + } + if (changed) + unit.warning(pos, s"${sym.fullLocationString} has changed semantics in version ${sym.migrationVersion.get}:\n${sym.migrationMessage.get}") + } } private def checkCompileTimeOnly(sym: Symbol, pos: Position) = { @@ -1449,7 +1460,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans * arbitrarily choose one as more important than the other. */ checkDeprecated(sym, tree.pos) - if (settings.Xmigration28.value) + if(settings.Xmigration.value != NoScalaVersion) checkMigration(sym, tree.pos) checkCompileTimeOnly(sym, tree.pos) |