diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileSocket.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/LambdaLift.scala | 41 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 121 | ||||
-rw-r--r-- | src/library/scala/concurrent/BatchingExecutor.scala | 117 | ||||
-rw-r--r-- | src/library/scala/concurrent/Future.scala | 6 | ||||
-rw-r--r-- | src/reflect/scala/reflect/macros/Attachments.scala | 14 | ||||
-rw-r--r-- | test/files/jvm/scala-concurrent-tck.scala | 7 | ||||
-rw-r--r-- | test/files/neg/t6443c.check | 7 | ||||
-rw-r--r-- | test/files/neg/t6443c.scala | 21 | ||||
-rw-r--r-- | test/files/run/t6028.check | 2 | ||||
-rw-r--r-- | test/files/run/t6135.scala | 13 | ||||
-rw-r--r-- | test/files/run/t6443-by-name.check | 3 | ||||
-rw-r--r-- | test/files/run/t6443-by-name.scala | 18 | ||||
-rw-r--r-- | test/files/run/t6443-varargs.check | 1 | ||||
-rw-r--r-- | test/files/run/t6443-varargs.scala | 16 | ||||
-rw-r--r-- | test/files/run/t6443.scala | 15 | ||||
-rw-r--r-- | test/files/run/t6443b.scala | 16 | ||||
-rw-r--r-- | test/files/run/t6863.scala | 114 | ||||
-rwxr-xr-x | test/partest | 7 |
19 files changed, 510 insertions, 31 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala index 9a3e8d1530..4051bda914 100644 --- a/src/compiler/scala/tools/nsc/CompileSocket.scala +++ b/src/compiler/scala/tools/nsc/CompileSocket.scala @@ -72,7 +72,7 @@ class CompileSocket extends CompileOutputCommon { /** A temporary directory to use */ val tmpDir = { val udir = Option(Properties.userName) getOrElse "shared" - val f = (Path(Properties.tmpDir) / "scala-devel" / udir).createDirectory() + val f = (Path(Properties.tmpDir) / ("scala-devel" + udir)).createDirectory() if (f.isDirectory && f.canWrite) { info("[Temp directory: " + f + "]") diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 448079abed..845843e9d6 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -451,20 +451,45 @@ abstract class LambdaLift extends InfoTransform { } case arg => arg } - /** Wrap expr argument in new *Ref(..) constructor, but make - * sure that Try expressions stay at toplevel. + + /** Wrap expr argument in new *Ref(..) constructor. But try/catch + * is a problem because a throw will clear the stack and post catch + * we would expect the partially-constructed object to be on the stack + * for the call to init. So we recursively + * search for "leaf" result expressions where we know its safe + * to put the new *Ref(..) constructor or, if all else fails, transform + * an expr to { val temp=expr; new *Ref(temp) }. + * The reason we narrowly look for try/catch in captured var definitions + * is because other try/catch expression have already been lifted + * see SI-6863 */ - def refConstr(expr: Tree): Tree = expr match { + def refConstr(expr: Tree): Tree = typer.typedPos(expr.pos) {expr match { + // very simple expressions can be wrapped in a new *Ref(expr) because they can't have + // a try/catch in final expression position. + case Ident(_) | Apply(_, _) | Literal(_) | New(_) | Select(_, _) | Throw(_) | Assign(_, _) | ValDef(_, _, _, _) | Return(_) | EmptyTree => + New(sym.tpe, expr) case Try(block, catches, finalizer) => Try(refConstr(block), catches map refConstrCase, finalizer) + case Block(stats, expr) => + Block(stats, refConstr(expr)) + case If(cond, trueBranch, falseBranch) => + If(cond, refConstr(trueBranch), refConstr(falseBranch)) + case Match(selector, cases) => + Match(selector, cases map refConstrCase) + // if we can't figure out what else to do, turn expr into {val temp1 = expr; new *Ref(temp1)} to avoid + // any possibility of try/catch in the *Ref constructor. This should be a safe tranformation as a default + // though it potentially wastes a variable slot. In particular this case handles LabelDefs. case _ => - New(sym.tpe, expr) - } + debuglog("assigning expr to temp: " + (expr.pos)) + val tempSym = currentOwner.newValue(unit.freshTermName("temp"), expr.pos) setInfo expr.tpe + val tempDef = ValDef(tempSym, expr) setPos expr.pos + val tempRef = Ident(tempSym) setPos expr.pos + Block(tempDef, New(sym.tpe, tempRef)) + }} def refConstrCase(cdef: CaseDef): CaseDef = CaseDef(cdef.pat, cdef.guard, refConstr(cdef.body)) - treeCopy.ValDef(tree, mods, name, tpt1, typer.typedPos(rhs.pos) { - refConstr(constructorArg) - }) + + treeCopy.ValDef(tree, mods, name, tpt1, refConstr(constructorArg)) } else tree case Return(Block(stats, value)) => Block(stats, treeCopy.Return(tree, value)) setType tree.tpe setPos tree.pos diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 9908bd689e..c07177ec10 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -603,8 +603,6 @@ abstract class UnCurry extends InfoTransform } case ValDef(_, _, _, rhs) => if (sym eq NoSymbol) throw new IllegalStateException("Encountered Valdef without symbol: "+ tree + " in "+ unit) - // a local variable that is mutable and free somewhere later should be lifted - // as lambda lifting (coming later) will wrap 'rhs' in an Ref object. if (!sym.owner.isSourceMethod) withNeedLift(true) { super.transform(tree) } else @@ -748,15 +746,22 @@ abstract class UnCurry extends InfoTransform } case dd @ DefDef(_, _, _, vparamss0, _, rhs0) => - val vparamss1 = vparamss0 match { - case _ :: Nil => vparamss0 - case _ => vparamss0.flatten :: Nil - } + val (newParamss, newRhs): (List[List[ValDef]], Tree) = + if (dependentParamTypeErasure isDependent dd) + dependentParamTypeErasure erase dd + else { + val vparamss1 = vparamss0 match { + case _ :: Nil => vparamss0 + case _ => vparamss0.flatten :: Nil + } + (vparamss1, rhs0) + } + val flatdd = copyDefDef(dd)( - vparamss = vparamss1, + vparamss = newParamss, rhs = nonLocalReturnKeys get dd.symbol match { - case Some(k) => atPos(rhs0.pos)(nonLocalReturnTry(rhs0, k, dd.symbol)) - case None => rhs0 + case Some(k) => atPos(newRhs.pos)(nonLocalReturnTry(newRhs, k, dd.symbol)) + case None => newRhs } ) addJavaVarargsForwarders(dd, flatdd) @@ -782,6 +787,104 @@ abstract class UnCurry extends InfoTransform } } + /** + * When we concatenate parameter lists, formal parameter types that were dependent + * on prior parameter values will no longer be correctly scoped. + * + * For example: + * + * {{{ + * def foo(a: A)(b: a.B): a.type = {b; b} + * // after uncurry + * def foo(a: A, b: a/* NOT IN SCOPE! */.B): a.B = {b; b} + * }}} + * + * This violates the principle that each compiler phase should produce trees that + * can be retyped (see [[scala.tools.nsc.typechecker.TreeCheckers]]), and causes + * a practical problem in `erasure`: it is not able to correctly determine if + * such a signature overrides a corresponding signature in a parent. (SI-6443). + * + * This transformation erases the dependent method types by: + * - Widening the formal parameter type to existentially abstract + * over the prior parameters (using `packSymbols`) + * - Inserting casts in the method body to cast to the original, + * precise type. + * + * For the example above, this results in: + * + * {{{ + * def foo(a: A, b: a.B forSome { val a: A }): a.B = { val b$1 = b.asInstanceOf[a.B]; b$1; b$1 } + * }}} + */ + private object dependentParamTypeErasure { + sealed abstract class ParamTransform { + def param: ValDef + } + final case class Identity(param: ValDef) extends ParamTransform + final case class Packed(param: ValDef, tempVal: ValDef) extends ParamTransform + + def isDependent(dd: DefDef): Boolean = + beforeUncurry { + val methType = dd.symbol.info + methType.isDependentMethodType && mexists(methType.paramss)(_.info exists (_.isImmediatelyDependent)) + } + + /** + * @return (newVparamss, newRhs) + */ + def erase(dd: DefDef): (List[List[ValDef]], Tree) = { + import dd.{ vparamss, rhs } + val vparamSyms = vparamss flatMap (_ map (_.symbol)) + + val paramTransforms: List[ParamTransform] = + vparamss.flatten.map { p => + val declaredType = p.symbol.info + // existentially abstract over value parameters + val packedType = typer.packSymbols(vparamSyms, declaredType) + if (packedType =:= declaredType) Identity(p) + else { + // Change the type of the param symbol + p.symbol updateInfo packedType + + // Create a new param tree + val newParam: ValDef = copyValDef(p)(tpt = TypeTree(packedType)) + + // Within the method body, we'll cast the parameter to the originally + // declared type and assign this to a synthetic val. Later, we'll patch + // the method body to refer to this, rather than the parameter. + val tempVal: ValDef = { + val tempValName = unit freshTermName (p.name + "$") + val newSym = dd.symbol.newTermSymbol(tempValName, p.pos, SYNTHETIC).setInfo(declaredType) + atPos(p.pos)(ValDef(newSym, gen.mkAttributedCast(Ident(p.symbol), declaredType))) + } + Packed(newParam, tempVal) + } + } + + val allParams = paramTransforms map (_.param) + val (packedParams, tempVals) = paramTransforms.collect { + case Packed(param, tempVal) => (param, tempVal) + }.unzip + + val rhs1 = localTyper.typedPos(rhs.pos) { + // Patch the method body to refer to the temp vals + val rhsSubstituted = rhs.substituteSymbols(packedParams map (_.symbol), tempVals map (_.symbol)) + // The new method body: { val p$1 = p.asInstanceOf[<dependent type>]; ...; <rhsSubstituted> } + Block(tempVals, rhsSubstituted) + } + + // update the type of the method after uncurry. + dd.symbol updateInfo { + val GenPolyType(tparams, tp) = dd.symbol.info + logResult("erased dependent param types for ${dd.symbol.info}") { + GenPolyType(tparams, MethodType(allParams map (_.symbol), tp.finalResultType)) + } + } + (allParams :: Nil, rhs1) + } + } + + /* Analyzes repeated params if method is annotated as `varargs`. * If the repeated params exist, it saves them into the `repeatedParams` map, * which is used later. diff --git a/src/library/scala/concurrent/BatchingExecutor.scala b/src/library/scala/concurrent/BatchingExecutor.scala new file mode 100644 index 0000000000..a0d7aaea47 --- /dev/null +++ b/src/library/scala/concurrent/BatchingExecutor.scala @@ -0,0 +1,117 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.concurrent + +import java.util.concurrent.Executor +import scala.annotation.tailrec + +/** + * Mixin trait for an Executor + * which groups multiple nested `Runnable.run()` calls + * into a single Runnable passed to the original + * Executor. This can be a useful optimization + * because it bypasses the original context's task + * queue and keeps related (nested) code on a single + * thread which may improve CPU affinity. However, + * if tasks passed to the Executor are blocking + * or expensive, this optimization can prevent work-stealing + * and make performance worse. Also, some ExecutionContext + * may be fast enough natively that this optimization just + * adds overhead. + * The default ExecutionContext.global is already batching + * or fast enough not to benefit from it; while + * `fromExecutor` and `fromExecutorService` do NOT add + * this optimization since they don't know whether the underlying + * executor will benefit from it. + * A batching executor can create deadlocks if code does + * not use `scala.concurrent.blocking` when it should, + * because tasks created within other tasks will block + * on the outer task completing. + * This executor may run tasks in any order, including LIFO order. + * There are no ordering guarantees. + * + * WARNING: The underlying Executor's execute-method must not execute the submitted Runnable + * in the calling thread synchronously. It must enqueue/handoff the Runnable. + */ +private[concurrent] trait BatchingExecutor extends Executor { + + // invariant: if "_tasksLocal.get ne null" then we are inside BatchingRunnable.run; if it is null, we are outside + private val _tasksLocal = new ThreadLocal[List[Runnable]]() + + private class Batch(val initial: List[Runnable]) extends Runnable with BlockContext { + private var parentBlockContext: BlockContext = _ + // this method runs in the delegate ExecutionContext's thread + override def run(): Unit = { + require(_tasksLocal.get eq null) + + val prevBlockContext = BlockContext.current + BlockContext.withBlockContext(this) { + try { + parentBlockContext = prevBlockContext + + @tailrec def processBatch(batch: List[Runnable]): Unit = batch match { + case Nil => () + case head :: tail => + _tasksLocal set tail + try { + head.run() + } catch { + case t: Throwable => + // if one task throws, move the + // remaining tasks to another thread + // so we can throw the exception + // up to the invoking executor + val remaining = _tasksLocal.get + _tasksLocal set Nil + unbatchedExecute(new Batch(remaining)) //TODO what if this submission fails? + throw t // rethrow + } + processBatch(_tasksLocal.get) // since head.run() can add entries, always do _tasksLocal.get here + } + + processBatch(initial) + } finally { + _tasksLocal.remove() + parentBlockContext = null + } + } + } + + override def blockOn[T](thunk: => T)(implicit permission: CanAwait): T = { + // if we know there will be blocking, we don't want to keep tasks queued up because it could deadlock. + { + val tasks = _tasksLocal.get + _tasksLocal set Nil + if ((tasks ne null) && tasks.nonEmpty) + unbatchedExecute(new Batch(tasks)) + } + + // now delegate the blocking to the previous BC + require(parentBlockContext ne null) + parentBlockContext.blockOn(thunk) + } + } + + protected def unbatchedExecute(r: Runnable): Unit + + override def execute(runnable: Runnable): Unit = { + if (batchable(runnable)) { // If we can batch the runnable + _tasksLocal.get match { + case null => unbatchedExecute(new Batch(List(runnable))) // If we aren't in batching mode yet, enqueue batch + case some => _tasksLocal.set(runnable :: some) // If we are already in batching mode, add to batch + } + } else unbatchedExecute(runnable) // If not batchable, just delegate to underlying + } + + /** Override this to define which runnables will be batched. */ + def batchable(runnable: Runnable): Boolean = runnable match { + case _: OnCompleteRunnable => true + case _ => false + } +} diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index 4b9e74708d..36f3be341f 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -675,9 +675,9 @@ object Future { // by just not ever using it itself. scala.concurrent // doesn't need to create defaultExecutionContext as // a side effect. - private[concurrent] object InternalCallbackExecutor extends ExecutionContext { - override def execute(runnable: Runnable): Unit = - runnable.run() + private[concurrent] object InternalCallbackExecutor extends ExecutionContext with BatchingExecutor { + override protected def unbatchedExecute(r: Runnable): Unit = + r.run() override def reportFailure(t: Throwable): Unit = throw new IllegalStateException("problem in scala.concurrent internal callback", t) } diff --git a/src/reflect/scala/reflect/macros/Attachments.scala b/src/reflect/scala/reflect/macros/Attachments.scala index a77cebf415..eeb87fafcc 100644 --- a/src/reflect/scala/reflect/macros/Attachments.scala +++ b/src/reflect/scala/reflect/macros/Attachments.scala @@ -44,17 +44,19 @@ abstract class Attachments { self => * Replaces an existing payload of the same type, if exists. */ def update[T: ClassTag](attachment: T): Attachments { type Pos = self.Pos } = - new NonemptyAttachments(this.pos, remove[T].all + attachment) + new NonemptyAttachments[Pos](this.pos, remove[T].all + attachment) /** Creates a copy of this attachment with the payload of the given class type `T` removed. */ def remove[T: ClassTag]: Attachments { type Pos = self.Pos } = { val newAll = all filterNot matchesTag[T] if (newAll.isEmpty) pos.asInstanceOf[Attachments { type Pos = self.Pos }] - else new NonemptyAttachments(this.pos, newAll) + else new NonemptyAttachments[Pos](this.pos, newAll) } +} - private class NonemptyAttachments(override val pos: Pos, override val all: Set[Any]) extends Attachments { - type Pos = self.Pos - def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all) - } +// SI-7018: This used to be an inner class of `Attachments`, but that led to a memory leak in the +// IDE via $outer pointers. +private final class NonemptyAttachments[P >: Null](override val pos: P, override val all: Set[Any]) extends Attachments { + type Pos = P + def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all) } diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index b529bca38a..b2b4183564 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -134,6 +134,12 @@ trait FutureCallbacks extends TestBase { assert(false) } } + + def testThatNestedCallbacksDoNotYieldStackOverflow(): Unit = { + val promise = Promise[Int] + (0 to 10000).map(Future(_)).foldLeft(promise.future)((f1, f2) => f2.flatMap(i => f1)) + promise.success(-1) + } testOnSuccess() testOnSuccessWhenCompleted() @@ -143,6 +149,7 @@ trait FutureCallbacks extends TestBase { // testOnFailureWhenSpecialThrowable(6, new scala.util.control.ControlThrowable { }) //TODO: this test is currently problematic, because NonFatal does not match InterruptedException //testOnFailureWhenSpecialThrowable(7, new InterruptedException) + testThatNestedCallbacksDoNotYieldStackOverflow() testOnFailureWhenTimeoutException() } diff --git a/test/files/neg/t6443c.check b/test/files/neg/t6443c.check new file mode 100644 index 0000000000..7cf8d23f4b --- /dev/null +++ b/test/files/neg/t6443c.check @@ -0,0 +1,7 @@ +t6443c.scala:16: error: double definition: +method foo:(d: B.D)(a: Any)(d2: d.type)Unit and +method foo:(d: B.D)(a: Any, d2: d.type)Unit at line 11 +have same type after erasure: (d: B.D, a: Object, d2: B.D)Unit + def foo(d: D)(a: Any)(d2: d.type): Unit = () + ^ +one error found diff --git a/test/files/neg/t6443c.scala b/test/files/neg/t6443c.scala new file mode 100644 index 0000000000..817224e043 --- /dev/null +++ b/test/files/neg/t6443c.scala @@ -0,0 +1,21 @@ +trait A { + type D >: Null <: C + def foo(d: D)(a: Any, d2: d.type): Unit + trait C { + def bar: Unit = foo(null)(null, null) + } +} +object B extends A { + class D extends C + + def foo(d: D)(a: Any, d2: d.type): Unit = () // Bridge method required here! + + // No bridge method should be added, but we'll be happy enough if + // the "same type after erasure" error kicks in before the duplicated + // bridge causes a problem. + def foo(d: D)(a: Any)(d2: d.type): Unit = () +} + +object Test extends App { + new B.D().bar +} diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index 34f4b22134..79deaacf3a 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -15,7 +15,7 @@ package <empty> { } }; def bar(barParam: Int): Object = { - @volatile var MethodLocalObject$module: runtime.VolatileObjectRef = new runtime.VolatileObjectRef(<empty>); + @volatile var MethodLocalObject$module: runtime.VolatileObjectRef = new runtime.VolatileObjectRef(null); T.this.MethodLocalObject$1(barParam, MethodLocalObject$module) }; def tryy(tryyParam: Int): Function0 = { diff --git a/test/files/run/t6135.scala b/test/files/run/t6135.scala new file mode 100644 index 0000000000..c0f8f3fd1d --- /dev/null +++ b/test/files/run/t6135.scala @@ -0,0 +1,13 @@ +object Test extends App { + class A { class V } + + abstract class B[S] { + def foo(t: S, a: A)(v: a.V) + } + + val b1 = new B[String] { + def foo(t: String, a: A)(v: a.V) = () // Bridge method required here! + } + + b1.foo("", null)(null) +} diff --git a/test/files/run/t6443-by-name.check b/test/files/run/t6443-by-name.check new file mode 100644 index 0000000000..6f98fa4a28 --- /dev/null +++ b/test/files/run/t6443-by-name.check @@ -0,0 +1,3 @@ +1 +foo +foo diff --git a/test/files/run/t6443-by-name.scala b/test/files/run/t6443-by-name.scala new file mode 100644 index 0000000000..bfd9bf9791 --- /dev/null +++ b/test/files/run/t6443-by-name.scala @@ -0,0 +1,18 @@ +object Test { + + def main(args: Array[String]) { + def foo = {println("foo"); 0} + lazyDep(X)(foo) + } + + trait T { + type U + } + object X extends T { type U = Int } + + def lazyDep(t: T)(u: => t.U) { + println("1") + u + u + } +} diff --git a/test/files/run/t6443-varargs.check b/test/files/run/t6443-varargs.check new file mode 100644 index 0000000000..257cc5642c --- /dev/null +++ b/test/files/run/t6443-varargs.check @@ -0,0 +1 @@ +foo diff --git a/test/files/run/t6443-varargs.scala b/test/files/run/t6443-varargs.scala new file mode 100644 index 0000000000..9cbae3e99c --- /dev/null +++ b/test/files/run/t6443-varargs.scala @@ -0,0 +1,16 @@ +object Test { + + def main(args: Array[String]) { + def foo = {println("foo"); 0} + lazyDep(X)(foo) + } + + trait T { + type U + } + object X extends T { type U = Int } + + def lazyDep(t: T)(us: t.U*) { + List(us: _*) + } +} diff --git a/test/files/run/t6443.scala b/test/files/run/t6443.scala new file mode 100644 index 0000000000..67fe2cab22 --- /dev/null +++ b/test/files/run/t6443.scala @@ -0,0 +1,15 @@ +class Base +class Derived extends Base + +trait A { + def foo(d: String)(d2: d.type): Base + val s = "" + def bar: Unit = foo(s)(s) +} +object B extends A { + def foo(d: String)(d2: d.type): D forSome { type D <: S; type S <: Derived } = {d2.isEmpty; null} // Bridge method required here! +} + +object Test extends App { + B.bar +} diff --git a/test/files/run/t6443b.scala b/test/files/run/t6443b.scala new file mode 100644 index 0000000000..9320b1dcfe --- /dev/null +++ b/test/files/run/t6443b.scala @@ -0,0 +1,16 @@ +trait A { + type D >: Null <: C + def foo(d: D)(d2: d.type): Unit + trait C { + def bar: Unit = foo(null)(null) + } +} +object B extends A { + class D extends C + + def foo(d: D)(d2: d.type): Unit = () // Bridge method required here! +} + +object Test extends App { + new B.D().bar +} diff --git a/test/files/run/t6863.scala b/test/files/run/t6863.scala new file mode 100644 index 0000000000..d77adb6af4 --- /dev/null +++ b/test/files/run/t6863.scala @@ -0,0 +1,114 @@ +/** Make sure that when a variable is captured its initialization expression is handled properly */ +object Test { + def lazyVal() = { + // internally lazy vals become vars which are initialized with "_", so they need to be tested just like vars do + lazy val x = "42" + assert({ () => x }.apply == "42") + } + def ident() = { + val y = "42" + var x = y + assert({ () => x }.apply == "42") + } + def apply() = { + def y(x : Int) = x.toString + var x = y(42) + assert({ () => x }.apply == "42") + } + def literal() = { + var x = "42" + assert({ () => x }.apply == "42") + } + def `new`() = { + var x = new String("42") + assert({ () => x }.apply == "42") + } + def select() = { + object Foo{val bar = "42"} + var x = Foo.bar + assert({ () => x }.apply == "42") + } + def `throw`() = { + var x = if (true) "42" else throw new Exception("42") + assert({ () => x }.apply == "42") + } + def assign() = { + var y = 1 + var x = y = 42 + assert({ () => x}.apply == ()) + } + def valDef() = { + var x = {val y = 42} + assert({ () => x}.apply == ()) + } + def `return`(): String = { + var x = if (true) return "42" else () + assert({ () => x}.apply == ()) + "42" + } + def tryFinally() = { + var x = try { "42" } finally () + assert({ () => x }.apply == "42") + } + def tryCatch() = { + var x = try { "42" } catch { case _ => "43" } + assert({ () => x }.apply == "42") + } + def `if`() = { + var x = if (true) () + assert({ () => x }.apply == ()) + } + def ifElse() = { + var x = if(true) "42" else "43" + assert({ () => x }.apply == "42") + } + def matchCase() = { + var x = 100 match { + case 100 => "42" + case _ => "43" + } + assert({ () => x }.apply == "42") + } + def block() = { + var x = { + val y = 42 + "42" + } + assert({ () => x }.apply == "42") + } + def labelDef() = { + var x = 100 match { + case 100 => try "42" finally () + } + assert({ () => x }.apply == "42") + } + def nested() = { + var x = { + val y = 42 + if(true) try "42" catch {case _ => "43"} + else "44" + } + assert({ () => x }.apply == "42") + } + def main(args: Array[String]) { + lazyVal() + ident() + apply() + literal() + `new`() + select() + `throw`() + assign() + valDef() + `return`() + tryFinally() + tryCatch() + ifElse() + `if`() + matchCase() + block() + labelDef() + nested() + } +} + diff --git a/test/partest b/test/partest index 186c0d1580..dd57137b21 100755 --- a/test/partest +++ b/test/partest @@ -74,9 +74,10 @@ if $cygwin; then EXT_CLASSPATH=`cygpath --path --$format "$EXT_CLASSPATH"` fi -# last arg wins, so if JAVA_OPTS already contains -Xmx or -Xms the -# supplied argument will be used. -JAVA_OPTS="-Xmx1024M -Xms64M $JAVA_OPTS" +# last arg wins, so if JAVA_OPTS already contains one of these options +# the supplied argument will be used. +# At this writing it is reported test/partest --all requires 108m permgen. +JAVA_OPTS="-Xmx1024M -Xms64M -XX:MaxPermSize=128M $JAVA_OPTS" partestDebugStr="" if [ ! -z "${PARTEST_DEBUG}" ] ; then |