diff options
17 files changed, 149 insertions, 142 deletions
@@ -1671,7 +1671,7 @@ DOCUMENTATION <taskdef name="genman" classname="scala.tools.docutil.ManMaker" classpathref="manual.classpath"/> - <genman command="fsc, sbaz, scala, scalac, scaladoc, scalap" + <genman command="fsc, scala, scalac, scaladoc, scalap" htmlout="${build-docs.dir}/manual/html" manout="${build-docs.dir}/manual/genman"/> <!-- On Windows source and target files can't be the same ! --> diff --git a/docs/README b/docs/README index bcc7108399..6af633444d 100644 --- a/docs/README +++ b/docs/README @@ -2,8 +2,7 @@ Scala Software Distributions ---------------------------- -- scala-<major>.<minor>.<patch>.tar.bz2 Unix distribution -- scala-<major>.<minor>.<patch>.tar.gz Unix distribution +- scala-<major>.<minor>.<patch>.tgz Unix distribution - scala-<major>.<minor>.<patch>.zip Windows distribution The standard distributions require Java 1.5 or above. If you don't @@ -32,15 +31,10 @@ directly accessible. You may test the distribution by running the following commands: -$ ./bin/sbaz install scala-devel-docs -$ ./bin/scalac doc/scala-devel-docs/examples/sort.scala -$ ./bin/scala examples.sort -[6,2,8,5,1] -[1,2,5,6,8] $ ./bin/scala -scala> examples.sort.main(null) -[6,2,8,5,1] -[1,2,5,6,8] +scala> Array(4,3,2,1).sorted +res0: Array[Int] = Array(1, 2, 3, 4) + scala>:quit $ diff --git a/src/build/pack.xml b/src/build/pack.xml index c12cfa44bf..723fd1d25d 100644 --- a/src/build/pack.xml +++ b/src/build/pack.xml @@ -78,6 +78,7 @@ MAIN DISTRIBUTION PACKAGING <exclude name="logs/**"/> <exclude name="sandbox/**"/> <exclude name="test/partest"/> + <exclude name=".git"/> </tarfileset> <tarfileset dir="${basedir}" prefix="${dist.name}-sources" filemode="755"> <include name="test/partest"/> @@ -95,8 +96,22 @@ MAIN DISTRIBUTION PACKAGING </fileset> </checksum> </target> + + <target name="pack-archives.latest.unix" depends="pack-archives.src" unless="os.win"> + <symlink link="${dists.dir}/archives/scala-latest-sources.tgz" + resource="${dists.dir}/archives/scala-${version.number}-sources.tgz" + overwrite="yes"/> + </target> + + <target name="pack-archives.latest.win" depends="pack-archives.src" if="os.win"> + <copy tofile="${dists.dir}/archives/scala-latest-sources.tgz"> + <fileset dir="${dists.dir}/archives"> + <include name="scala-${version.number}-sources.tgz"/> + </fileset> + </copy> + </target> - <target name="pack-archives.done" depends="pack-archives.src"/> + <target name="pack-archives.done" depends="pack-archives.src, pack-archives.latest.win, pack-archives.latest.unix"/> <!-- =========================================================================== MAIN DISTRIBUTION SBAZ diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index a20853adc8..bb9549deba 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -97,7 +97,7 @@ trait Types extends api.Types { self: SymbolTable => */ private final val propagateParameterBoundsToTypeVars = sys.props contains "scalac.debug.prop-constraints" - protected val enableTypeVarExperimentals = settings.Xexperimental.value + protected val enableTypeVarExperimentals = settings.Xexperimental.value || settings.YvirtPatmat.value /** Empty immutable maps to avoid allocations. */ private val emptySymMap = immutable.Map[Symbol, Symbol]() @@ -448,7 +448,7 @@ trait Types extends api.Types { self: SymbolTable => def resultType(actuals: List[Type]) = this /** Only used for dependent method types. */ - def resultApprox: Type = ApproximateDependentMap(resultType) // if (!settings.YdepMethTpes.value) resultType else + def resultApprox: Type = ApproximateDependentMap(resultType) /** If this is a TypeRef `clazz`[`T`], return the argument `T` * otherwise return this type @@ -2268,7 +2268,7 @@ trait Types extends api.Types { self: SymbolTable => override def isTrivial: Boolean = isTrivial0 && (resultType eq resultType.withoutAnnotations) private lazy val isTrivial0 = resultType.isTrivial && params.forall{p => p.tpe.isTrivial && ( - /*!settings.YdepMethTpes.value ||*/ !(params.exists(_.tpe.contains(p)) || resultType.contains(p))) + !(params.exists(_.tpe.contains(p)) || resultType.contains(p))) } def isImplicit = params.nonEmpty && params.head.isImplicit @@ -2292,8 +2292,9 @@ trait Types extends api.Types { self: SymbolTable => } else existentialAbstraction(params, resultType) - // implicit args can only be depended on in result type: TODO this may be generalised so that the only constraint is dependencies are acyclic - def approximate: MethodType = MethodType(params, resultApprox) // if (!settings.YdepMethTpes.value) this else + // implicit args can only be depended on in result type: + //TODO this may be generalised so that the only constraint is dependencies are acyclic + def approximate: MethodType = MethodType(params, resultApprox) override def finalResultType: Type = resultType.finalResultType diff --git a/src/compiler/scala/reflect/internal/settings/MutableSettings.scala b/src/compiler/scala/reflect/internal/settings/MutableSettings.scala index 0092f73fe3..b556c33aba 100644 --- a/src/compiler/scala/reflect/internal/settings/MutableSettings.scala +++ b/src/compiler/scala/reflect/internal/settings/MutableSettings.scala @@ -43,4 +43,5 @@ abstract class MutableSettings extends AbsSettings { def Yrecursion: IntSetting def maxClassfileName: IntSetting def Xexperimental: BooleanSetting + def YvirtPatmat: BooleanSetting }
\ No newline at end of file diff --git a/src/compiler/scala/reflect/runtime/Settings.scala b/src/compiler/scala/reflect/runtime/Settings.scala index b4f0123114..27e90c94bd 100644 --- a/src/compiler/scala/reflect/runtime/Settings.scala +++ b/src/compiler/scala/reflect/runtime/Settings.scala @@ -23,7 +23,6 @@ class Settings extends internal.settings.MutableSettings { val overrideObjects = new BooleanSetting(false) val debug = new BooleanSetting(false) - // val YdepMethTpes = new BooleanSetting(true) val Ynotnull = new BooleanSetting(false) val explaintypes = new BooleanSetting(false) val verbose = new BooleanSetting(false) @@ -34,4 +33,6 @@ class Settings extends internal.settings.MutableSettings { val Yrecursion = new IntSetting(0) val maxClassfileName = new IntSetting(255) val Xexperimental = new BooleanSetting(false) + val deepCloning = new BooleanSetting (false) + val YvirtPatmat = new BooleanSetting(false) } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index ccebcfa54d..45325b4694 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1394,13 +1394,7 @@ self => } } } else if (in.token == MATCH) { - t = atPos(t.pos.startOrPoint, in.skipToken()) { - /** For debugging pattern matcher transition issues */ - if (settings.Ypmatnaive.value) - makeSequencedMatch(stripParens(t), inBracesOrNil(caseClauses())) - else - Match(stripParens(t), inBracesOrNil(caseClauses())) - } + t = atPos(t.pos.startOrPoint, in.skipToken())(Match(stripParens(t), inBracesOrNil(caseClauses()))) } // in order to allow anonymous functions as statements (as opposed to expressions) inside // templates, we have to disambiguate them from self type declarations - bug #1565 diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 0bc88d1efd..3a6e26d3b5 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -505,37 +505,6 @@ abstract class TreeBuilder { def makePatDef(pat: Tree, rhs: Tree): List[Tree] = makePatDef(Modifiers(0), pat, rhs) - /** For debugging only. Desugar a match statement like so: - * val x = scrutinee - * x match { - * case case1 => ... - * case _ => x match { - * case case2 => ... - * case _ => x match ... - * } - * } - * - * This way there are never transitions between nontrivial casedefs. - * Of course many things break: exhaustiveness and unreachable checking - * do not work, no switches will be generated, etc. - */ - def makeSequencedMatch(selector: Tree, cases: List[CaseDef]): Tree = { - require(cases.nonEmpty) - - val selectorName = freshTermName() - val valdef = atPos(selector.pos)(ValDef(Modifiers(PrivateLocal | SYNTHETIC), selectorName, TypeTree(), selector)) - val nselector = Ident(selectorName) - - def loop(cds: List[CaseDef]): Match = { - def mkNext = CaseDef(Ident(nme.WILDCARD), EmptyTree, loop(cds.tail)) - - if (cds.size == 1) Match(nselector, cds) - else Match(selector, List(cds.head, mkNext)) - } - - Block(List(valdef), loop(cases)) - } - /** Create tree for pattern definition <mods val pat0 = rhs> */ def makePatDef(mods: Modifiers, pat: Tree, rhs: Tree): List[Tree] = matchVarPattern(pat) match { case Some((name, tpt)) => diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index d1224fc79d..fdde8f9990 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -30,6 +30,22 @@ trait ScalaSettings extends AbsScalaSettings */ protected def defaultClasspath = sys.env.getOrElse("CLASSPATH", ".") + /** Enabled under -Xexperimental. */ + protected def experimentalSettings = List[BooleanSetting](YmethodInfer, overrideObjects) + + /** Enabled under -Xfuture. */ + protected def futureSettings = List[BooleanSetting]() + + /** Enabled under -optimise. */ + protected def optimiseSettings = List[BooleanSetting](inline, inlineHandlers, Xcloselim, Xdce) + + /** Internal use - syntax enhancements. */ + private class EnableSettings[T <: Setting](val s: T) { + def enabling(toEnable: List[BooleanSetting]): s.type = s withPostSetHook (_ => toEnable foreach (_.value = true)) + def andThen(f: s.T => Unit): s.type = s withPostSetHook (setting => f(setting.value)) + } + private implicit def installEnableSettings[T <: Setting](s: T) = new EnableSettings(s) + /** Disable a setting */ def disable(s: Setting) = allSettings -= s @@ -43,12 +59,8 @@ trait ScalaSettings extends AbsScalaSettings */ // argfiles is only for the help message val argfiles = BooleanSetting ("@<file>", "A text file containing compiler arguments (options and source files)") - val classpath = PathSetting ("-classpath", "Specify where to find user class files.", defaultClasspath) . - withAbbreviation ("-cp") + val classpath = PathSetting ("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp" val d = OutputSetting (outputDirs, ".") - val optimise = BooleanSetting ("-optimise", "Generates faster bytecode by applying optimisations to the program") . - withAbbreviation("-optimize") . - withPostSetHook(set => List(inline, inlineHandlers, Xcloselim, Xdce) foreach (_.value = set.value)) val nospecialization = BooleanSetting ("-no-specialization", "Ignore @specialize annotations.") /** @@ -64,7 +76,6 @@ trait ScalaSettings extends AbsScalaSettings val elidebelow = IntSetting ("-Xelide-below", "Calls to @elidable methods are omitted if method priority is lower than argument", elidable.MINIMUM, None, elidable.byName get _) val noForwarders = BooleanSetting ("-Xno-forwarders", "Do not generate static forwarders in mirror classes.") - val future = BooleanSetting ("-Xfuture", "Turn on future language features.") val genPhaseGraph = StringSetting ("-Xgenerate-phase-graph", "file", "Generate the phase graphs (outputs .dot files) to fileX.dot.", "") val XlogImplicits = BooleanSetting ("-Xlog-implicits", "Show more detail on why some implicits are not applicable.") val logImplicitConv = BooleanSetting ("-Xlog-implicit-conversions", "Print a message whenever an implicit conversion is inserted.") @@ -92,12 +103,6 @@ trait ScalaSettings extends AbsScalaSettings val showPhases = BooleanSetting ("-Xshow-phases", "Print a synopsis of compiler phases.") val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "") - // Experimental Extensions - val Xexperimental = BooleanSetting ("-Xexperimental", "Enable experimental extensions.") . - withPostSetHook(set => List(YmethodInfer, overrideObjects) foreach (_.value = set.value)) - // YdepMethTpes, YvirtClasses, - val Xmacros = BooleanSetting ("-Xmacros", "Enable macros.") - /** Compatibility stubs for options whose value name did * not previously match the option name. */ @@ -145,8 +150,7 @@ trait ScalaSettings extends AbsScalaSettings val Ygenjavap = StringSetting ("-Ygen-javap", "dir", "Generate a parallel output directory of .javap files.", "") val Ydumpclasses = StringSetting ("-Ydump-classes", "dir", "Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).", "") val Ynosqueeze = BooleanSetting ("-Yno-squeeze", "Disable creation of compact code in matching.") - val Ystatistics = BooleanSetting ("-Ystatistics", "Print compiler statistics.") . - withPostSetHook(set => util.Statistics.enabled = set.value) + val Ystatistics = BooleanSetting ("-Ystatistics", "Print compiler statistics.") andThen (util.Statistics.enabled = _) val stopAfter = PhasesSetting ("-Ystop-after", "Stop after") withAbbreviation ("-stop") // backward compat val stopBefore = PhasesSetting ("-Ystop-before", "Stop before") val refinementMethodDispatch = @@ -157,26 +161,11 @@ trait ScalaSettings extends AbsScalaSettings val YrichExes = BooleanSetting ("-Yrich-exceptions", "Fancier exceptions. Set source search path with -D" + sys.SystemProperties.traceSourcePath.key) - val Yidedebug = BooleanSetting ("-Yide-debug", "Generate, validate and output trees using the interactive compiler.") - val Ybuilderdebug = ChoiceSetting ("-Ybuilder-debug", "manager", "Compile using the specified build manager.", List("none", "refined", "simple"), "none") - val Ybuildmanagerdebug = - BooleanSetting ("-Ybuild-manager-debug", "Generate debug information for the Refined Build Manager compiler.") - val Ytyperdebug = BooleanSetting ("-Ytyper-debug", "Trace all type assignments.") - val Yposdebug = BooleanSetting ("-Ypos-debug", "Trace position validation.") - val Yinferdebug = BooleanSetting ("-Yinfer-debug", "Trace type inference and implicit search.") - val Ypmatdebug = BooleanSetting ("-Ypmat-debug", "Trace all pattern matcher activity.") + val Ybuilderdebug = ChoiceSetting("-Ybuilder-debug", "manager", "Compile using the specified build manager.", List("none", "refined", "simple"), "none") val Yreifycopypaste = BooleanSetting ("-Yreify-copypaste", "Dump the reified trees in copypasteable representation.") - val Yreifydebug = BooleanSetting ("-Yreify-debug", "Trace reification.") - val Ymacrodebug = BooleanSetting ("-Ymacro-debug", "Trace macro-related activities: generation of synthetics, expansion, exceptions.") val Yreplsync = BooleanSetting ("-Yrepl-sync", "Do not use asynchronous code for repl startup") - val Yrepldebug = BooleanSetting ("-Yrepl-debug", "Trace all repl activity.") . - withPostSetHook(_ => interpreter.replProps.debug setValue true) - val Ycompletion = BooleanSetting ("-Ycompletion-debug", "Trace all tab completion activity.") - val Ydocdebug = BooleanSetting ("-Ydoc-debug", "Trace all scaladoc activity.") - val Ypmatnaive = BooleanSetting ("-Ypmat-naive", "Desugar matches as naively as possible.") val Ynotnull = BooleanSetting ("-Ynotnull", "Enable (experimental and incomplete) scala.NotNull.") - // val YdepMethTpes = BooleanSetting ("-Ydependent-method-types", "Allow dependent method types.") val YmethodInfer = BooleanSetting ("-Yinfer-argument-types", "Infer types for arguments of overriden methods.") val etaExpandKeepsStar = BooleanSetting("-Yeta-expand-keeps-star", "Eta-expand varargs methods to T* rather than Seq[T]. This is a temporary option to ease transition.") val noSelfCheck = BooleanSetting ("-Yno-self-type-checks", "Suppress check for self-type conformance among inherited members.") @@ -188,6 +177,29 @@ trait ScalaSettings extends AbsScalaSettings def stop = stopAfter + /** Area-specific debug output. + */ + val Ybuildmanagerdebug = BooleanSetting("-Ybuild-manager-debug", "Generate debug information for the Refined Build Manager compiler.") + val Ycompletion = BooleanSetting("-Ycompletion-debug", "Trace all tab completion activity.") + val Ydocdebug = BooleanSetting("-Ydoc-debug", "Trace all scaladoc activity.") + val Yidedebug = BooleanSetting("-Yide-debug", "Generate, validate and output trees using the interactive compiler.") + val Yinferdebug = BooleanSetting("-Yinfer-debug", "Trace type inference and implicit search.") + val Ymacrodebug = BooleanSetting("-Ymacro-debug", "Trace macro-related activities: generation of synthetics, expansion, exceptions.") + val Ypmatdebug = BooleanSetting("-Ypmat-debug", "Trace all pattern matcher activity.") + val Yposdebug = BooleanSetting("-Ypos-debug", "Trace position validation.") + val Yreifydebug = BooleanSetting("-Yreify-debug", "Trace reification.") + val Yrepldebug = BooleanSetting("-Yrepl-debug", "Trace all repl activity.") andThen (interpreter.replProps.debug setValue _) + val Ytyperdebug = BooleanSetting("-Ytyper-debug", "Trace all type assignments.") + + /** Groups of Settings. + */ + val future = BooleanSetting ("-Xfuture", "Turn on future language features.") enabling futureSettings + val optimise = BooleanSetting ("-optimise", "Generates faster bytecode by applying optimisations to the program") withAbbreviation "-optimize" enabling optimiseSettings + val Xexperimental = BooleanSetting ("-Xexperimental", "Enable experimental extensions.") enabling experimentalSettings + + // Feature extensions + val Xmacros = BooleanSetting ("-Xmacros", "Enable macros.") + /** * IDE-specific settings */ diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index e37f5784c9..764823d786 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -376,21 +376,16 @@ trait ContextErrors { setError(tree) } - def MissingParameterTypeError(fun: Tree, vparam: ValDef, pt: Type) = { - def anonMessage = ( - "\nThe argument types of an anonymous function must be fully known. (SLS 8.5)" + - "\nExpected type was: " + pt.toLongString - ) - - val suffix = - if (!vparam.mods.isSynthetic) "" - else " for expanded function" + (fun match { - case Function(_, Match(_, _)) => anonMessage - case _ => " " + fun - }) - - issueNormalTypeError(vparam, "missing parameter type" + suffix) - } + def MissingParameterTypeError(fun: Tree, vparam: ValDef, pt: Type) = + if (vparam.mods.isSynthetic) fun match { + case Function(_, Match(_, _)) => MissingParameterTypeAnonMatchError(vparam, pt) + case _ => issueNormalTypeError(vparam, "missing parameter type for expanded function " + fun) + } else issueNormalTypeError(vparam, "missing parameter type") + + def MissingParameterTypeAnonMatchError(vparam: Tree, pt: Type) = + issueNormalTypeError(vparam, "missing parameter type for expanded function\n"+ + "The argument types of an anonymous function must be fully known. (SLS 8.5)\n"+ + "Expected type was: " + pt.toLongString) def ConstructorsOrderError(tree: Tree) = { issueNormalTypeError(tree, "called constructor's definition must precede calling constructor's definition") diff --git a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala index bbc36e01c9..aff8368f75 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala @@ -1649,7 +1649,7 @@ class Foo(x: Other) { x._1 } // no error in this order def catchAll = matchFailGen map { matchFailGen => val scrutRef = if(scrutSym ne NoSymbol) REF(scrutSym) else EmptyTree // for alternatives - LabelDef(nextCase, Nil, matchEnd APPLY (matchFailGen(scrutRef))) // need to jump to matchEnd with result generated by matchFailGen (could be `FALSE` for isDefinedAt) + LabelDef(nextCase, Nil, matchEnd APPLY (_asInstanceOf(matchFailGen(scrutRef), restpe))) // need to jump to matchEnd with result generated by matchFailGen (could be `FALSE` for isDefinedAt) } toList // catchAll.isEmpty iff no synthetic default case needed (the (last) user-defined case is a default) // if the last user-defined case is a default, it will never jump to the next case; it will go immediately to matchEnd diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index d98d248231..013a74da7e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1625,12 +1625,18 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R case _ => tree } + // skip refchecks in patterns.... result = result match { case CaseDef(pat, guard, body) => inPattern = true val pat1 = transform(pat) inPattern = false treeCopy.CaseDef(tree, pat1, transform(guard), transform(body)) + case LabelDef(_, _, _) if gen.hasSynthCaseSymbol(result) => + inPattern = true + val res = deriveLabelDef(result)(transform) + inPattern = false + res case _ => super.transform(result) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 95a1eafae2..06a7311f79 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2144,15 +2144,15 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { case Annotated(Ident(nme.synthSwitch), selector) => (selector, false) case s => (s, true) } - val selector1 = checkDead(typed(selector, EXPRmode | BYVALmode, WildcardType)) - val selectorTp = packCaptured(selector1.tpe.widen) - val casesTyped = typedCases(cases, selectorTp, resTp) + val selector1 = checkDead(typed(selector, EXPRmode | BYVALmode, WildcardType)) + val selectorTp = packCaptured(selector1.tpe.widen) + + val casesTyped = typedCases(cases, selectorTp, resTp) val caseTypes = casesTyped map (c => packedType(c, context.owner).deconst) - val (ownType0, needAdapt) = if (isFullyDefined(resTp)) (resTp, false) else weakLub(caseTypes) - val ownType = ownType0.skolemizeExistential(context.owner, context.tree) - val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, ownType)) - // val (owntype0, needAdapt) = ptOrLub(casesTyped map (x => repackExistential(x.tpe))) - // val owntype = elimAnonymousClass(owntype0) + val (ownType, needAdapt) = if (isFullyDefined(resTp)) (resTp, false) else weakLub(caseTypes) + + val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, ownType)) + (selector1, selectorTp, casesAdapted, ownType, doTranslation) } @@ -2166,14 +2166,17 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { Match(selector1, casesAdapted) setType ownType // setType of the Match to avoid recursing endlessly } else { val scrutType = repeatedToSeq(elimAnonymousClass(selectorTp)) - MatchTranslator(this).translateMatch(selector1, casesAdapted, repeatedToSeq(ownType), scrutType, matchFailGen) + // we've packed the type for each case in prepareTranslateMatch so that if all cases have the same existential case, we get a clean lub + // here, we should open up the existential again + // relevant test cases: pos/existentials-harmful.scala, pos/gadt-gilles.scala, pos/t2683.scala, pos/virtpatmat_exist4.scala + MatchTranslator(this).translateMatch(selector1, casesAdapted, repeatedToSeq(ownType.skolemizeExistential(context.owner, context.tree)), scrutType, matchFailGen) } } def typedMatchAnonFun(tree: Tree, cases: List[CaseDef], mode: Int, pt0: Type, selOverride: Option[(List[ValDef], Tree)] = None) = { val pt = deskolemizeGADTSkolems(pt0) val targs = pt.normalize.typeArgs - val arity = if (isFunctionType(pt)) targs.length - 1 else 1 + val arity = if (isFunctionType(pt)) targs.length - 1 else 1 // TODO pt should always be a (Partial)Function, right? val ptRes = if (targs.isEmpty) WildcardType else targs.last // may not be fully defined val isPartial = pt.typeSymbol == PartialFunctionClass @@ -2185,6 +2188,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { def mkParams(methodSym: Symbol) = { selOverride match { + case None if targs.isEmpty => MissingParameterTypeAnonMatchError(tree, pt); (Nil, EmptyTree) case None => val ps = methodSym newSyntheticValueParams targs.init // is there anything we can do if targs.isEmpty?? val ids = ps map (p => Ident(p.name)) @@ -2210,44 +2214,52 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { anonClass setInfo ClassInfoType(List(ObjectClass.tpe, pt, SerializableClass.tpe), newScope, anonClass) val methodSym = anonClass.newMethod(nme.apply, tree.pos, FINAL) val (paramSyms, selector) = mkParams(methodSym) - methodSym setInfoAndEnter MethodType(paramSyms, AnyClass.tpe) - val methodBodyTyper = newTyper(context.makeNewScope(context.tree, methodSym)) // should use the DefDef for the context's tree, but it doesn't exist yet (we need the typer we're creating to create it) - paramSyms foreach (methodBodyTyper.context.scope enter _) + if (selector eq EmptyTree) EmptyTree + else { + methodSym setInfoAndEnter MethodType(paramSyms, AnyClass.tpe) + + val methodBodyTyper = newTyper(context.makeNewScope(context.tree, methodSym)) // should use the DefDef for the context's tree, but it doesn't exist yet (we need the typer we're creating to create it) + paramSyms foreach (methodBodyTyper.context.scope enter _) - val (selector1, selectorTp, casesAdapted, resTp, doTranslation) = methodBodyTyper.prepareTranslateMatch(selector, cases, mode, ptRes) + val (selector1, selectorTp, casesAdapted, resTp, doTranslation) = methodBodyTyper.prepareTranslateMatch(selector, cases, mode, ptRes) - val formalTypes = paramSyms map (_.tpe) - val parents = - if (isPartial) List(appliedType(AbstractPartialFunctionClass.typeConstructor, List(formalTypes.head, resTp)), SerializableClass.tpe) - else List(appliedType(AbstractFunctionClass(arity).typeConstructor, formalTypes :+ resTp), SerializableClass.tpe) + val formalTypes = paramSyms map (_.tpe) + val parents = + if (isPartial) List(appliedType(AbstractPartialFunctionClass.typeConstructor, List(formalTypes.head, resTp)), SerializableClass.tpe) + else List(appliedType(AbstractFunctionClass(arity).typeConstructor, formalTypes :+ resTp), SerializableClass.tpe) - anonClass setInfo ClassInfoType(parents, newScope, anonClass) - methodSym setInfoAndEnter MethodType(paramSyms, resTp) + anonClass setInfo ClassInfoType(parents, newScope, anonClass) + methodSym setInfoAndEnter MethodType(paramSyms, resTp) - // use apply's parameter since the scrut's type has been widened - def missingCase(scrut_ignored: Tree) = (funThis DOT nme.missingCase) (REF(paramSyms.head)) + // use apply's parameter since the scrut's type has been widened + def missingCase(scrut_ignored: Tree) = (funThis DOT nme.missingCase) (REF(paramSyms.head)) - val body = methodBodyTyper.translateMatch(selector1, selectorTp, casesAdapted, resTp, doTranslation, if (isPartial) Some(missingCase) else None) + val body = methodBodyTyper.translateMatch(selector1, selectorTp, casesAdapted, resTp, doTranslation, if (isPartial) Some(missingCase) else None) - DefDef(methodSym, body) + DefDef(methodSym, body) + } } def isDefinedAtMethod = { val methodSym = anonClass.newMethod(nme._isDefinedAt, tree.pos, FINAL) val (paramSyms, selector) = mkParams(methodSym) - val methodBodyTyper = newTyper(context.makeNewScope(context.tree, methodSym)) // should use the DefDef for the context's tree, but it doesn't exist yet (we need the typer we're creating to create it) - paramSyms foreach (methodBodyTyper.context.scope enter _) - methodSym setInfoAndEnter MethodType(paramSyms, BooleanClass.tpe) + if (selector eq EmptyTree) EmptyTree + else { + val methodBodyTyper = newTyper(context.makeNewScope(context.tree, methodSym)) // should use the DefDef for the context's tree, but it doesn't exist yet (we need the typer we're creating to create it) + paramSyms foreach (methodBodyTyper.context.scope enter _) + methodSym setInfoAndEnter MethodType(paramSyms, BooleanClass.tpe) - val (selector1, selectorTp, casesAdapted, resTp, doTranslation) = methodBodyTyper.prepareTranslateMatch(selector, casesTrue, mode, BooleanClass.tpe) - val body = methodBodyTyper.translateMatch(selector1, selectorTp, casesAdapted, resTp, doTranslation, Some(scrutinee => FALSE_typed)) + val (selector1, selectorTp, casesAdapted, resTp, doTranslation) = methodBodyTyper.prepareTranslateMatch(selector, casesTrue, mode, BooleanClass.tpe) + val body = methodBodyTyper.translateMatch(selector1, selectorTp, casesAdapted, resTp, doTranslation, Some(scrutinee => FALSE_typed)) - DefDef(methodSym, body) + DefDef(methodSym, body) + } } val members = if (!isPartial) List(applyMethod) else List(applyMethod, isDefinedAtMethod) - typed(Block(List(ClassDef(anonClass, NoMods, List(List()), List(List()), members, tree.pos)), New(anonClass.tpe)), mode, pt) + if (members.head eq EmptyTree) setError(tree) + else typed(Block(List(ClassDef(anonClass, NoMods, List(List()), List(List()), members, tree.pos)), New(anonClass.tpe)), mode, pt) } /** diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index 019d3d0785..a7ec7618b7 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -156,7 +156,7 @@ trait GenTraversableOnce[+A] extends Any { * @return the result of inserting `op` between consecutive elements of this $coll, * going left to right with the start value `z` on the left: * {{{ - * op(...op(op(z, x1), x2), ..., xn) + * op(...op(op(z, x_1), x_2), ..., x_n) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. */ @@ -191,7 +191,7 @@ trait GenTraversableOnce[+A] extends Any { * @return the result of inserting `op` between consecutive elements of this $coll, * going right to left with the start value `z` on the right: * {{{ - * op(x1, op(x2, ... op(xn, z)...)) + * op(x_1, op(x_2, ... op(x_n, z)...)) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. */ @@ -209,7 +209,7 @@ trait GenTraversableOnce[+A] extends Any { * @return the result of inserting `op` between consecutive elements of this $coll, * going left to right with the start value `z` on the left: * {{{ - * op(...op(z, x1), x2, ..., xn) + * op(...op(z, x_1), x_2, ..., x_n) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. */ @@ -226,7 +226,7 @@ trait GenTraversableOnce[+A] extends Any { * @return the result of inserting `op` between consecutive elements of this $coll, * going right to left with the start value `z` on the right: * {{{ - * op(x1, op(x2, ... op(xn, z)...)) + * op(x_1, op(x_2, ... op(x_n, z)...)) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. */ @@ -271,7 +271,7 @@ trait GenTraversableOnce[+A] extends Any { * @return the result of inserting `op` between consecutive elements of this $coll, * going right to left: * {{{ - * op(x,,1,,, op(x,,2,,, ..., op(x,,n-1,,, x,,n,,)...)) + * op(x_1, op(x_2, ..., op(x_{n-1}, x_n)...)) * }}} * where `x,,1,,, ..., x,,n,,` are the elements of this $coll. * @throws `UnsupportedOperationException` if this $coll is empty. diff --git a/src/library/scala/collection/JavaConverters.scala b/src/library/scala/collection/JavaConverters.scala index 07e8518cb0..13f1f19f81 100755 --- a/src/library/scala/collection/JavaConverters.scala +++ b/src/library/scala/collection/JavaConverters.scala @@ -16,7 +16,7 @@ import convert._ // additions. Would be nice to have in one place. -/** A collection of decorators that allow to convert between +/** A collection of decorators that allow converting between * Scala and Java collections using `asScala` and `asJava` methods. * * The following conversions are supported via `asJava`, `asScala` diff --git a/src/library/scala/collection/mutable/FlatArray.scala b/src/library/scala/collection/mutable/FlatArray.scala index a7f994bf74..3e43b66ecf 100644 --- a/src/library/scala/collection/mutable/FlatArray.scala +++ b/src/library/scala/collection/mutable/FlatArray.scala @@ -60,8 +60,15 @@ extends AbstractSeq[T] */ object FlatArray { - def empty[Boxed, Unboxed](elems: Boxed*) - (implicit boxings: BoxingConversions[Boxed, Unboxed], elemManifest: ClassManifest[Unboxed]): FlatArray[Boxed] = apply() + def ofDim[Boxed, Unboxed](size:Int) + (implicit boxings: BoxingConversions[Boxed, Unboxed], + manifest: ClassManifest[Unboxed]): FlatArray[Boxed] = { + val elems = Array.ofDim[Unboxed](size) + new FlatArray.Impl(elems, boxings, manifest) + } + + def empty[Boxed, Unboxed](implicit boxings: BoxingConversions[Boxed, Unboxed], + elemManifest: ClassManifest[Unboxed]): FlatArray[Boxed] = apply() def apply[Boxed, Unboxed](elems: Boxed*) (implicit boxings: BoxingConversions[Boxed, Unboxed], elemManifest: ClassManifest[Unboxed]): FlatArray[Boxed] = { diff --git a/src/library/scala/testing/Show.scala b/src/library/scala/testing/Show.scala index b0d094e466..7570bf705c 100644 --- a/src/library/scala/testing/Show.scala +++ b/src/library/scala/testing/Show.scala @@ -11,7 +11,7 @@ package scala.testing /** Classes inheriting trait `Show` can test their member methods using the - * notattion `meth(arg,,1,,, ..., arg,,n,,)`, where `meth` is the name of + * notation `meth(arg,,1,,, ..., arg,,n,,)`, where `meth` is the name of * the method and `arg,,1,,,...,arg,,n,,` are the arguments. * * The only difference to a normal method call is the leading quote |